This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
version: Move vX.Y.Z to version.go so it works with go get
, add git info
#304
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.
Followup from #293.
Previously, building with
make
was required forversion
command to output "v0.15.0"; if you justgo get
or clone andgo build .
it would always tell you "v0.0.0-unset" :-(Now the basic vX.Y.Z is always available, and when building with
make
git information is appended:(I added
version --short
mode formake release
to be able to extract the const embedded in version.go without anything else. IMHO that's cleaner than slicing the output ofversion
but could go either way.)Alternatives:
golang/go#22147, golang/go#29814 explore several directions for letting binaries know which git they were built from. ldflags is indeed main current way.
Most of these don't work with bare
go get
.(
go generate
is not an option as go get won't run it, it's intended for the author to run and commit)Go 1.12 has new
debug.ReadBuildInfo()
api that's supposed to automagically provide build info without needing ldflags, but only if you use go modules (?) and people reported some issues using it: golang/go#29228. See also golang-migrate/migrate#172 for example attempt at using that.