|
| 1 | +# Manual rehearsal of the release pipeline against TestPyPI |
| 2 | +# (https://test.pypi.org), so a build can be exercised end-to-end — gate, |
| 3 | +# build, upload, pip install — without the release hitting the real index. |
| 4 | +# Run it from the Actions tab against any branch or tag. |
| 5 | +# |
| 6 | +# Mirrors python-publish.yml stage for stage (test gate -> build -> publish). |
| 7 | +# The deliberate differences: |
| 8 | +# - trigger: manual (workflow_dispatch) instead of a published release |
| 9 | +# - index: TestPyPI via repository-url, never PyPI |
| 10 | +# - version: the local segment (+g<sha>) is stripped at build time, because |
| 11 | +# PyPI-family indexes reject local versions; the no-local-version override |
| 12 | +# keeps rehearsal uploads unique per commit (e.g. 0.10.0.dev3). |
| 13 | +# |
| 14 | +# One-time setup before the first run: |
| 15 | +# 1. On test.pypi.org, add a trusted publisher for requirements-as-code |
| 16 | +# pointing at this repository, this workflow file (test-publish.yml), |
| 17 | +# and the `testpypi` environment. |
| 18 | +# 2. In the repository settings, create the `testpypi` environment. |
| 19 | +# |
| 20 | +# Install a rehearsal build (deps come from real PyPI via the extra index): |
| 21 | +# pip install --index-url https://test.pypi.org/simple/ \ |
| 22 | +# --extra-index-url https://pypi.org/simple/ \ |
| 23 | +# requirements-as-code==<rehearsal version> |
| 24 | + |
| 25 | +name: Test Publish (TestPyPI) |
| 26 | + |
| 27 | +on: |
| 28 | + workflow_dispatch: |
| 29 | + |
| 30 | +permissions: |
| 31 | + contents: read |
| 32 | + |
| 33 | +jobs: |
| 34 | + test: |
| 35 | + # Same gate as the real release: the full battery grid must pass before |
| 36 | + # anything is built or uploaded, so the rehearsal proves the gate too. |
| 37 | + uses: ./.github/workflows/tests.yml |
| 38 | + |
| 39 | + rehearsal-build: |
| 40 | + needs: test |
| 41 | + runs-on: ubuntu-latest |
| 42 | + |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@v4 |
| 45 | + with: |
| 46 | + # setuptools-scm derives the version from git tags, so we need the |
| 47 | + # full history + tags (the default shallow checkout omits them). |
| 48 | + fetch-depth: 0 |
| 49 | + |
| 50 | + - uses: actions/setup-python@v5 |
| 51 | + with: |
| 52 | + python-version: "3.x" |
| 53 | + |
| 54 | + - name: Build rehearsal distributions |
| 55 | + env: |
| 56 | + # Strip the +g<sha> local segment; TestPyPI rejects local versions. |
| 57 | + SETUPTOOLS_SCM_OVERRIDES_FOR_REQUIREMENTS_AS_CODE: '{ local_scheme = "no-local-version" }' |
| 58 | + run: | |
| 59 | + python -m pip install build |
| 60 | + python -m build |
| 61 | +
|
| 62 | + - name: Upload distributions |
| 63 | + uses: actions/upload-artifact@v4 |
| 64 | + with: |
| 65 | + name: testpypi-dists |
| 66 | + path: dist/ |
| 67 | + |
| 68 | + testpypi-publish: |
| 69 | + runs-on: ubuntu-latest |
| 70 | + needs: |
| 71 | + - rehearsal-build |
| 72 | + permissions: |
| 73 | + # Mandatory for trusted publishing (same mechanism as the real publish). |
| 74 | + id-token: write |
| 75 | + |
| 76 | + environment: |
| 77 | + name: testpypi |
| 78 | + url: https://test.pypi.org/p/requirements-as-code |
| 79 | + |
| 80 | + steps: |
| 81 | + - name: Retrieve release distributions |
| 82 | + uses: actions/download-artifact@v4 |
| 83 | + with: |
| 84 | + name: testpypi-dists |
| 85 | + path: dist/ |
| 86 | + |
| 87 | + - name: Publish release distributions to TestPyPI |
| 88 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 89 | + with: |
| 90 | + repository-url: https://test.pypi.org/legacy/ |
| 91 | + packages-dir: dist/ |
0 commit comments