|
| 1 | +name: Publish to PyPI |
| 2 | +on: |
| 3 | + release: |
| 4 | + types: |
| 5 | + - released |
| 6 | + - prereleased |
| 7 | + |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + pypi_repo: |
| 11 | + description: Which PyPI repository to use |
| 12 | + required: true |
| 13 | + type: choice |
| 14 | + options: ["pypi", "testpypi"] |
| 15 | + |
| 16 | +permissions: {} |
| 17 | + |
| 18 | +jobs: |
| 19 | + build: |
| 20 | + runs-on: ubuntu-24.04 |
| 21 | + |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 28 | + |
| 29 | + - name: Setup Python |
| 30 | + id: setup-python |
| 31 | + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 |
| 32 | + with: |
| 33 | + python-version: "3.14" |
| 34 | + |
| 35 | + - name: Install uv |
| 36 | + uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7.3.1 |
| 37 | + with: |
| 38 | + python-version: ${{ steps.setup-python.outputs.python-version }} |
| 39 | + version: "0.10.7" |
| 40 | + # hash for uv-x86_64-unknown-linux-gnu.tar.gz.sha256 |
| 41 | + # (from https://github.com/astral-sh/uv/releases) |
| 42 | + checksum: "9ac6cee4e379a5abfca06e78a777b26b7ba1f81cb7935b97054d80d85ac00774" |
| 43 | + |
| 44 | + - name: Build source distributions and wheels |
| 45 | + run: uv build -o ./dist |
| 46 | + |
| 47 | + - name: Upload Build |
| 48 | + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 |
| 49 | + with: |
| 50 | + name: "dist" |
| 51 | + path: "dist/" |
| 52 | + if-no-files-found: error |
| 53 | + retention-days: 5 |
| 54 | + |
| 55 | + publish: |
| 56 | + runs-on: ubuntu-24.04 |
| 57 | + environment: publish-pypi |
| 58 | + |
| 59 | + needs: |
| 60 | + - build |
| 61 | + |
| 62 | + permissions: |
| 63 | + id-token: write # Required for PyPI trusted publishing |
| 64 | + |
| 65 | + steps: |
| 66 | + - name: Download source distributions and wheels |
| 67 | + uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 |
| 68 | + with: |
| 69 | + name: dist |
| 70 | + path: dist |
| 71 | + |
| 72 | + - name: Publish to PyPI |
| 73 | + if: >- |
| 74 | + github.event_name == 'release' |
| 75 | + || ( |
| 76 | + github.event_name == 'workflow_dispatch' |
| 77 | + && github.event.inputs.pypi_repo == 'pypi' |
| 78 | + ) |
| 79 | + uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0 |
| 80 | + |
| 81 | + - name: Publish to TestPyPI |
| 82 | + if: >- |
| 83 | + github.event_name == 'workflow_dispatch' |
| 84 | + && github.event.inputs.pypi_repo == 'testpypi' |
| 85 | + uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0 |
| 86 | + with: |
| 87 | + repository-url: https://test.pypi.org/legacy/ |
0 commit comments