|
1 |
| -name: Release |
| 1 | +name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI |
2 | 2 |
|
3 |
| -on: |
4 |
| - push: |
5 |
| - tags: |
6 |
| - - '*' |
| 3 | +on: push |
| 4 | + |
| 5 | +env: |
| 6 | + PYPI_URL: https://pypi.org/p/django-debug-toolbar |
| 7 | + PYPI_TEST_URL: https://test.pypi.org/p/django-debug-toolbar |
7 | 8 |
|
8 | 9 | jobs:
|
| 10 | + |
9 | 11 | build:
|
10 |
| - if: github.repository == 'jazzband/django-debug-toolbar' |
| 12 | + name: Build distribution 📦 |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + - name: Set up Python |
| 18 | + uses: actions/setup-python@v5 |
| 19 | + with: |
| 20 | + python-version: "3.x" |
| 21 | + - name: Install pypa/build |
| 22 | + run: |
| 23 | + python3 -m pip install build --user |
| 24 | + - name: Build a binary wheel and a source tarball |
| 25 | + run: python3 -m build |
| 26 | + - name: Store the distribution packages |
| 27 | + uses: actions/upload-artifact@v4 |
| 28 | + with: |
| 29 | + name: python-package-distributions |
| 30 | + path: dist/ |
| 31 | + |
| 32 | + publish-to-pypi: |
| 33 | + name: >- |
| 34 | + Publish Python 🐍 distribution 📦 to PyPI |
| 35 | + if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes |
| 36 | + needs: |
| 37 | + - build |
| 38 | + runs-on: ubuntu-latest |
| 39 | + environment: |
| 40 | + name: pypi |
| 41 | + url: ${{ env.PYPI_URL }} |
| 42 | + permissions: |
| 43 | + id-token: write # IMPORTANT: mandatory for trusted publishing |
| 44 | + steps: |
| 45 | + - name: Download all the dists |
| 46 | + uses: actions/download-artifact@v4 |
| 47 | + with: |
| 48 | + name: python-package-distributions |
| 49 | + path: dist/ |
| 50 | + - name: Publish distribution 📦 to PyPI |
| 51 | + uses: pypa/gh-action-pypi-publish@release/v1.10 |
| 52 | + |
| 53 | + github-release: |
| 54 | + name: >- |
| 55 | + Sign the Python 🐍 distribution 📦 with Sigstore |
| 56 | + and upload them to GitHub Release |
| 57 | + needs: |
| 58 | + - publish-to-pypi |
| 59 | + runs-on: ubuntu-latest |
| 60 | + |
| 61 | + permissions: |
| 62 | + contents: write # IMPORTANT: mandatory for making GitHub Releases |
| 63 | + id-token: write # IMPORTANT: mandatory for sigstore |
| 64 | + |
| 65 | + steps: |
| 66 | + - name: Download all the dists |
| 67 | + uses: actions/download-artifact@v4 |
| 68 | + with: |
| 69 | + name: python-package-distributions |
| 70 | + path: dist/ |
| 71 | + - name: Sign the dists with Sigstore |
| 72 | + uses: sigstore/gh-action-sigstore-python@v3 |
| 73 | + with: |
| 74 | + inputs: >- |
| 75 | + ./dist/*.tar.gz |
| 76 | + ./dist/*.whl |
| 77 | + - name: Create GitHub Release |
| 78 | + env: |
| 79 | + GITHUB_TOKEN: ${{ github.token }} |
| 80 | + run: >- |
| 81 | + gh release create |
| 82 | + '${{ github.ref_name }}' |
| 83 | + --repo '${{ github.repository }}' |
| 84 | + --notes "" |
| 85 | + - name: Upload artifact signatures to GitHub Release |
| 86 | + env: |
| 87 | + GITHUB_TOKEN: ${{ github.token }} |
| 88 | + # Upload to GitHub Release using the `gh` CLI. |
| 89 | + # `dist/` contains the built packages, and the |
| 90 | + # sigstore-produced signatures and certificates. |
| 91 | + run: >- |
| 92 | + gh release upload |
| 93 | + '${{ github.ref_name }}' dist/** |
| 94 | + --repo '${{ github.repository }}' |
| 95 | +
|
| 96 | + publish-to-testpypi: |
| 97 | + name: Publish Python 🐍 distribution 📦 to TestPyPI |
| 98 | + if: startsWith(github.ref, 'refs/tags/') # only publish to TestPyPI on tag pushes |
| 99 | + needs: |
| 100 | + - build |
11 | 101 | runs-on: ubuntu-latest
|
12 | 102 |
|
| 103 | + environment: |
| 104 | + name: testpypi |
| 105 | + url: ${{ env.PYPI_TEST_URL }} |
| 106 | + |
| 107 | + permissions: |
| 108 | + id-token: write # IMPORTANT: mandatory for trusted publishing |
| 109 | + |
13 | 110 | steps:
|
14 |
| - - uses: actions/checkout@v4 |
15 |
| - with: |
16 |
| - fetch-depth: 0 |
17 |
| - |
18 |
| - - name: Set up Python |
19 |
| - uses: actions/setup-python@v5 |
20 |
| - with: |
21 |
| - python-version: 3.9 |
22 |
| - |
23 |
| - - name: Install dependencies |
24 |
| - run: | |
25 |
| - python -m pip install -U pip |
26 |
| - python -m pip install -U build hatchling twine |
27 |
| -
|
28 |
| - - name: Build package |
29 |
| - run: | |
30 |
| - hatchling version |
31 |
| - python -m build |
32 |
| - twine check dist/* |
33 |
| -
|
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 |
37 |
| - with: |
38 |
| - user: jazzband |
39 |
| - password: ${{ secrets.JAZZBAND_RELEASE_KEY }} |
40 |
| - repository_url: https://jazzband.co/projects/django-debug-toolbar/upload |
| 111 | + - name: Download all the dists |
| 112 | + uses: actions/download-artifact@v4 |
| 113 | + with: |
| 114 | + name: python-package-distributions |
| 115 | + path: dist/ |
| 116 | + - name: Publish distribution 📦 to TestPyPI |
| 117 | + uses: pypa/gh-action-pypi-publish@release/v1.10 |
| 118 | + with: |
| 119 | + repository-url: https://test.pypi.org/legacy/ |
| 120 | + skip-existing: true |
0 commit comments