Repository navigation
Release automatically when the version changes - #37
Merged
Merged
Conversation
Add a release job to python-publish.yml that runs after the tests on pushes to the default branch, reads the version from setup.cfg and, when no tag of that name exists, creates the tag and the GitHub release with generated notes. The build-n-publish job now waits for it and uploads to PyPI when that tag was created in the same run, keeping a tag pushed by hand as the alternative path. Document the process in a Releasing section of the README. Co-Authored-By: Claude Fable 5.1 <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
releasejob to.github/workflows/python-publish.ymlthat runs after the test matrix on every push tomaster, reads the version fromsetup.cfgand, when no tag of that name exists yet, creates the tag and the GitHub release (with generated notes) in one step.build-n-publishwait for that job and upload to PyPI when the tag was created in the same run; a tag pushed by hand still publishes as before.How it works
releaseis guarded bygithub.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch), needstest, runs withpermissions: contents: writeand in thereleaseconcurrency group without cancellation, so two merges in a row release one after the other.sed -nE 's/^version *= *([^[:space:]]+).*/\1/p' setup.cfg | head -1(tags carry novprefix, matching the existing tags) and checksgit ls-remote --exit-code --tags origin "refs/tags/$TAG": exit 0 means the tag exists and the job reports that there is nothing to release (created=false); exit 2 means it is missing, sogh release create "$TAG" --target "$GITHUB_SHA" --title "$TAG" --generate-notescreates the tag and the release with the workflow's ownGITHUB_TOKEN(created=true); any other exit code fails the job.GITHUB_TOKENdoes not start another workflow run, so publishing happens in the same run:build-n-publishnow hasneeds: [test, release]and its "Publish to PyPI" step runs whenneeds.release.outputs.created == 'true'or, as before, when the run was started by a tag push (startsWith(github.ref, 'refs/tags')). The job itself still runs for every push (full test suite with the API key, then the build), and its condition tolerates the release job being skipped on tag pushes.master, the publish steps and the secrets they use are as before. The version currently insetup.cfg(4.1.0) is already tagged, so merging this pull request releases nothing by itself.Verification
python3 -c 'import yaml,sys; [yaml.safe_load(open(f)) for f in sys.argv[1:]]' .github/workflows/*.ymlpasses.actionlint .github/workflows/*.yml(v1.7.12) reports nothing.4.1.0for the checked-outsetup.cfg.releasejob can only be exercised by a merge.🤖 Generated with Claude Code