|
| 1 | + |
| 2 | +name: Publish Release |
| 3 | + |
| 4 | +permissions: read-all |
| 5 | + |
| 6 | +concurrency: |
| 7 | + # stop previous release runs if tag is recreated |
| 8 | + group: release-${{ github.ref }} |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +on: |
| 12 | + push: |
| 13 | + tags: |
| 14 | + - 'v*' # only publish on version tags (e.g. v1.0.0) |
| 15 | + |
| 16 | +jobs: |
| 17 | + |
| 18 | + lint: |
| 19 | + permissions: |
| 20 | + contents: read |
| 21 | + actions: write |
| 22 | + uses: ./.github/workflows/lint.yml |
| 23 | + secrets: inherit |
| 24 | + |
| 25 | + test: |
| 26 | + permissions: |
| 27 | + contents: read |
| 28 | + actions: write |
| 29 | + uses: ./.github/workflows/test.yml |
| 30 | + secrets: inherit |
| 31 | + |
| 32 | + build: |
| 33 | + name: Build Package |
| 34 | + runs-on: ubuntu-latest |
| 35 | + permissions: |
| 36 | + contents: read |
| 37 | + actions: write |
| 38 | + outputs: |
| 39 | + PACKAGE_NAME: ${{ steps.set-package.outputs.package_name }} |
| 40 | + RELEASE_VERSION: ${{ steps.set-package.outputs.release_version }} |
| 41 | + steps: |
| 42 | + - uses: actions/checkout@v5 |
| 43 | + with: |
| 44 | + persist-credentials: false |
| 45 | + - name: Set up Python |
| 46 | + uses: actions/setup-python@v6 |
| 47 | + with: |
| 48 | + python-version: "3.12" # for tomlib |
| 49 | + - name: Install uv |
| 50 | + uses: astral-sh/setup-uv@v6 |
| 51 | + with: |
| 52 | + enable-cache: true |
| 53 | + - name: Setup Just |
| 54 | + uses: extractions/setup-just@v3 |
| 55 | + - name: Verify Tag |
| 56 | + run: | |
| 57 | + TAG_NAME=${GITHUB_REF#refs/tags/} |
| 58 | + echo "Verifying tag $TAG_NAME..." |
| 59 | + # if a tag was deleted and recreated we may have the old one cached |
| 60 | + # be sure that we're publishing the current tag! |
| 61 | + git fetch --force origin refs/tags/$TAG_NAME:refs/tags/$TAG_NAME |
| 62 | +
|
| 63 | + # verify signature |
| 64 | + curl -sL https://github.com/${{ github.actor }}.gpg | gpg --import |
| 65 | + git tag -v "$TAG_NAME" |
| 66 | +
|
| 67 | + # verify version |
| 68 | + RELEASE_VERSION=$(just validate_version $TAG_NAME) |
| 69 | +
|
| 70 | + # export the release version |
| 71 | + echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV |
| 72 | + - name: Build the binary wheel and a source tarball |
| 73 | + run: just build |
| 74 | + - name: Store the distribution packages |
| 75 | + uses: actions/upload-artifact@v4 |
| 76 | + with: |
| 77 | + name: python-package-distributions |
| 78 | + path: dist/ |
| 79 | + - name: Set Package Name |
| 80 | + id: set-package |
| 81 | + run: |
| 82 | + PACKAGE_NAME=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['name'])") |
| 83 | + echo "PACKAGE_NAME=${PACKAGE_NAME}" >> $GITHUB_ENV |
| 84 | + |
| 85 | + publish-to-pypi: |
| 86 | + name: Publish to PyPI |
| 87 | + needs: |
| 88 | + - lint |
| 89 | + - test |
| 90 | + - build |
| 91 | + - publish-to-testpypi |
| 92 | + runs-on: ubuntu-latest |
| 93 | + environment: |
| 94 | + name: pypi |
| 95 | + url: https://pypi.org/p/${{ needs.build.outputs.PACKAGE_NAME }} |
| 96 | + permissions: |
| 97 | + id-token: write # IMPORTANT: mandatory for trusted publishing |
| 98 | + steps: |
| 99 | + - name: Download all the dists |
| 100 | + uses: actions/download-artifact@v5 |
| 101 | + with: |
| 102 | + name: python-package-distributions |
| 103 | + path: dist/ |
| 104 | + - name: Publish distribution 📦 to PyPI |
| 105 | + uses: pypa/gh-action-pypi-publish@release/v1.13 |
| 106 | + |
| 107 | + github-release: |
| 108 | + name: Publish GitHub Release |
| 109 | + runs-on: ubuntu-latest |
| 110 | + needs: |
| 111 | + - lint |
| 112 | + - test |
| 113 | + - build |
| 114 | + permissions: |
| 115 | + contents: write # IMPORTANT: mandatory for making GitHub Releases |
| 116 | + id-token: write # IMPORTANT: mandatory for sigstore |
| 117 | + |
| 118 | + steps: |
| 119 | + - name: Download all the dists |
| 120 | + uses: actions/download-artifact@v5 |
| 121 | + with: |
| 122 | + name: python-package-distributions |
| 123 | + path: dist/ |
| 124 | + - name: Sign the dists with Sigstore |
| 125 | + uses: sigstore/gh-action-sigstore-python@v3.0.1 |
| 126 | + with: |
| 127 | + inputs: >- |
| 128 | + ./dist/*.tar.gz |
| 129 | + ./dist/*.whl |
| 130 | + - name: Create GitHub Release |
| 131 | + env: |
| 132 | + GITHUB_TOKEN: ${{ github.token }} |
| 133 | + run: >- |
| 134 | + gh release create |
| 135 | + '${{ github.ref_name }}' |
| 136 | + --repo '${{ github.repository }}' |
| 137 | + --generate-notes |
| 138 | + --prerelease |
| 139 | + - name: Upload artifact signatures to GitHub Release |
| 140 | + env: |
| 141 | + GITHUB_TOKEN: ${{ github.token }} |
| 142 | + # Upload to GitHub Release using the `gh` CLI. |
| 143 | + # `dist/` contains the built packages, and the |
| 144 | + # sigstore-produced signatures and certificates. |
| 145 | + run: >- |
| 146 | + gh release upload |
| 147 | + '${{ github.ref_name }}' dist/** |
| 148 | + --repo '${{ github.repository }}' |
| 149 | +
|
| 150 | + publish-to-testpypi: |
| 151 | + name: Publish to TestPyPI |
| 152 | + needs: |
| 153 | + - build |
| 154 | + runs-on: ubuntu-latest |
| 155 | + |
| 156 | + environment: |
| 157 | + name: testpypi |
| 158 | + url: https://test.pypi.org/project/${{ needs.build.outputs.PACKAGE_NAME }} |
| 159 | + |
| 160 | + permissions: |
| 161 | + id-token: write # IMPORTANT: mandatory for trusted publishing |
| 162 | + |
| 163 | + steps: |
| 164 | + - name: Download all the dists |
| 165 | + uses: actions/download-artifact@v5 |
| 166 | + with: |
| 167 | + name: python-package-distributions |
| 168 | + path: dist/ |
| 169 | + - name: Publish distribution 📦 to TestPyPI |
| 170 | + uses: pypa/gh-action-pypi-publish@release/v1.13 |
| 171 | + with: |
| 172 | + repository-url: https://test.pypi.org/legacy/ |
| 173 | + skip-existing: true |
0 commit comments