Repository navigation
fix: report the real version for go-installed binaries - #5
Merged
Merged
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up polish found while verifying the v0.5.0 release end to end.
The problem
go install github.com/juangracia/gitrespect/cmd/gitrespect@latestproduces a binary that goreleaser never stamped with ldflags, so it reported itself asdev: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.Versionfrom the nearest tag, so naively trusting it made an untagged working copy claim to be the previous release:Presence of a
vcs.revisionbuild setting distinguishes the two cases. Local builds keep reportingdev, and now also carry the VCS revision and commit time instead ofnone/unknown.Result
0.5.0+ commitgo install ...@latestdev0.5.0go builddevdev+ revisionTests
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 -lall clean.