Skip to content
"go build" wrapper to add version info to Golang applications
Branch: master
Clone or download
ahmetb Merge pull request #14 from maguro/version
Add option to specify version to be used in build variables
Latest commit eeed55f Nov 2, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information.
integration-test Fix more tests in integration-tests Oct 30, 2017
.gitignore Add cross-compiled release builds via travis Aug 5, 2016
LICENSE README update Aug 5, 2016 Add option to specify version to be used in build variables Sep 15, 2017
VERSION Add -print-ldflags argument Aug 18, 2016
git.go add GitSummary value from git-describe Aug 11, 2016
git_test.go add GitSummary value from git-describe Aug 11, 2016
ldflags.go Wrap "go install" command as well Aug 4, 2016
main.go Fix long map literal formatting Nov 2, 2017
main_test.go Add more robust handling of govvv directives Sep 12, 2017
values.go go fmt cleanup Oct 29, 2017
values_test.go Flesh out tests Oct 29, 2017
version.go handle the case where version is not available Aug 4, 2016


The simple Go binary versioning tool that wraps the go build command.

Stop worrying about -ldflags and go get now.

Build Variables

Variable Description Example
main.GitCommit short commit hash of source tree 0b5ed7a
main.GitBranch current branch name the code is built off master
main.GitState whether there are uncommitted changes clean or dirty
main.GitSummary output of git describe --tags --dirty --always v1.0.0,
main.BuildDate RFC3339 formatted UTC date 2016-08-04T18:07:54Z
main.Version contents of ./VERSION file, if exists, or the value passed via the -version option 2.0.0

Using govvv is easy

Just add the build variables you want to the main package and run:

old new
go build govvv build
go install govvv install

Version your app with govvv

Create a VERSION file in your build root directory and add a Version variable to your main package.

Do you have your own way of specifying Version? No problem:

govvv lets you specify custom -ldflags

Your existing -ldflags argument will still be preserved:

govvv build -ldflags "-X main.BuildNumber=$buildnum" myapp

and the -ldflags constructed by govvv will be appended to your flag.

Don’t want to depend on govvv? It’s fine!

You can just pass a -print argument and govvv will just print the go build command with -ldflags for you and will not execute the go tool:

$ govvv build -print
go build \
    -ldflags \
    "-X main.GitCommit=57b9870 -X main.GitBranch=dry-run -X main.GitState=dirty -X main.Version=0.1.0 -X main.BuildDate=2016-08-08T20:50:21Z"

Still don’t want to wrap the go tool? Well, try -flags to retrieve the LDFLAGS govvv prepares:

$ go build -ldflags="$(govvv -flags)"

Want to use a different package?

You can pass a -pkg argument with the full package name, and govvv will set the build variables in that package instead of main. For example:

# build with govvv
$ govvv build -pkg

# build with go
$ go build -ldflags="$(govvv -flags -pkg $(go list ./mypkg))"

Want to use a different version?

You can pass a -version argument with the desired version, and govvv will use the specified version instead of obtaining it from the ./VERSION file. For example:

# build with govvv
$ govvv build -version 1.2.3

# build with go
$ go build -ldflags="$(govvv -flags -version 1.2.3)"

Try govvv today

$ go get

govvv is distributed under Apache 2.0 License.

Copyright 2016 Ahmet Alp Balkan

Build Status

You can’t perform that action at this time.