Repository navigation
Release automatically when the version changes - #6
Merged
Merged
Conversation
Add a release job to ci.yml that runs after the tests on every push to the default branch. It reads the version from Cargo.toml, derives the tag vX.Y.Z and, when that tag does not exist yet, creates the tag and the GitHub release in one step with gh release create. A merge whose version is already tagged creates nothing; a failed tag lookup fails the job instead of guessing. A release created with the workflow's own token does not trigger the publish workflow, so publish.yml becomes callable (workflow_call with a tag input; the release trigger is kept for releases published by hand) and ci.yml calls it from the same run with secrets: inherit when a release was created. The publish steps and the secret they use are unchanged; the checkout now names the tag being published explicitly. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Add a Releasing section for maintainers: bump the version in Cargo.toml in a pull request and merge it; CI tags vX.Y.Z, creates the release and publishes the crate, and a merge whose version is already tagged publishes nothing. 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
Merging a version bump to
mainis now enough to tag, create the GitHub release and publish the crate to crates.io; nothing is tagged by hand any more..github/workflows/ci.yml: a newreleasejob runs afterteston pushes to the default branch only (permissions: contents: write,concurrency: release). It readsversionfromCargo.toml, derives the tagvX.Y.Zand, when that tag does not exist yet, creates the tag and the GitHub release with generated notes in one step. When the tag exists it does nothing and says so. A newpublishjob (needs: release,if: needs.release.outputs.created == 'true') callspublish.ymlwith the tag andsecrets: inherit..github/workflows/publish.yml: now also callable (on: workflow_callwith a requiredtaginput). Therelease: publishedtrigger is kept, so a release published by hand still publishes as before. The checkout names the tag being published (refs/tags/<input>, or the release's own tag when triggered by a release); the fmt, clippy, test andcargo publishsteps and theCARGO_REGISTRY_TOKENsecret are unchanged.README.md: a short "Releasing" section for maintainers.How it works
test, thenrelease, which runsgit ls-remote --exit-code --tags origin refs/tags/vX.Y.Z: exit 0 means the tag exists (created=false), exit 2 means it is missing andgh release create vX.Y.Z --target $GITHUB_SHA --title vX.Y.Z --generate-notescreates the tag and the release (created=true); any other exit status fails the job rather than guessing. The job'stagandcreatedoutputs drive the next step.GITHUB_TOKENdoes not trigger other workflows, so the publish steps have to run in the same workflow run: thepublishjob callspublish.ymlas a reusable workflow with the tag as input.test;releaseis skipped by itsifandpublishwith it. Theconcurrencygroup makes concurrent pushes queue, and the second one finds the tag already present.Verification
sed -nE 's/^version *= *"([^"]+)".*/\1/p' Cargo.toml | head -1) prints0.1.2for the currentCargo.toml.gh: an existing tag (v0.1.2) givescreated=falseand calls nothing, a missing tag (v9.9.9) callsgh release create v9.9.9 --target <sha> --title v9.9.9 --generate-notesand givescreated=true, an unreachable remote fails the step with thegit ls-remotestatus, and aCargo.tomlwithout a version fails it with an error annotation.v0.1.2is already tagged and published, so merging this pull request creates no release and publishes nothing; the first version bump merged afterwards will be the first automatic release. The push-triggeredreleasejob itself cannot run before the merge.🤖 Generated with Claude Code