Skip to content

Commit 7c058f2

Browse files
committed
Stable per-branch SNAPSHOTs on CI (git-versioning)
me.qoomon.git-versioning v6.4.4 intermittently fails to detect the branch on GitHub Actions runners and falls back to the rev clause, producing the static gradle.properties version (2.0.0-rc5) instead of <branch-slug>-SNAPSHOT. The failure is per-workflow-run, not per- branch — same SHA, different runs, different results. Root cause: actions/checkout leaves HEAD detached and only creates refs/remotes/origin/<branch>; the plugin's heuristic sometimes picks up the branch via the remote ref and sometimes doesn't. Fix: after each checkout, materialise refs/heads/<branch> with `git update-ref` pointing at HEAD. Deterministic, idempotent, and lets git-versioning find the branch the same way it does locally. Applied to all three workflows that invoke gradle (build-artifacts, gradle-build's publish-gh-packages job, gh-pages). Also adds the missing `fetch-depth: 0` to gh-pages.yml so the branch ref is actually present. Stable per-branch SNAPSHOTs are needed because integration tests publish to and consume from build/maven-repo under the derived coordinate; if it drifts to 2.0.0-rc5 we collide with the upcoming release version and can't reliably exercise the branch's actual code.
1 parent 874be23 commit 7c058f2

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

.github/workflows/build-artifacts.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ jobs:
3131
# and the plugin falls back to gradle.properties' static version.
3232
fetch-depth: 0
3333

34+
- name: Create local branch ref for git-versioning
35+
# actions/checkout leaves HEAD detached and only creates refs/remotes/origin/<branch>.
36+
# me.qoomon.git-versioning v6.4.4 sometimes finds the branch via the remote ref and
37+
# sometimes falls back to the rev clause, producing 2.0.0-rc5 instead of
38+
# <branch-slug>-SNAPSHOT — non-deterministic across workflow runs on the same SHA.
39+
# Materialising refs/heads/<branch> ourselves makes detection reliable.
40+
shell: bash
41+
run: |
42+
BRANCH="${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}"
43+
if [[ -z "$BRANCH" || "$BRANCH" == "HEAD" ]]; then
44+
echo "::notice::No branch name; leaving git-versioning to its own detection."
45+
exit 0
46+
fi
47+
if [[ -z "$GITHUB_HEAD_REF" && "$GITHUB_REF" == refs/tags/* ]]; then
48+
echo "::notice::Tag push; leaving git-versioning to its own detection."
49+
exit 0
50+
fi
51+
git update-ref "refs/heads/$BRANCH" HEAD
52+
echo "::notice::Materialised refs/heads/$BRANCH at $(git rev-parse --short HEAD)"
53+
3454
- name: Setup Java
3555
uses: actions/setup-java@v5
3656
with:

.github/workflows/gh-pages.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@ jobs:
5151

5252
- name: Check out
5353
uses: actions/checkout@v5
54+
with:
55+
# Needed for git-versioning to derive the branch-slug-SNAPSHOT version
56+
# when generate-pages calls `./gradlew -q printVersion`.
57+
fetch-depth: 0
58+
59+
- name: Create local branch ref for git-versioning
60+
# See build-artifacts.yml — without this, git-versioning intermittently falls back
61+
# to gradle.properties' static version, and generate-pages then asks self-check
62+
# for the wrong coordinate.
63+
shell: bash
64+
run: |
65+
BRANCH="${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}"
66+
if [[ -z "$BRANCH" || "$BRANCH" == "HEAD" ]]; then
67+
echo "::notice::No branch name; leaving git-versioning to its own detection."
68+
exit 0
69+
fi
70+
if [[ -z "$GITHUB_HEAD_REF" && "$GITHUB_REF" == refs/tags/* ]]; then
71+
echo "::notice::Tag push; leaving git-versioning to its own detection."
72+
exit 0
73+
fi
74+
git update-ref "refs/heads/$BRANCH" HEAD
75+
echo "::notice::Materialised refs/heads/$BRANCH at $(git rev-parse --short HEAD)"
5476
5577
- name: Setup JDK
5678
uses: actions/setup-java@v5

.github/workflows/gradle-build.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ jobs:
3737
# Needed for git-versioning to derive the branch-slug-SNAPSHOT version.
3838
fetch-depth: 0
3939

40+
- name: Create local branch ref for git-versioning
41+
# See build-artifacts.yml — without this, git-versioning intermittently falls back
42+
# to gradle.properties' static version and publishes under the wrong coordinate.
43+
shell: bash
44+
run: |
45+
BRANCH="${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}"
46+
if [[ -z "$BRANCH" || "$BRANCH" == "HEAD" ]]; then
47+
echo "::notice::No branch name; leaving git-versioning to its own detection."
48+
exit 0
49+
fi
50+
if [[ -z "$GITHUB_HEAD_REF" && "$GITHUB_REF" == refs/tags/* ]]; then
51+
echo "::notice::Tag push; leaving git-versioning to its own detection."
52+
exit 0
53+
fi
54+
git update-ref "refs/heads/$BRANCH" HEAD
55+
echo "::notice::Materialised refs/heads/$BRANCH at $(git rev-parse --short HEAD)"
56+
4057
- name: Setup Java
4158
uses: actions/setup-java@v5
4259
with:

0 commit comments

Comments
 (0)