|
| 1 | +name: Upload A Release to pypi.org or test.pypi.org |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: |
| 6 | + - published |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + dry_run: |
| 10 | + description: "Dry run (build only, do not publish)" |
| 11 | + required: false |
| 12 | + type: boolean |
| 13 | + default: false |
| 14 | + |
| 15 | +jobs: |
| 16 | + release-build: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 21 | + with: |
| 22 | + persist-credentials: false |
| 23 | + |
| 24 | + - name: Set up Python |
| 25 | + uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0 |
| 26 | + with: |
| 27 | + python-version: "3.x" |
| 28 | + |
| 29 | + - name: Build release distributions |
| 30 | + run: | |
| 31 | + scripts/build_pypi_package.sh |
| 32 | +
|
| 33 | + - name: Persist dist folder |
| 34 | + uses: actions/upload-artifact@v4 |
| 35 | + with: |
| 36 | + name: release-dist |
| 37 | + path: dist/ |
| 38 | + |
| 39 | + test-pypi-publish: |
| 40 | + runs-on: ubuntu-latest |
| 41 | + needs: |
| 42 | + - release-build |
| 43 | + if: github.event_name == 'workflow_dispatch' && !github.event.inputs.dry_run |
| 44 | + environment: |
| 45 | + name: testpypi |
| 46 | + permissions: |
| 47 | + id-token: write |
| 48 | + |
| 49 | + steps: |
| 50 | + - name: Retrieve dist folder |
| 51 | + uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 |
| 52 | + with: |
| 53 | + name: release-dist |
| 54 | + path: dist/ |
| 55 | + |
| 56 | + - name: Publish release distributions to test.pypi.org |
| 57 | + # Using OIDC for PyPI publishing (no API tokens needed) |
| 58 | + # See: https://docs.github.com/en/actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-pypi |
| 59 | + uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0 |
| 60 | + with: |
| 61 | + repository-url: https://test.pypi.org/legacy/ |
| 62 | + |
| 63 | + pypi-publish: |
| 64 | + runs-on: ubuntu-latest |
| 65 | + needs: |
| 66 | + - release-build |
| 67 | + if: github.event_name == 'release' |
| 68 | + environment: |
| 69 | + name: pypi |
| 70 | + permissions: |
| 71 | + id-token: write |
| 72 | + |
| 73 | + steps: |
| 74 | + - name: Retrieve dist folder |
| 75 | + uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 |
| 76 | + with: |
| 77 | + name: release-dist |
| 78 | + path: dist/ |
| 79 | + |
| 80 | + - name: Publish release distributions to test.pypi.org |
| 81 | + # Using OIDC for PyPI publishing (no API tokens needed) |
| 82 | + # See: https://docs.github.com/en/actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-pypi |
| 83 | + uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0 |
0 commit comments