Releases are published to PyPI by GitHub Actions using Trusted Publishing (GitHub OIDC). There is no PyPI API token, nothing is uploaded from a laptop, and every upload waits for a human to approve it in GitHub.
Two distributions ship from this repository and are versioned independently:
| Distribution | Source | Version lives in |
|---|---|---|
testmcpy |
repository root | pyproject.toml |
testmcpy-oauth-probe |
oauth-probe/ |
oauth-probe/pyproject.toml |
testmcpy hard-depends on the probe (testmcpy-oauth-probe>=X,<Y in
pyproject.toml), so the exact in-tree probe version must be available as a
wheel from PyPI before testmcpy is uploaded. The workflow enforces that
ordering and refuses a source-only probe: downloading an sdist could execute
its build backend in the OIDC-enabled job.
The tag is the release request. Its version must equal the version in the
tagged tree's pyproject.toml; any mismatch fails the release (there is no
fallback that publishes "whatever was built").
| Tag | Releases |
|---|---|
vX.Y.Z |
testmcpy X.Y.Z. The in-tree probe version is released first if it is not on PyPI yet. |
vX.Y.Z is the only release tag. The pypi environment's deployment policy
admits v* tags only, so a tag such as oauth-probe-vX.Y.Z would be rejected at
the environment gate; the workflow does not trigger on it and scripts/publish.sh
has no probe-only mode.
Pre-releases use aN, bN or rcN suffixes (v0.12.0rc1). Anything else
(v1.2, 1.2.3, v1.2.3-beta, release-1.2.3) is rejected. The tagged commit
must be on main.
Pushing a tag is the only trigger. Creating a GitHub Release, running the workflow by hand, or pushing a branch does nothing.
These are account/repository settings, not code. All of them are in place; the workflow depends on them staying that way.
- PyPI trusted publishers (done) on both
testmcpyandtestmcpy-oauth-probe: ownerpreset-io, repositorytestmcpy, workflowpublish.yml, environmentpypi. Renamingpublish.ymlor the environment breaks publishing until both PyPI projects are updated. - GitHub environment
pypi(done): it exists with required reviewers (self-review permitted) and a deployment policy limited to tags matchingv*. Settings → Environments →pypi.
Never push a release tag if the
pypienvironment is missing or has no required reviewers. GitHub silently creates a missing environment the first time a job references it, with no protection, which would let that run publish with no approval.scripts/publish.shchecks throughghthat the environment has required reviewers and a tag deployment policy covering the tag, and refuses to push the tag otherwise.
The old PYPI_API_TOKEN repository secret is no longer read by anything.
Deleting it and revoking the PyPI token is a separate step to do only after the
verification release below has succeeded.
- Bump versions in a normal PR. Change
versioninpyproject.toml; changeoauth-probe/pyproject.tomlonly if the probe changed, and keeptestmcpy'stestmcpy-oauth-probepin range containing the probe version. Merge tomain. Pick a version that is not on PyPI yet: checkhttps://pypi.org/pypi/testmcpy/jsonandhttps://pypi.org/pypi/testmcpy-oauth-probe/jsonfirst, because a version can exist on PyPI without a matching commit or tag in this repository (testmcpy 0.11.21 was uploaded from a local, uncommitted bump before Trusted Publishing).scripts/publish.sh --dry-runalso refuses a version that is already published. Add theCHANGELOG.mdentry in the same PR. - Dry run from an up-to-date
main:Validates the tag against both versions and PyPI, runs lint and unit tests, builds the web UI (scripts/publish.sh --dry-run
npm ci && npm run buildintestmcpy/ui, so Node.js and npm are required), builds the wheel and sdist of each planned distribution, runstwine check, and checks thepypienvironment. It never creates a tag or touches PyPI. - Tag and push:
Runs the same checks, creates the annotated tag locally, then asks before pushing it. Answering
scripts/publish.sh
nleaves the local tag in place (it prints the push command, and how to delete the tag).--skip-testsskips lint and pytest. - Approve the run: Actions → Publish to PyPI → Review deployments →
pypi. Nothing is uploaded until a required reviewer approves.
| Job | Permissions | Does |
|---|---|---|
build |
contents: read, no OIDC |
Checks the tag is on main; validates tag vs. versions and PyPI; runs release/packaging tests; builds the web UI (testmcpy/ui/dist is git-ignored but shipped in the testmcpy wheel and sdist, and verify-dists fails the release if it is missing); builds the planned dists; twine check --strict; installs the built wheels into clean venvs (pip check, CLI smoke); records checksums; uploads one artifact. |
publish |
id-token: write, environment pypi |
Downloads the artifact and runs no repository code: verifies checksums and re-derives tag/version/filenames from the tag itself; uploads the probe (if planned); checks the exact probe version is installable from PyPI; uploads testmcpy. |
homebrew |
contents: write, pull-requests: write, no OIDC |
After testmcpy is published, rewrites Formula/testmcpy.rb (see below), pushes it to chore/homebrew-formula-X.Y.Z and opens a PR against main. Never pushes to main. |
All actions are pinned by full commit SHA, with the version in a comment. Bump them deliberately.
Before publishing, SHA256SUMS must cover every artifact file, including
plan.json, exactly once (excluding the manifest itself). Omissions, extra
entries, duplicate paths, absolute paths, .. components and symlinks are
rejected before any listed file is read; then every digest is verified.
scripts/update_homebrew_formula.py VERSION asks PyPI's JSON API for the sdist
of that version, downloads it, and refuses to touch the formula unless the
download is HTTP 200, non-empty, a valid gzip tarball whose PKG-INFO names
testmcpy VERSION, and its sha256 equals the digest PyPI reports. It then
rewrites both the url and sha256 lines (they must move together) and reads
the file back. Any failure exits non-zero and fails the job.
main is protected (changes must go through a pull request), so the job does
not push to it. It commits the formula to chore/homebrew-formula-X.Y.Z and
opens a PR against main with the job's own GITHUB_TOKEN; a maintainer
merges that PR to finish the release. A failed branch push, or a PR that
cannot be opened, fails the job. Re-runs are idempotent: an existing branch with
the same formula is reused (never force-pushed), and an already-open PR is
left alone. If the branch exists with a different formula the job fails
rather than overwrite it.
Two things to know:
- Opening PRs from Actions needs the repository setting Settings → Actions →
General → Workflow permissions → Allow GitHub Actions to create and approve
pull requests. If it is off, the job fails with a message naming that setting
and the manual command. Enable it and re-run, or run the printed
gh pr create --base main --head chore/homebrew-formula-X.Y.Z ...yourself: the branch is already pushed. - Events created with
GITHUB_TOKENdo not start other workflows, so CI does not run on this PR by itself. If checks are required, close and reopen the PR to start them.
PyPI is already published when this job runs, so if it fails fix the cause and use Re-run failed jobs: the publish job is not repeated. You can also run the script yourself and open the PR by hand.
- Tag/version mismatch, malformed tag, version already on PyPI → the
buildjob fails before anything is uploaded. Delete the tag (git push origin :refs/tags/TAG), fix the version in a PR, and tag again. - Probe uploaded,
testmcpyupload failed → fix the cause and re-run the whole workflow. The plan is recomputed: the probe is now on PyPI, so onlytestmcpyis built and uploaded. PyPI files are immutable andskip-existingis deliberately not used, since it would hide an artifact that differs from the one on PyPI. testmcpypublished but Homebrew sync failed → Re-run failed jobs (see above; for a refused PR, fix the setting first or open the PR by hand). Re-running the whole workflow instead fails at the "already on PyPI" check.- Rejected approval → nothing was uploaded; delete the tag.
The pypi environment exists with required reviewers, so the first real release
doubles as the end-to-end verification. It is a manual operational step and is
not part of the change that introduced this workflow:
- Confirm the environment still has required reviewers and a
v*tag policy (gh api repos/preset-io/testmcpy/environments/pypiand.../environments/pypi/deployment-branch-policies). - Merge a version-bump PR and run
scripts/publish.sh --dry-run, thenscripts/publish.sh. - Confirm the run pauses at Review deployments and that the upload does not start before approval. Approve it.
- Confirm on PyPI that each new release shows it was published via Trusted Publishing from this workflow.
- In a clean venv,
pip install testmcpy==X.Y.Zresolvestestmcpy-oauth-probeandtestmcpy --helpruns. - Confirm the Homebrew job opened a PR from
chore/homebrew-formula-X.Y.Zwhose formulaurlandsha256both nameX.Y.Z, start its checks (close and reopen), and merge it. - Only then delete the
PYPI_API_TOKENsecret and revoke the PyPI token.
- No probe-only release (deferred decision). Because the environment admits
v*tags only, a change tooauth-probe/can only ship together with a newvX.Y.Zoftestmcpy(bump the probe version and cut atestmcpyrelease). Releasing the probe on its own would need anoauth-probe-v*tag policy on thepypienvironment plus restoring that tag path in the workflow,scripts/release_check.pyandscripts/publish.sh. Not done here; for the repository owner to decide. - If the probe's code changes but its version is not bumped, the release does not
notice: the probe's version is already on PyPI, so it is skipped, and
testmcpyships against the older probe. Bump the probe wheneveroauth-probe/changes. - The workflow cannot itself prove the
pypienvironment is protected; onlyscripts/publish.shchecks it (reviewers and tag policy, best effort, throughgh).