|
1 | | -name: release |
2 | 1 |
|
3 | | -on: |
4 | | - release: |
5 | | - types: [published] |
| 2 | +name: Publish Release |
| 3 | + |
| 4 | +permissions: read-all |
6 | 5 |
|
| 6 | +on: |
| 7 | + push: |
| 8 | + tags: |
| 9 | + - 'v*' # only publish on version tags (e.g. v1.0.0) |
7 | 10 |
|
8 | 11 | jobs: |
| 12 | + |
| 13 | + lint: |
| 14 | + uses: ./.github/workflows/lint.yml |
| 15 | + secrets: inherit |
| 16 | + |
9 | 17 | test: |
10 | 18 | uses: ./.github/workflows/test.yml |
11 | 19 | secrets: inherit |
12 | 20 |
|
13 | | - pypi: |
| 21 | + build: |
| 22 | + name: Build Package |
14 | 23 | runs-on: ubuntu-latest |
15 | | - needs: test |
16 | | - environment: release |
17 | 24 | permissions: |
18 | | - contents: write |
19 | | - id-token: write |
| 25 | + actions: write |
| 26 | + outputs: |
| 27 | + PACKAGE_NAME: ${{ steps.set-package.outputs.package_name }} |
20 | 28 | steps: |
21 | | - - uses: actions/checkout@v4 |
22 | | - |
23 | | - - name: Install uv |
24 | | - uses: astral-sh/setup-uv@v5 |
25 | | - with: |
26 | | - enable-cache: true |
27 | | - |
28 | | - - name: Build package |
29 | | - run: | |
30 | | - uv build |
31 | | -
|
32 | | - - name: Upload release assets to GitHub |
33 | | - env: |
34 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
35 | | - run: | |
36 | | - gh release upload ${{ github.event.release.tag_name }} ./dist/* |
37 | | -
|
38 | | - - name: Publish to PyPI |
39 | | - run: | |
40 | | - uv publish |
| 29 | + - uses: actions/checkout@v4 |
| 30 | + - name: Set up Python |
| 31 | + uses: actions/setup-python@v5 |
| 32 | + with: |
| 33 | + python-version: ">=3.11" # for tomlib |
| 34 | + - name: Verify Tag Signature |
| 35 | + run: | |
| 36 | + TAG_NAME=${GITHUB_REF#refs/tags/} |
| 37 | + echo "Verifying tag $TAG_NAME..." |
| 38 | + git tag -v "$TAG_NAME" |
| 39 | + - name: Install pypa/build |
| 40 | + run: |
| 41 | + python3 -m pip install build --user |
| 42 | + - name: Build a binary wheel and a source tarball |
| 43 | + run: python3 -m build |
| 44 | + - name: Store the distribution packages |
| 45 | + uses: actions/upload-artifact@v4 |
| 46 | + with: |
| 47 | + name: python-package-distributions |
| 48 | + path: dist/ |
| 49 | + - name: Set Package Name |
| 50 | + id: set-package |
| 51 | + run: |
| 52 | + PACKAGE_NAME=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['name'])") |
| 53 | + echo "PACKAGE_NAME=${PACKAGE_NAME}" >> $GITHUB_ENV |
| 54 | + |
| 55 | + publish-to-pypi: |
| 56 | + name: Publish to PyPI |
| 57 | + needs: |
| 58 | + - lint |
| 59 | + - test |
| 60 | + - build |
| 61 | + - publish-to-testpypi |
| 62 | + runs-on: ubuntu-latest |
| 63 | + environment: |
| 64 | + name: pypi |
| 65 | + url: https://pypi.org/p/${{ needs.build.outputs.PACKAGE_NAME }} |
| 66 | + permissions: |
| 67 | + id-token: write # IMPORTANT: mandatory for trusted publishing |
| 68 | + steps: |
| 69 | + - name: Download all the dists |
| 70 | + uses: actions/download-artifact@v4 |
| 71 | + with: |
| 72 | + name: python-package-distributions |
| 73 | + path: dist/ |
| 74 | + - name: Publish distribution 📦 to PyPI |
| 75 | + uses: pypa/gh-action-pypi-publish@release/v1.12 |
| 76 | + |
| 77 | + github-release: |
| 78 | + name: Publish GitHub Release |
| 79 | + runs-on: ubuntu-latest |
| 80 | + needs: |
| 81 | + - lint |
| 82 | + - test |
| 83 | + - build |
| 84 | + permissions: |
| 85 | + contents: write # IMPORTANT: mandatory for making GitHub Releases |
| 86 | + id-token: write # IMPORTANT: mandatory for sigstore |
| 87 | + |
| 88 | + steps: |
| 89 | + - name: Download all the dists |
| 90 | + uses: actions/download-artifact@v4 |
| 91 | + with: |
| 92 | + name: python-package-distributions |
| 93 | + path: dist/ |
| 94 | + - name: Sign the dists with Sigstore |
| 95 | + uses: sigstore/gh-action-sigstore-python@v3.0.0 |
| 96 | + with: |
| 97 | + inputs: >- |
| 98 | + ./dist/*.tar.gz |
| 99 | + ./dist/*.whl |
| 100 | + - name: Create GitHub Release |
| 101 | + env: |
| 102 | + GITHUB_TOKEN: ${{ github.token }} |
| 103 | + run: >- |
| 104 | + gh release create |
| 105 | + '${{ github.ref_name }}' |
| 106 | + --repo '${{ github.repository }}' |
| 107 | + --generate-notes |
| 108 | + - name: Upload artifact signatures to GitHub Release |
| 109 | + env: |
| 110 | + GITHUB_TOKEN: ${{ github.token }} |
| 111 | + # Upload to GitHub Release using the `gh` CLI. |
| 112 | + # `dist/` contains the built packages, and the |
| 113 | + # sigstore-produced signatures and certificates. |
| 114 | + run: >- |
| 115 | + gh release upload |
| 116 | + '${{ github.ref_name }}' dist/** |
| 117 | + --repo '${{ github.repository }}' |
| 118 | +
|
| 119 | + publish-to-testpypi: |
| 120 | + name: Publish to TestPyPI |
| 121 | + needs: |
| 122 | + - build |
| 123 | + runs-on: ubuntu-latest |
| 124 | + |
| 125 | + environment: |
| 126 | + name: testpypi |
| 127 | + url: https://test.pypi.org/project/${{ needs.build.outputs.PACKAGE_NAME }} |
| 128 | + |
| 129 | + permissions: |
| 130 | + id-token: write # IMPORTANT: mandatory for trusted publishing |
| 131 | + |
| 132 | + steps: |
| 133 | + - name: Download all the dists |
| 134 | + uses: actions/download-artifact@v4 |
| 135 | + with: |
| 136 | + name: python-package-distributions |
| 137 | + path: dist/ |
| 138 | + - name: Publish distribution 📦 to TestPyPI |
| 139 | + uses: pypa/gh-action-pypi-publish@release/v1.12 |
| 140 | + with: |
| 141 | + repository-url: https://test.pypi.org/legacy/ |
| 142 | + skip-existing: true |
| 143 | + |
| 144 | + # TODO fetch-data requires login |
| 145 | + # notify-django-packages: |
| 146 | + # name: Notify Django Packages |
| 147 | + # runs-on: ubuntu-latest |
| 148 | + # needs: |
| 149 | + # - publish-to-pypi |
| 150 | + # steps: |
| 151 | + # - name: Notify Django Packages |
| 152 | + # run: |
| 153 | + # curl -X GET "https://djangopackages.org/packages/django-typer/fetch-data/" |
0 commit comments