Skip to content
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

Merged
merged 1 commit into from
Apr 1, 2019

Conversation

cben
Copy link
Contributor

@cben cben commented Mar 5, 2019

Followup from #293.
Previously, building with make was required for version command to output "v0.15.0"; if you just go get or clone and go 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:

$ go run . version
v0.15.0 built from git (unknown)
$ out/container-diff version
v0.15.0 built from git v0.15.0-1-gcd5a837-dirty

(I added version --short mode for make release to be able to extract the const embedded in version.go without anything else. IMHO that's cleaner than slicing the output of version 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.

… info

Previously, building with `make` was required for `version` command to
output v0.15.0; `go get` or `go build` 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:

$ go run . version
v0.15.0 built from git (unknown)
$ out/container-diff version
v0.15.0 built from git v0.15.0-1-gcd5a837-dirty
@cben
Copy link
Contributor Author

cben commented Mar 5, 2019

BTW, I don't think README says how to build from source, initially I didn't notice the Makefile and assumed go get / go build, which is what led me think version command is completely useless :-)

Copy link
Contributor

@nkubala nkubala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cben thanks for addressing this!

@nkubala nkubala merged commit 367eb42 into GoogleContainerTools:master Apr 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants