fix(version): go install reports the module version, not 0.0.0-dev#307
Merged
Conversation
….0.0-dev A binary built with go install <module>@<version> does not get the release version through ldflags the way a goreleaser build does, so flynn --version printed 0.0.0-dev even when installed at a real tag. Fall back to the module version Go records in the build info when no ldflags version is set, and treat such a build as a real release (not a dev build) for durable-state isolation. A plain source checkout still reports the dev default with its VCS revision.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What
When no release version is stamped through ldflags, resolve the version from the module version Go records in the build info, so a
go install github.com/ionalpha/flynn/cmd/flynn@<version>build reports that version instead of0.0.0-dev. Such a build is also treated as a real release rather than a development build for durable-state isolation.Why
go install <module>@<version>does not pass the-ldflags -X ...version.Version=that the goreleaser build uses, soflynn --versionprinted0.0.0-deveven when installed at a tagged release, andIsDev()routed it to the development data directory. Go stamps the resolved module version into the binary's build info, so using it as the fallback gives the correct version and data-directory behavior. A goreleaser build is unaffected (its ldflags version wins), and a plain source checkout still reports the dev default plus its VCS revision.How to verify
go test ./internal/version/passes, includingTestStampedVersionWins(an ldflags version is reported verbatim and is not a dev build) andTestModuleVersionFallback(a real module version is used, while(devel)and an empty version are not). End to end:go install github.com/ionalpha/flynn/cmd/flynn@<next-tag>thenflynn --versionprints the tag rather than0.0.0-dev.