Publish to PyPI with trusted publishing and create the GitHub release - #41
Merged
Conversation
Swaps the stored PYPI_API_TOKEN for PyPI trusted publishing: the release job runs in a `pypi` environment and uses pypa/gh-action-pypi-publish, which exchanges the job's short-lived GitHub OIDC token for an upload credential. The job already requested `id-token: write` without using it; now it does. Artifacts are collected into dist/ with a wheels-* pattern so the action finds them where it expects. The job also creates the GitHub release for the tag. Pushing v0.8.0 published to PyPI but left no release behind, because a tag and a GitHub release are separate objects and nothing created the latter. It now extracts the matching CHANGELOG section as the release notes (falling back to generated notes if the section is missing rather than failing the release), attaches the wheels and sdist, and re-uploads assets instead of erroring if the release already exists. Documents the flow in docs/contributing.md, which also had the version bump in the wrong file — the version lives in Cargo.toml, and pyproject.toml derives it through maturin. Requires one-time setup on PyPI: register this repository, the ci.yml workflow and the pypi environment as a trusted publisher, then delete the PYPI_API_TOKEN secret.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a3903543a6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
`gh release create` with assets creates a draft, uploads, then publishes, and deletes the draft if an upload fails. If the job dies before that cleanup runs — cancelled run, runner loss — a draft survives, and the already-exists branch would then upload assets and exit successfully, leaving the release invisible. Check isDraft on that path and publish it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two changes to the
releasejob inci.yml, plus the docs that describe it.Trusted publishing
PYO3/maturin-actionwithMATURIN_PYPI_TOKEN→pypa/gh-action-pypi-publish, which exchanges the job's short-lived GitHub OIDC token for a PyPI upload credential. The job already declaredid-token: writewithout using it; now that permission does something and no long-lived PyPI token is stored in repository secrets.pypienvironment (https://pypi.org/p/common-expression-language), which is what the trusted publisher is scoped against and gives you somewhere to add an approval gate later.dist/viapattern: wheels-*+merge-multiple: true, since the action publishesdist/by default.skip-existing: truepreserves the old--skip-existingbehaviour on re-runs.GitHub release creation
Pushing
v0.8.0published to PyPI but left no GitHub release, because a tag and a release are separate objects and nothing in the repo created the latter. The job now does, from the tag:## [X.Y.Z]section ofCHANGELOG.md, extracted with awk. Verified against the real file: 46 lines for0.8.0, empty for a version with no section — in which case it warns and falls back to--generate-notesrather than failing a release that has already published to PyPI.--verify-tagrefuses to invent a tag that doesn't exist.This needs
contents: writeon the job, alongsideid-token: write.Docs
docs/contributing.md's release process said to bump the version inpyproject.toml— the version actually lives inCargo.toml, withpyproject.tomlderiving it through maturin. Corrected, and the tag-driven flow, the trusted-publishing setup, and the workflow/environment names the publisher is tied to are now written down.Required one-time setup before the next tag
This PR cannot configure PyPI, so the next release will fail to upload unless this is done first:
common-expression-language→ Manage → Publishing → Add a new pending/trusted publisher (GitHub):hardbyte, repositorypython-common-expression-languageci.ymlpypipypi(optionally restrict it to tag pushes).PYPI_API_TOKENsecret.All three values must match the workflow exactly — renaming
ci.ymlor the environment means updating the publisher on PyPI too.Verification
The workflow parses (
yaml.safe_load) with the expected permissions, environment and step order; the awk extraction was exercised againstCHANGELOG.mdfor both the present and missing-section cases; docs tests,ruff format --checkandruff checkpass. The release path itself can only be exercised by a real tag push, so0.9.0will be its first live run — theskip-existing,--verify-tagand already-exists guards are there so a partial failure is recoverable.Note that
v0.8.0itself still has no GitHub release; this automation only applies from the next tag. Happy to write the notes for a backfilledv0.8.0release if you create it (the tag push I attempted was blocked — this session's credentials can push branches but not tags).Generated by Claude Code