Skip to content

fix: report module version for go install builds - #4

Merged
tanem merged 1 commit into
mainfrom
fix/go-install-version
Jun 14, 2026
Merged

fix: report module version for go install builds#4
tanem merged 1 commit into
mainfrom
fix/go-install-version

Conversation

@tanem

@tanem tanem commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Problem

go install github.com/tanem/mt5-pnl-cli@latest produces a binary whose version subcommand reports dev:

mt5-pnl-cli dev (schema 1.0)

GoReleaser injects the version via -ldflags "-X main.version=...", so the downloaded release binaries report 1.0.0 correctly — but go install never applies those flags, leaving the dev default. This is the standard GoReleaser/go install gap.

Fix

When the ldflag is unset (version == "dev"), fall back to the module version Go embeds in the build info — runtime/debug.ReadBuildInfo().Main.Version — which is v1.0.0 for go install ...@v1.0.0/@latest. The leading v is trimmed for parity with GoReleaser output. Local builds with no VCS version ((devel)/empty) keep dev.

Release builds are unaffected: the ldflag wins whenever it's set, so GoReleaser output stays 1.0.0.

Notes

  • Logic lives in a pure, injectable versionFrom(ldflag, reader) so all branches are unit-tested deterministically (the package version var and debug.ReadBuildInfo() can't be exercised cleanly otherwise).
  • The binary smoke test no longer asserts a literal version string: a local build's version now depends on build context (ldflag / module version / VCS stamp), so it asserts the stable surrounding format instead.

Test plan

  • go test -race ./... green
  • gofmt -l . clean, go vet ./... clean
  • New TestVersionFrom covers: ldflag wins, go-install resolves module version, (devel) → dev, empty → dev, missing build info → dev.

🤖 Generated with Claude Code

GoReleaser injects the version via -ldflags, so release binaries report
the right version, but `go install ...@latest` left it as "dev". Fall back
to the module version Go embeds in the build info when the ldflag is unset,
so installed binaries report e.g. 1.0.0 (the "v" prefix is trimmed for
parity with GoReleaser output). Local builds without a VCS version keep
"dev".

The binary smoke test no longer asserts a literal version, since a local
build's version now depends on build context (ldflag, module version, or
VCS stamp).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tanem
tanem merged commit 468a205 into main Jun 14, 2026
4 checks passed
@tanem
tanem deleted the fix/go-install-version branch June 15, 2026 01:29
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.

1 participant