|
1 | 1 | name: Upload Python Package |
2 | 2 |
|
| 3 | +# Publishing a GitHub release uploads the package to PyPI. Running this |
| 4 | +# workflow by hand on main uploads it to TestPyPI. Both use PyPI trusted |
| 5 | +# publishing (OIDC), so no API token is stored in this repository; the |
| 6 | +# publish jobs run in the "pypi" / "testpypi" environments. |
| 7 | + |
3 | 8 | on: |
4 | 9 | release: |
5 | 10 | types: [published] |
|
8 | 13 | permissions: {} |
9 | 14 |
|
10 | 15 | jobs: |
11 | | - deploy: |
| 16 | + build: |
| 17 | + runs-on: ubuntu-latest |
12 | 18 | permissions: |
13 | 19 | contents: read |
14 | | - id-token: write # trusted signing of build provenance attestations |
| 20 | + # for the build provenance attestation |
| 21 | + id-token: write |
15 | 22 | attestations: write |
16 | | - uses: cpp-linter/.github/.github/workflows/py-publish.yml@main |
17 | | - secrets: inherit |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 25 | + with: |
| 26 | + # setuptools_scm needs the tags |
| 27 | + fetch-depth: 0 |
| 28 | + persist-credentials: false |
| 29 | + - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 |
| 30 | + with: |
| 31 | + python-version: '3.x' |
| 32 | + - name: Build wheel |
| 33 | + run: pipx run build --wheel --outdir dist |
| 34 | + - name: Check distribution |
| 35 | + run: pipx run twine check dist/* |
| 36 | + - name: Attest build provenance |
| 37 | + uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 |
| 38 | + with: |
| 39 | + subject-path: dist/* |
| 40 | + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 |
| 41 | + with: |
| 42 | + name: dist |
| 43 | + path: dist |
| 44 | + |
| 45 | + publish-testpypi: |
| 46 | + name: Publish to TestPyPI |
| 47 | + needs: build |
| 48 | + if: >- |
| 49 | + github.event_name == 'workflow_dispatch' && |
| 50 | + github.ref == 'refs/heads/main' && |
| 51 | + github.repository_owner == 'cpp-linter' |
| 52 | + runs-on: ubuntu-latest |
| 53 | + environment: |
| 54 | + name: testpypi |
| 55 | + url: https://test.pypi.org/project/cpp-linter-hooks/ |
| 56 | + permissions: |
| 57 | + id-token: write # trusted publishing |
| 58 | + steps: |
| 59 | + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 |
| 60 | + with: |
| 61 | + name: dist |
| 62 | + path: dist |
| 63 | + - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 |
| 64 | + with: |
| 65 | + repository-url: https://test.pypi.org/legacy/ |
| 66 | + skip-existing: true |
| 67 | + |
| 68 | + publish-pypi: |
| 69 | + name: Publish to PyPI |
| 70 | + needs: build |
| 71 | + if: >- |
| 72 | + github.event_name == 'release' && |
| 73 | + startsWith(github.ref, 'refs/tags/') && |
| 74 | + github.repository_owner == 'cpp-linter' |
| 75 | + runs-on: ubuntu-latest |
| 76 | + environment: |
| 77 | + name: pypi |
| 78 | + url: https://pypi.org/project/cpp-linter-hooks/ |
| 79 | + permissions: |
| 80 | + id-token: write # trusted publishing |
| 81 | + steps: |
| 82 | + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 |
| 83 | + with: |
| 84 | + name: dist |
| 85 | + path: dist |
| 86 | + - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 |
0 commit comments