From 3a7d9ede90e355904ed80d76dfae8d1f81b9648b Mon Sep 17 00:00:00 2001 From: dudiedri Date: Wed, 23 Sep 2026 13:50:47 +0300 Subject: [PATCH] ci(publish): run the version guard on workflow_dispatch too The tag/pom cross-check was gated on startsWith(github.ref, 'refs/tags/v'), but workflow_dispatch sets github.ref to the branch holding the workflow file (refs/heads/main) regardless of which ref is checked out. The guard therefore skipped on every dispatch - the exact path used to re-drive a failed release, and the one most likely to be pointed at the wrong ref under pressure. Observed on the v1.4.0 re-run, where the step reported "skipped". Now reads the ref that was actually built (inputs.ref on dispatch, ref_name on a tag push) and compares on both triggers. A ref that makes no version claim - a SHA or a branch name - skips the comparison and says which pom version it is about to publish, rather than failing on something it cannot check. Verified against the ref shapes that reach this workflow: v1.4.0 -> claims 1.4.0, pom 1.4.0 => pass v1.3.0 -> claims 1.3.0, pom 1.4.0 => blocked v2.0.0-rc1 -> claims 2.0.0-rc1, pom 1.4.0 => blocked 4660c7d / main -> no claim, cross-check skipped Co-Authored-By: Claude Opus 5 --- .github/workflows/publish.yml | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 404a6b9..4f5b510 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -57,14 +57,30 @@ jobs: # When they disagree, v1.3.0 silently publishes 1.4.0 (or worse, republishes an # existing version), which is exactly the ambiguity that let this repo's main and # Maven Central diverge. Refuse rather than guess. - - name: Verify the tag matches the pom version - if: startsWith(github.ref, 'refs/tags/v') + # Runs on BOTH triggers. Gating this on github.ref made it skip on every + # workflow_dispatch, because that sets github.ref to the branch holding the workflow + # file (refs/heads/main) no matter which ref was checked out - so the guard was absent + # from exactly the path used to re-drive a failed release. Read the ref that was + # actually built instead. + - name: Verify the ref's version claim matches the pom + env: + BUILT_REF: ${{ github.event.inputs.ref || github.ref_name }} run: | + case "$BUILT_REF" in + v[0-9]*) + claimed="${BUILT_REF#v}" + ;; + *) + # A SHA or branch name asserts no version, so there is nothing to contradict. + echo "Ref '$BUILT_REF' makes no version claim; skipping the cross-check." + echo "Publishing pom version $(mvn -B -q -DforceStdout help:evaluate -Dexpression=project.version)." + exit 0 + ;; + esac pom_version=$(mvn -B -q -DforceStdout help:evaluate -Dexpression=project.version) - tag_version="${GITHUB_REF_NAME#v}" - echo "tag: $tag_version pom: $pom_version" - if [ "$pom_version" != "$tag_version" ]; then - echo "::error::Tag $GITHUB_REF_NAME does not match pom version $pom_version. Bump the pom and re-tag." + echo "ref claims: $claimed pom says: $pom_version" + if [ "$pom_version" != "$claimed" ]; then + echo "::error::Ref $BUILT_REF claims version $claimed but the pom is $pom_version. Publishing would ship $pom_version under a $BUILT_REF label." exit 1 fi