|
| 1 | +name: Publish (TestPyPI) |
| 2 | + |
| 3 | +# Fire only after the Tests workflow finishes. The job-level `if` further |
| 4 | +# restricts to successful runs on the `dev` branch. |
| 5 | +# |
| 6 | +# One-time setup required at https://test.pypi.org/manage/account/publishing/ |
| 7 | +# Owner: Botts-Innovative-Research |
| 8 | +# Project: oshconnect |
| 9 | +# Workflow: publish-test.yml |
| 10 | +# Environment: publish-test |
| 11 | +# And in this repo's Settings -> Environments, create an env named |
| 12 | +# `publish-test` (no secrets needed; OIDC handles trust). |
| 13 | +on: |
| 14 | + workflow_run: |
| 15 | + workflows: ["Tests"] |
| 16 | + types: [completed] |
| 17 | + |
| 18 | +permissions: {} |
| 19 | + |
| 20 | +jobs: |
| 21 | + publish: |
| 22 | + if: > |
| 23 | + github.event.workflow_run.conclusion == 'success' |
| 24 | + && github.event.workflow_run.head_branch == 'dev' |
| 25 | + runs-on: ubuntu-latest |
| 26 | + environment: |
| 27 | + name: publish-test |
| 28 | + url: https://test.pypi.org/project/oshconnect/ |
| 29 | + permissions: |
| 30 | + id-token: write # OIDC trusted publishing |
| 31 | + contents: read |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Checkout (matching the tested commit) |
| 35 | + uses: actions/checkout@v5 |
| 36 | + with: |
| 37 | + ref: ${{ github.event.workflow_run.head_sha }} |
| 38 | + |
| 39 | + - name: Install uv |
| 40 | + uses: astral-sh/setup-uv@v6 |
| 41 | + |
| 42 | + - name: Install Python 3.13 |
| 43 | + run: uv python install 3.13 |
| 44 | + |
| 45 | + # Append `.dev<run_number>` to the version in pyproject.toml so each |
| 46 | + # dev push gets a fresh PEP 440-compliant pre-release (e.g. |
| 47 | + # 0.5.1a0 -> 0.5.1a0.dev42). The change is in-memory on the runner; |
| 48 | + # nothing is committed back to the repo. |
| 49 | + - name: Auto-bump version with .devN suffix |
| 50 | + run: | |
| 51 | + python - <<'PY' |
| 52 | + import os, pathlib, re |
| 53 | + run = os.environ['GITHUB_RUN_NUMBER'] |
| 54 | + p = pathlib.Path('pyproject.toml') |
| 55 | + src = p.read_text() |
| 56 | + new = re.sub( |
| 57 | + r'^(version\s*=\s*")([^"]+)(")', |
| 58 | + lambda m: f'{m.group(1)}{m.group(2)}.dev{run}{m.group(3)}', |
| 59 | + src, count=1, flags=re.M, |
| 60 | + ) |
| 61 | + if new == src: |
| 62 | + raise SystemExit("No `version = \"...\"` line found in pyproject.toml") |
| 63 | + p.write_text(new) |
| 64 | + for line in new.splitlines(): |
| 65 | + if line.startswith("version"): |
| 66 | + print(f"Bumped {line}") |
| 67 | + break |
| 68 | + PY |
| 69 | +
|
| 70 | + - name: Build |
| 71 | + run: uv build |
| 72 | + |
| 73 | + - name: Publish to TestPyPI |
| 74 | + run: uv publish --publish-url https://test.pypi.org/legacy/ |
0 commit comments