Repository navigation
Release automatically when the version changes - #21
Merged
Merged
Conversation
Add a release job to the CI workflow that runs after the tests on every push to the default branch: it reads the project version from pom.xml and, when tag v<version> does not exist yet, creates the tag and the GitHub release with gh, then publishes to Maven Central by calling the Release workflow in the same run, because a tag created with the workflow token does not trigger other workflows. A merge whose version is already tagged publishes nothing. Make the Release workflow callable with a tag input, keeping its tag push trigger, and 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 toci.ymlthat runs afterteston every push to the default branch, reads the version frompom.xmland, when tagv<version>does not exist yet, creates the tag and the GitHub release and publishes to Maven Central in the same run.release.ymlcallable (workflow_callwith ataginput) while keeping itsv*tag push trigger, so a tag pushed by hand still publishes as before. The deploy step and the secrets it uses are unchanged.How it works
testruns as today for pull requests and pushes.release(needs: test; push to the default branch only;permissions: contents: write; serialized through thereleaseconcurrency group) reads the project version frompom.xmlwithawk, derivesv<version>and checks it withgit ls-remote --exit-code --tags origin refs/tags/<tag>. When the tag is missing it runsgh release create <tag> --target $GITHUB_SHA --title <tag> --generate-noteswith the workflow token and sets the job outputstagandcreated=true; when the tag exists it says so and setscreated=false.publish(needs: release, only whencreated == 'true') callsrelease.ymlwithtagandsecrets: inherit. A tag created with the workflow token does not trigger other workflows, so the Maven Central deploy has to run inside the same run.release.ymlchecks outrefs/tags/<tag>, taking the tag from the input or, on the tag push trigger, fromgithub.ref_name, and runs the unchangedmvn deploy -DskipTests=true.Verification
python3 -c 'import yaml,sys; [yaml.safe_load(open(f)) for f in sys.argv[1:]]' .github/workflows/*.ymlpasses andactionlintv1.7.12 reports no findings for either workflow.0.3.0against the currentpom.xml;git ls-remote --exit-code --tags origin refs/tags/v0.3.0exits 2 (missing) andrefs/tags/v0.2.2exits 0 (present), so a merge of the current version would createv0.3.0.runscripts of thereleasejob were executed locally underbash -ewith a stubgh: they writeversion=0.3.0andtag=v0.3.0, thencreated=truefor the missing tag andcreated=falsefor the existing one..github/and the README change; the build and tests are untouched.releaseandpublishjobs can only run after this is merged; the pull request CI on this branch exercises thetestjob.🤖 Generated with Claude Code