Repository navigation
Release automatically when the version changes - #57
Merged
Merged
Conversation
Add a release job to the Lint and Test workflow. On a push to the default branch, after lint and test pass, it reads the version from package.json and, when the tag v<version> does not exist yet, creates it together with the GitHub release. Tags created with the workflow token do not start other workflows, so the Release workflow is now also callable and is run from the same workflow run with the new tag; its tag trigger is kept so a tag pushed by hand still publishes. Document the procedure in 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 the Lint and Test workflow that runs on pushes to the default branch after lint and test pass. It reads the version frompackage.jsonand, whenv<version>is not tagged yet, creates the tag and the GitHub release (with generated notes) in one step.workflow_callwith ataginput) and call it from the same run when a tag was created, with inherited secrets, so the npm publish happens even though a tag created with the workflow token starts no other workflow. The tag trigger is kept, so pushing a tag by hand still publishes exactly as before; the publish steps and the secret they use are unchanged.How it works
release(indefault.yml) runs only forpushevents on the repository's default branch, needslintandtest, hascontents: write, and is serialised through thereleaseconcurrency group without cancelling runs in progress.sed -nE 's/^ *"version": *"([^"]+)".*/\1/p' package.json | head -1and derives the tagv<version>.git ls-remote --exit-code --tags origin refs/tags/<tag>decides what happens next: exit 0 means the tag exists and the job reports that nothing is released; exit 2 means it is missing andgh release create <tag> --target $GITHUB_SHA --title <tag> --generate-notescreates the tag and the release withGITHUB_TOKEN; any other exit code fails the job. The job exposestagandcreatedas outputs.publishneedsrelease, runs only whencreated == 'true', and calls./.github/workflows/release.ymlwith the tag,secrets: inheritandcontents: read/id-token: write(npm provenance needs the OIDC token).release.ymlgains theworkflow_calltrigger with a requiredtaginput and checks outinputs.tag, falling back togithub.refwhen it is started by a tag push. Lint, test, build andnpm publish --provenance --access publicare unchanged.Verification
3.1.0;git ls-remote --exit-codereturns 2 for the untaggedv3.1.0and 0 for the existingv3.0.1, and the step logic, run locally with theghcall stubbed, setscreated=truefor the first andcreated=falsefor the second.npm version x.y.z --no-git-tag-version, as recommended in the README, updates bothpackage.jsonandpackage-lock.json.releaseandpublishjobs are skipped on pull requests and on pushes to branches other than the default one.package.jsonis already at 3.1.0 andv3.1.0is not tagged, so merging this pull request will tagv3.1.0, create its release and publish 3.1.0 to npm.🤖 Generated with Claude Code