|
1 | | -# This workflow will upload a Python Package to PyPI when a release is created |
2 | | -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries |
3 | | - |
4 | | -# This workflow uses actions that are not certified by GitHub. |
5 | | -# They are provided by a third-party and are governed by |
6 | | -# separate terms of service, privacy policy, and support |
7 | | -# documentation. |
8 | | - |
9 | | -name: Upload Python Package |
10 | | - |
11 | | -on: |
12 | | - release: |
13 | | - types: [published] |
14 | | - |
15 | | -permissions: |
16 | | - contents: read |
17 | | - |
| 1 | +name: Publish Python distribution to PyPI |
| 2 | +on: push |
18 | 3 | jobs: |
19 | | - release-build: |
| 4 | + lint-and-test: |
| 5 | + if: github.ref_type == 'tag' |
| 6 | + name: Run linter and tests |
| 7 | + uses: ./.github/workflows/Lint-and-test.yml |
| 8 | + build: |
| 9 | + needs: lint-and-test |
| 10 | + if: github.ref_type == 'tag' |
| 11 | + name: build distribution |
20 | 12 | runs-on: ubuntu-latest |
21 | 13 |
|
22 | 14 | steps: |
23 | | - - uses: actions/checkout@v4 |
24 | | - with: |
25 | | - fetch-depth: 0 |
26 | | - |
27 | | - - uses: actions/setup-python@v5 |
28 | | - with: |
29 | | - python-version: "3.x" |
30 | | - |
31 | | - - name: Build release distributions |
32 | | - run: | |
33 | | - # NOTE: put your own distribution build steps here. |
34 | | - python -m pip install build |
35 | | - python -m build |
36 | | -
|
37 | | - - name: Upload distributions |
38 | | - uses: actions/upload-artifact@v4 |
39 | | - with: |
40 | | - name: release-dists |
41 | | - path: dist/ |
42 | | - |
43 | | - pypi-publish: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + - name: Set up Python |
| 17 | + uses: actions/setup-python@v5 |
| 18 | + with: |
| 19 | + python-version: "3.11" |
| 20 | + - name: Install pypa/build |
| 21 | + run: >- |
| 22 | + python3 -m |
| 23 | + pip install |
| 24 | + build |
| 25 | + --user |
| 26 | + - name: Build a binary wheel and a source tarball |
| 27 | + run: python3 -m build |
| 28 | + - name: Store the distribution packages |
| 29 | + uses: actions/upload-artifact@v4 |
| 30 | + with: |
| 31 | + name: python-package-distributions |
| 32 | + path: dist/ |
| 33 | + publish-to-pypi: |
| 34 | + name: >- |
| 35 | + Publish Python distribution to PyPI |
| 36 | + if: github.ref_type == 'tag' |
| 37 | + needs: [lint-and-test, build] |
44 | 38 | runs-on: ubuntu-latest |
45 | | - needs: |
46 | | - - release-build |
| 39 | + environment: |
| 40 | + name: release |
| 41 | + url: https://pypi.org/p/lewis |
47 | 42 | permissions: |
48 | | - # IMPORTANT: this permission is mandatory for trusted publishing |
49 | | - id-token: write |
| 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 |
| 52 | + github-release: |
| 53 | + name: >- |
| 54 | + Sign the Python distribution with Sigstore |
| 55 | + and upload them to GitHub Release |
| 56 | + needs: [lint-and-test, build, publish-to-pypi] |
| 57 | + runs-on: ubuntu-latest |
50 | 58 |
|
51 | | - # Dedicated environments with protections for publishing are strongly recommended. |
52 | | - # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules |
53 | | - environment: |
54 | | - name: pypi |
55 | | - # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status: |
56 | | - # url: https://pypi.org/p/YOURPROJECT |
57 | | - # |
58 | | - # ALTERNATIVE: if your GitHub Release name is the PyPI project version string |
59 | | - # ALTERNATIVE: exactly, uncomment the following line instead: |
60 | | - # url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }} |
| 59 | + permissions: |
| 60 | + contents: write # IMPORTANT: mandatory for making GitHub Releases |
| 61 | + id-token: write # IMPORTANT: mandatory for sigstore |
61 | 62 |
|
62 | 63 | steps: |
63 | | - - name: Retrieve release distributions |
64 | | - uses: actions/download-artifact@v4 |
65 | | - with: |
66 | | - name: release-dists |
67 | | - path: dist/ |
68 | | - |
69 | | - - name: Publish release distributions to PyPI |
70 | | - uses: pypa/gh-action-pypi-publish@release/v1 |
71 | | - with: |
72 | | - packages-dir: dist/ |
| 64 | + - name: Download all the dists |
| 65 | + uses: actions/download-artifact@v4 |
| 66 | + with: |
| 67 | + name: python-package-distributions |
| 68 | + path: dist/ |
| 69 | + - name: Sign the dists with Sigstore |
| 70 | + |
| 71 | + with: |
| 72 | + inputs: >- |
| 73 | + ./dist/*.tar.gz |
| 74 | + ./dist/*.whl |
| 75 | + - name: Create GitHub Release |
| 76 | + env: |
| 77 | + GITHUB_TOKEN: ${{ github.token }} |
| 78 | + run: >- |
| 79 | + gh release create |
| 80 | + '${{ github.ref_name }}' |
| 81 | + --repo '${{ github.repository }}' |
| 82 | + --notes "" |
| 83 | + - name: Upload artifact signatures to GitHub Release |
| 84 | + env: |
| 85 | + GITHUB_TOKEN: ${{ github.token }} |
| 86 | + # Upload to GitHub Release using the `gh` CLI. |
| 87 | + # `dist/` contains the built packages, and the |
| 88 | + # sigstore-produced signatures and certificates. |
| 89 | + run: >- |
| 90 | + gh release upload |
| 91 | + '${{ github.ref_name }}' dist/** |
| 92 | + --repo '${{ github.repository }}' |
0 commit comments