|
1 | 1 | ---
|
2 |
| -name: Release |
| 2 | +name: Publish Python 🐍 distribution 📦 to PyPI |
3 | 3 |
|
4 | 4 | on:
|
5 | 5 | push:
|
6 | 6 | tags:
|
| 7 | + # Order matters, the last rule that applies to a tag |
| 8 | + # is the one that takes effect: |
| 9 | + # https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-branches-and-tags |
7 | 10 | - '*'
|
| 11 | + # There should be no dev tags created, but to be safe, |
| 12 | + # let's not publish them. |
| 13 | + - '!*.dev*' |
| 14 | + |
| 15 | +env: |
| 16 | + PYPI_URL: https://pypi.org/p/django-simple-history |
8 | 17 |
|
9 | 18 | jobs:
|
| 19 | + |
10 | 20 | build:
|
11 |
| - if: github.repository == 'jazzband/django-simple-history' |
| 21 | + name: Build distribution 📦 |
12 | 22 | runs-on: ubuntu-latest
|
13 | 23 |
|
14 | 24 | steps:
|
15 | 25 | - uses: actions/checkout@v4
|
16 |
| - with: |
17 |
| - fetch-depth: 0 |
18 |
| - |
19 | 26 | - name: Set up Python
|
20 | 27 | uses: actions/setup-python@v5
|
21 | 28 | with:
|
22 |
| - python-version: 3.x |
| 29 | + python-version: "3.x" |
| 30 | + - name: Install pypa/build |
| 31 | + run: |
| 32 | + python3 -m pip install build --user |
| 33 | + - name: Build a binary wheel and a source tarball |
| 34 | + run: python3 -m build |
| 35 | + - name: Store the distribution packages |
| 36 | + uses: actions/upload-artifact@v4 |
| 37 | + with: |
| 38 | + name: python-package-distributions |
| 39 | + path: dist/ |
| 40 | + |
| 41 | + publish-to-pypi: |
| 42 | + name: >- |
| 43 | + Publish Python 🐍 distribution 📦 to PyPI |
| 44 | + needs: |
| 45 | + - build |
| 46 | + runs-on: ubuntu-latest |
| 47 | + environment: |
| 48 | + name: pypi |
| 49 | + url: ${{ env.PYPI_URL }} |
| 50 | + permissions: |
| 51 | + id-token: write # IMPORTANT: mandatory for trusted publishing |
| 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.12 |
23 | 60 |
|
24 |
| - - name: Install dependencies |
25 |
| - run: | |
26 |
| - python -m pip install -U pip |
27 |
| - python -m pip install -U build twine |
| 61 | + github-release: |
| 62 | + name: >- |
| 63 | + Sign the Python 🐍 distribution 📦 with Sigstore |
| 64 | + and upload them to GitHub Release |
| 65 | + needs: |
| 66 | + - publish-to-pypi |
| 67 | + runs-on: ubuntu-latest |
28 | 68 |
|
29 |
| - - name: Build package |
30 |
| - run: | |
31 |
| - python -m build |
32 |
| - twine check dist/* |
| 69 | + permissions: |
| 70 | + contents: write # IMPORTANT: mandatory for making GitHub Releases |
| 71 | + id-token: write # IMPORTANT: mandatory for sigstore |
33 | 72 |
|
34 |
| - - name: Upload packages to Jazzband |
35 |
| - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') |
36 |
| - uses: pypa/gh-action-pypi-publish@release/v1 |
| 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 | + |
37 | 81 | with:
|
38 |
| - user: jazzband |
39 |
| - password: ${{ secrets.JAZZBAND_RELEASE_KEY }} |
40 |
| - repository-url: https://jazzband.co/projects/django-simple-history/upload |
| 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 | + --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 }}' |
0 commit comments