|
| 1 | +name: test-release |
| 2 | + |
| 3 | +# Builds the wheel + sdist, uploads to TestPyPI (sanity check only). |
| 4 | +# Called by release.yml before the real PyPI publish. |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_call: |
| 8 | + outputs: |
| 9 | + pkg-name: |
| 10 | + description: "Distribution name from pyproject.toml" |
| 11 | + value: ${{ jobs.build.outputs.pkg-name }} |
| 12 | + version: |
| 13 | + description: "Version from pyproject.toml" |
| 14 | + value: ${{ jobs.build.outputs.version }} |
| 15 | + |
| 16 | +permissions: {} |
| 17 | + |
| 18 | +env: |
| 19 | + PYTHON_VERSION: "3.11" |
| 20 | + |
| 21 | +jobs: |
| 22 | + build: |
| 23 | + if: github.ref == 'refs/heads/main' |
| 24 | + runs-on: ubuntu-latest |
| 25 | + permissions: |
| 26 | + contents: read |
| 27 | + |
| 28 | + outputs: |
| 29 | + pkg-name: ${{ steps.check-version.outputs.pkg-name }} |
| 30 | + version: ${{ steps.check-version.outputs.version }} |
| 31 | + |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v4 |
| 34 | + |
| 35 | + - uses: actions/setup-python@v5 |
| 36 | + with: |
| 37 | + python-version: ${{ env.PYTHON_VERSION }} |
| 38 | + cache: pip |
| 39 | + cache-dependency-path: pyproject.toml |
| 40 | + |
| 41 | + - name: Install build tooling |
| 42 | + run: pip install build |
| 43 | + |
| 44 | + # We keep the build job *separate* from the publish job so a compromised |
| 45 | + # build-time dependency cannot reach the trusted-publishing OIDC token. |
| 46 | + # https://github.com/pypa/gh-action-pypi-publish#non-goals |
| 47 | + - name: Build wheel + sdist |
| 48 | + run: python -m build |
| 49 | + |
| 50 | + - name: Upload build artifacts |
| 51 | + uses: actions/upload-artifact@v4 |
| 52 | + with: |
| 53 | + name: test-dist |
| 54 | + path: dist/ |
| 55 | + |
| 56 | + - name: Extract pkg-name + version |
| 57 | + id: check-version |
| 58 | + run: | |
| 59 | + python -m pip install --quiet tomli |
| 60 | + PKG=$(python -c "import tomli; print(tomli.load(open('pyproject.toml','rb'))['project']['name'])") |
| 61 | + VER=$(python -c "import tomli; print(tomli.load(open('pyproject.toml','rb'))['project']['version'])") |
| 62 | + echo "pkg-name=$PKG" >> "$GITHUB_OUTPUT" |
| 63 | + echo "version=$VER" >> "$GITHUB_OUTPUT" |
| 64 | +
|
| 65 | + publish: |
| 66 | + needs: build |
| 67 | + runs-on: ubuntu-latest |
| 68 | + permissions: |
| 69 | + contents: read |
| 70 | + # Required for PyPI trusted publishing (OIDC token). |
| 71 | + # Configure the trusted publisher at: |
| 72 | + # https://test.pypi.org/manage/account/publishing/ |
| 73 | + id-token: write |
| 74 | + |
| 75 | + steps: |
| 76 | + - uses: actions/download-artifact@v4 |
| 77 | + with: |
| 78 | + name: test-dist |
| 79 | + path: dist/ |
| 80 | + |
| 81 | + - name: Publish to TestPyPI |
| 82 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 83 | + with: |
| 84 | + packages-dir: dist/ |
| 85 | + verbose: true |
| 86 | + print-hash: true |
| 87 | + repository-url: https://test.pypi.org/legacy/ |
| 88 | + # CI-only — overwrites a same-version file if a re-run is needed. |
| 89 | + # https://github.com/pypa/gh-action-pypi-publish#tolerating-release-package-file-duplicates |
| 90 | + skip-existing: true |
| 91 | + # Attestations default-on in v1.11.0+ and require additional |
| 92 | + # trusted-publisher config; disable until we opt in deliberately. |
| 93 | + attestations: false |
0 commit comments