Skip to content

Fix goreleaser version mislabeling when multiple tags share a commit - #26

Merged
ndenny merged 1 commit into
developfrom
fix/goreleaser-current-tag-race
Sep 21, 2026
Merged

ndenny merged 1 commit into
developfrom
fix/goreleaser-current-tag-race

Conversation

@ndenny

@ndenny ndenny commented Sep 18, 2026

Copy link
Copy Markdown
Member

Summary

  • apimetrics-beta built from the v0.0.1-beta tag reported apimetrics-beta version 0.0.1-qc-stable instead of 0.0.1-beta, even though the environment (beta-client.apimetrics.io) and config directory were correct.
  • Root cause: all four .goreleaser/config*.yaml files set git.tag_sort: -version:refname. When several environment tags point at the same commit (as happened here — v0.0.1-beta, v0.0.1-qc, and v0.0.1-qc-stable were all cut from the same develop HEAD), goreleaser's own git-based "current tag" detection picks whichever co-located tag sorts highest under that key (qc-stable > qc > beta), not the tag that actually triggered the run. That value feeds {{.Version}} into main.version via ldflags.
  • Fix: explicitly set GORELEASER_CURRENT_TAG to $GITHUB_REF_NAME (the tag that triggered the workflow) before invoking goreleaser, so it no longer infers the version from ambiguous git state. This only applies on tag-triggered runs; branch/snapshot dispatches are unaffected.

Detail

This surfaced when three environment builds (beta, qc, qc-stable) were tagged and pushed against the same develop commit within about a minute of each other. qc and qc-stable happened to resolve correctly depending on which sibling tags existed on origin at each job's checkout time; beta did not. Pinning the tag removes the race entirely rather than relying on push ordering/timing.

Test plan

  • Re-cut a beta/qc/qc-stable build sharing a commit and confirm each binary's --version output matches its own tag, not a sibling's.
  • Validated the workflow YAML parses (yq) and reviewed the diff for shell/quoting correctness (no shellcheck available locally).

All four .goreleaser configs sort tags with -version:refname, so when
multiple environment tags point at the same commit (e.g. qc/beta/qc-stable
cut from the same develop HEAD), goreleaser's git-based tag detection
picks whichever tag sorts highest rather than the one that actually
triggered the run — silently baking the wrong version into main.version.

Set GORELEASER_CURRENT_TAG to $GITHUB_REF_NAME so goreleaser always uses
the triggering tag instead of inferring it from git state.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The change is a small, correct, well-scoped CI fix whose bash array usage, tag-ref gating, and goreleaser override variable were all verified, with no other build step needing the same fix.

Review effort: Balanced
Findings: None

What changed in this PR

This PR fixes a version-mislabeling bug in the release workflow's goreleaser build step. Because all four .goreleaser/config*.yaml files use git.tag_sort: -version:refname, when multiple environment tags (e.g. v0.0.1-beta, v0.0.1-qc, v0.0.1-qc-stable) point at the same commit, goreleaser's git-based "current tag" detection can pick a sibling tag rather than the one that triggered the run, embedding the wrong main.version. The fix pins GORELEASER_CURRENT_TAG to $GITHUB_REF_NAME on tag-triggered runs so the version is deterministic.

Changes:

  • On tag-triggered runs, export GORELEASER_CURRENT_TAG="$GITHUB_REF_NAME" and pass it into the goreleaser container.
  • Refactor the docker -e flags into a DOCKER_ENV_ARGS bash array so the new env var is conditionally appended.
  • Add an explanatory comment documenting the root cause.
File Description
.github/​workflows/​release.yml Pins goreleaser's current tag to the triggering ref on tag runs via a conditional GORELEASER_CURRENT_TAG env var, passed through a new DOCKER_ENV_ARGS array.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ndenny
ndenny merged commit 99f7c0b into develop Sep 21, 2026
2 checks passed
@ndenny
ndenny deleted the fix/goreleaser-current-tag-race branch September 21, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants