Skip to content

Commit 036e40c

Browse files
committed
add a GitHub Action to release to PyPI when a new tag is created
1 parent bb89cd6 commit 036e40c

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

.github/workflows/build.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Publish to PyPI
2+
on:
3+
push:
4+
branches: [main]
5+
tags: '*'
6+
pull_request:
7+
8+
jobs:
9+
build:
10+
name: Build distribution
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.13"
19+
- name: Install pypa/build
20+
run: >-
21+
python3 -m
22+
pip install
23+
build
24+
--user
25+
26+
# If the event that triggered this workflow is a push of a tag, then build with
27+
# the version of that tag.
28+
- name: Build a binary wheel and a source tarball for tag
29+
run: BUILD_VERSION=${{ github.ref_name }} python3 -m build
30+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
31+
# The event that trigged this workflow is not a tag, so build without specifying the version.
32+
- name: Build a binary wheel and a source tarball
33+
run: python3 -m build
34+
if: "!startsWith(github.ref, 'refs/tags/')"
35+
36+
- name: Store the distribution packages
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: python-package-distributions
40+
path: dist/
41+
42+
pypi-publish:
43+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
44+
needs: [build]
45+
name: Upload release to PyPI
46+
runs-on: ubuntu-latest
47+
environment:
48+
name: pypi
49+
url: https://pypi.org/p/wagtail-thumbnail-choice-block
50+
permissions:
51+
id-token: write
52+
steps:
53+
- name: Download all the dists
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: python-package-distributions
57+
path: dist/
58+
- name: Publish distribution to PyPI
59+
uses: pypa/gh-action-pypi-publish@release/v1
60+
61+
github-release:
62+
name: >-
63+
Sign the Python 🐍 distribution 📦 with Sigstore
64+
and upload them to GitHub Release
65+
needs:
66+
- pypi-publish
67+
runs-on: ubuntu-latest
68+
69+
permissions:
70+
contents: write # IMPORTANT: mandatory for making GitHub Releases
71+
id-token: write # IMPORTANT: mandatory for sigstore
72+
73+
steps:
74+
- name: Download all the dists
75+
uses: actions/download-artifact@v4
76+
with:
77+
name: python-package-distributions
78+
path: dist/
79+
- name: Sign the dists with Sigstore
80+
uses: sigstore/gh-action-sigstore-python@v3
81+
with:
82+
inputs: >-
83+
./dist/*.tar.gz
84+
./dist/*.whl
85+
- name: Create GitHub Release
86+
env:
87+
GITHUB_TOKEN: ${{ github.token }}
88+
run: >-
89+
gh release create
90+
'${{ github.ref_name }}'
91+
--repo '${{ github.repository }}'
92+
--generate-notes
93+
- name: Upload artifact signatures to GitHub Release
94+
env:
95+
GITHUB_TOKEN: ${{ github.token }}
96+
# Upload to GitHub Release using the `gh` CLI.
97+
# `dist/` contains the built packages, and the
98+
# sigstore-produced signatures and certificates.
99+
run: >-
100+
gh release upload
101+
'${{ github.ref_name }}' dist/**
102+
--repo '${{ github.repository }}'

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,9 @@ Developed by Lincoln Loop.
287287
## Contributing
288288

289289
Contributions are welcome! Please feel free to submit a Pull Request.
290+
291+
## Releases
292+
293+
Releases are done with GitHub Actions whenever a new tag is created. For more information,
294+
see `<./.github/workflows/build.yml>`_. If adding a new tag, make sure to first update the
295+
version in pyproject.toml.

0 commit comments

Comments
 (0)