Skip to content

fix: report the real version for go-installed binaries - #5

Merged
juangracia merged 1 commit into
mainfrom
fix/version-from-buildinfo
Aug 17, 2026
Merged

juangracia merged 1 commit into
mainfrom
fix/version-from-buildinfo

Conversation

@juangracia

Copy link
Copy Markdown
Owner

Follow-up polish found while verifying the v0.5.0 release end to end.

The problem

go install github.com/juangracia/gitrespect/cmd/gitrespect@latest produces a binary that goreleaser never stamped with ldflags, so it reported itself as dev:

$ go install github.com/juangracia/gitrespect/cmd/gitrespect@latest
$ gitrespect version
gitrespect dev

That is the install path the README leads with, so the most common way to get gitrespect produced a binary that could not tell you what it was.

The fix

Fall back to the module version from debug.ReadBuildInfo(), but only when the binary actually came from the module proxy.

That condition matters. A build from a local checkout derives Main.Version from the nearest tag, so naively trusting it made an untagged working copy claim to be the previous release:

gitrespect 0.4.1+dirty     # wrong: this tree is newer than v0.4.1

Presence of a vcs.revision build setting distinguishes the two cases. Local builds keep reporting dev, and now also carry the VCS revision and commit time instead of none / unknown.

Result

Build Before After
goreleaser release 0.5.0 + commit unchanged
go install ...@latest dev 0.5.0
local go build dev dev + revision

Tests

First tests for internal/cmd: four cases covering version resolution (proxy install, local checkout, goreleaser-stamped, (devel)), plus coverage of the output flag validation added in #4.

go build, go vet, go test, gofmt -l all clean.

`go install github.com/juangracia/gitrespect/cmd/gitrespect@latest`
produces a binary goreleaser never stamped, so `gitrespect version`
reported "dev" even for a released build.

Fall back to the module version from debug.ReadBuildInfo, but only when
the binary came from the module proxy. A build from a local checkout
derives its version from the nearest tag, so trusting it there would make
an untagged working copy claim to be the previous release.

Local builds keep reporting "dev" and now also carry the VCS revision and
commit time, which is more useful than the previous "none"/"unknown".

Adds the first tests for internal/cmd, covering the version resolution
cases and the output flag validation.
@juangracia juangracia self-assigned this Aug 17, 2026
@juangracia
juangracia merged commit e23bdf2 into main Aug 17, 2026
5 checks passed
@juangracia
juangracia deleted the fix/version-from-buildinfo branch August 17, 2026 19:55
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