Awesome Go

govvv

CategorySoftware Packages
SubcategoryDevOps Tools
Stars0

“go build” wrapper to easily add version information into Go binaries

About govvv

govvv

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

:warning::warning::warning: DEPRECATED: Go now offers build info natively. Please migrate to use that instead. I am no longer planning to maintain this project.

Stop worrying about -ldflags and go get github.com/ahmetb/govvv now.

Build Variables

VariableDescriptionExample
main.GitCommitshort commit hash of source tree0b5ed7a
main.GitBranchcurrent branch name the code is built offmaster
main.GitStatewhether there are uncommitted changesclean or dirty
main.GitSummaryoutput of git describe --tags --dirty --alwaysv1.0.0, v1.0.1-5-g585c78f-dirty, fbd157c
main.BuildDateRFC3339 formatted UTC date2016-08-04T18:07:54Z
main.Versioncontents of ./VERSION file, if exists, or the value passed via the -version option2.0.0

Using govvv is easy

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

old:sparkles: new :sparkles:
go buildgovvv build
go installgovvv 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 github.com/myacct/myproj/mypkg

# 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 github.com/ahmetb/govvv

govvv is distributed under Apache 2.0 License.

Copyright 2016 Ahmet Alp Balkan


Build Status

Frequently Asked Questions

What is govvv?

govvv is a Software Packages library for the Go programming language. “go build” wrapper to easily add version information into Go binaries

How do I install govvv?

Install govvv with the Go module system using `go get ahmetalpbalkan/govvv`. Check the repository for the current installation instructions.

What category does govvv belong to?

govvv is listed under Software Packages, specifically DevOps Tools.

← Back to DevOps Tools