|
| 1 | +name:Publish Release |
| 2 | + |
| 3 | +concurrency: |
| 4 | +# stop previous release runs if tag is recreated |
| 5 | +group:release-${{ github.ref }} |
| 6 | +cancel-in-progress:true |
| 7 | + |
| 8 | +on: |
| 9 | +push: |
| 10 | +tags: |
| 11 | +# Order matters, the last rule that applies to a tag |
| 12 | +# is the one that takes effect: |
| 13 | +# https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-branches-and-tags |
| 14 | + -'*' |
| 15 | +# There should be no dev tags created, but to be safe, |
| 16 | +# let's not publish them. |
| 17 | + -'!*.dev*' |
| 18 | + |
| 19 | +env: |
| 20 | +PYPI_URL:https://pypi.org/p/djangorestframework |
| 21 | +PYPI_TEST_URL:https://test.pypi.org/p/djangorestframework |
| 22 | + |
| 23 | +jobs: |
| 24 | +build: |
| 25 | +name:Build distribution 📦 |
| 26 | +runs-on:ubuntu-latest |
| 27 | +steps: |
| 28 | + -uses:actions/checkout@v6 |
| 29 | + -name:Set up Python |
| 30 | +uses:actions/setup-python@v6 |
| 31 | +with: |
| 32 | +python-version:"3.x" |
| 33 | + -name:Install pypa/build |
| 34 | +run: |
| 35 | +python3 -m pip install build --user |
| 36 | + -name:Build a binary wheel and a source tarball |
| 37 | +run:python3 -m build |
| 38 | + -name:Store the distribution packages |
| 39 | +uses:actions/upload-artifact@v6 |
| 40 | +with: |
| 41 | +name:python-package-distributions |
| 42 | +path:dist/ |
| 43 | + |
| 44 | +publish-to-testpypi: |
| 45 | +name:Publish Python 🐍 distribution 📦 to TestPyPI |
| 46 | +needs: |
| 47 | + -build |
| 48 | +runs-on:ubuntu-latest |
| 49 | +environment: |
| 50 | +name:testpypi |
| 51 | +url:${{ env.PYPI_TEST_URL }} |
| 52 | +permissions: |
| 53 | +id-token:write# IMPORTANT: mandatory for trusted publishing |
| 54 | +steps: |
| 55 | + -name:Download all the dists |
| 56 | +uses:actions/download-artifact@v7 |
| 57 | +with: |
| 58 | +name:python-package-distributions |
| 59 | +path:dist/ |
| 60 | + -name:Publish distribution 📦 to TestPyPI |
| 61 | +uses:pypa/gh-action-pypi-publish@release/v1.13 |
| 62 | +with: |
| 63 | +repository-url:https://test.pypi.org/legacy/ |
| 64 | +skip-existing:true |
| 65 | + |
| 66 | +publish-to-pypi: |
| 67 | +name:Publish Python 🐍 distribution 📦 to PyPI |
| 68 | +needs: |
| 69 | + -build |
| 70 | + -publish-to-testpypi |
| 71 | +runs-on:ubuntu-latest |
| 72 | +environment: |
| 73 | +name:pypi |
| 74 | +url:${{ env.PYPI_URL }} |
| 75 | +permissions: |
| 76 | +id-token:write# IMPORTANT: mandatory for trusted publishing |
| 77 | +steps: |
| 78 | + -name:Download all the dists |
| 79 | +uses:actions/download-artifact@v7 |
| 80 | +with: |
| 81 | +name:python-package-distributions |
| 82 | +path:dist/ |
| 83 | + -name:Publish distribution 📦 to PyPI |
| 84 | +uses:pypa/gh-action-pypi-publish@release/v1.13 |
| 85 | + |
| 86 | +github-release: |
| 87 | +name:>- |
| 88 | + Sign the Python 🐍 distribution 📦 with Sigstore |
| 89 | + and upload them to GitHub Release |
| 90 | +needs: |
| 91 | + -publish-to-pypi |
| 92 | +runs-on:ubuntu-latest |
| 93 | +permissions: |
| 94 | +contents:write# IMPORTANT: mandatory for making GitHub Releases |
| 95 | +id-token:write# IMPORTANT: mandatory for sigstore |
| 96 | +steps: |
| 97 | + -name:Download all the dists |
| 98 | +uses:actions/download-artifact@v7 |
| 99 | +with: |
| 100 | +name:python-package-distributions |
| 101 | +path:dist/ |
| 102 | + -name:Sign the dists with Sigstore |
| 103 | +uses:sigstore/gh-action-sigstore-python@v3.2.0 |
| 104 | +with: |
| 105 | +inputs:>- |
| 106 | + ./dist/*.tar.gz |
| 107 | + ./dist/*.whl |
| 108 | + -name:Create GitHub Release |
| 109 | +env: |
| 110 | +GITHUB_TOKEN:${{ github.token }} |
| 111 | +run:>- |
| 112 | + gh release create |
| 113 | + '${{ github.ref_name }}' |
| 114 | + --repo '${{ github.repository }}' |
| 115 | + --notes "" |
| 116 | + -name:Upload artifact signatures to GitHub Release |
| 117 | +env: |
| 118 | +GITHUB_TOKEN:${{ github.token }} |
| 119 | +# Upload to GitHub Release using the `gh` CLI. |
| 120 | +# `dist/` contains the built packages, and the |
| 121 | +# sigstore-produced signatures and certificates. |
| 122 | +run:>- |
| 123 | + gh release upload |
| 124 | + '${{ github.ref_name }}' dist/** |
| 125 | + --repo '${{ github.repository }}' |