Publish to PyPI on a push to main that bumps the version - #313
Merged
Conversation
The existing release_artifacts job was unreachable: it was gated on `contains(github.ref, 'refs/tags/')`, but the workflow only triggers on `push: branches: [main]`, so github.ref was always refs/heads/main. Replace that gate with a check_version job that reads project.version from pyproject.toml at HEAD and at github.event.before and releases only when they differ. It falls back to HEAD^ when `before` is absent (new branch) or has been force-pushed away, and skips a version already on PyPI so re-running the workflow is safe. release_artifacts now also needs build_sdist -- it previously needed only build_wheels, so it could publish without the sdist -- tags at the bare version to match the existing convention (2.6.1, not v2.6.1), and marks aN/bN/rcN/.devN as GitHub pre-releases. Also fix the Pip workflow triggering on pushes to `master`, which this repo does not have, so the test suite has never run on a push to main. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Summary
Adds a
check_versionjob towheels.ymlthat gates the PyPI publish on the version inpyproject.tomlactually changing.Heads up: this needs a Trusted Publisher configured on PyPI before it will work — see below.
The existing release job was unreachable
release_artifactswas gated on:but the workflow only triggers on
push: branches: [main], sogithub.refis alwaysrefs/heads/mainand that condition can never be true. Whatever published2.6.3.dev1–dev4was not this job. Worth confirming there isn't another publish path that would now double up.How the gate works
check_versionreadsproject.versionfrompyproject.tomlatHEADand atgithub.event.before, and setsshould_release=trueonly when they differ. It:HEAD^whenbeforeis all-zeros (branch just created) or points at a commit that a force-push removed;400 File already exists;aN/bN/rcN/.devNas GitHub pre-releases (.postNis deliberately not one).Verified against real commits in this repo's history:
983b3d52.6.3.dev4→2.6.3.dev5eb2783b6f70157dev3→dev4Since
dev1–dev4are all on PyPI, "any bump publishes" is treated as intended rather than special-casing dev versions.Other changes to
release_artifactsneeds: build_sdistas well asbuild_wheels. It previously needed onlybuild_wheels, so it could publish without the sdist.2.6.1), matching the existing tag convention rather thanv2.6.1.skip-existing: trueon the publish step.pip.ymlfixIt triggered on
push: branches: [master]. This repo's default branch ismain, so the pytest suite has never run on a push tomain. One-word fix.Required PyPI setup
The publish step uses OIDC (
id-token: write, no password) and the repo has no secrets configured, so a Trusted Publisher must be added or auth will fail:Leave the environment blank — this job intentionally has no
environment:key, so an environment claim would mismatch. (Alternative: add aPYPI_API_TOKENsecret andpassword:to the publish step.)Repo-side is already fine: default workflow permissions are
write, so tagging and creating the GitHub release will work.Not addressed
Nothing gates the release on tests.
build_wheelssets noCIBW_TEST_COMMAND, andpip.ymlis a separate workflow so it can't be aneeds:dependency. Separately, the wheel upload step hascontinue-on-error: true, so a failed artifact upload won't fail the job — a release could go out with wheels silently missing for a platform. Both are outside the scope of this change but worth a follow-up.🤖 Generated with Claude Code