"go build" wrapper to add version info to Golang applications

govvv

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

Stop worrying about -ldflags and go get github.com/ahmetb/govvv 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,
v1.0.1-5-g585c78f-dirty,
fbd157c
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 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

Owner
Ahmet Alp Balkan
Senior software engineer at Google Cloud, on cloud-native technologies: Kubernetes/GKE and Cloud Run.
Ahmet Alp Balkan
Comments
  • Add main.GitCommitMsg

    Add main.GitCommitMsg

    govvv is amazing as-is, but I felt that being able to fetch the latest commit's message would be very helpful for not only myself but any others looking to utilize developer messages alongside their git versioning for any public or private releases of their programs. This works completely for me and even comes with a small little bug workaround, so I hope this gets accepted and someone appreciates the work already being done for them (because it took me longer to fix the bug than to add GitCommitMsg) c:

  • stoped working after upgrade to go1.11

    stoped working after upgrade to go1.11

    Hi,

    govvv worked fine with older go version. But go version go1.11 windows/amd64 now returns

    govvv build .\testGit.go go tool: fork/exec C:\Go\bin\go.exe: invalid argument

    go build .\testGit.go works fine

    //test program package main

    import "log"

    var GitCommit, GitBranch, GitState, BuildDate, Version string

    func main() {

    log.Println("Code Status at compile time: ")
    log.Println("   Version:   " + Version)
    log.Println("   GitCommit: " + GitCommit)
    log.Println("   GitBranch: " + GitBranch)
    log.Println("   GitState:  " + GitState)
    log.Println("   BuildDate: " + BuildDate)
    

    }

  • Add support for setting --version from command line

    Add support for setting --version from command line

    Forcing people to use the ./VERSION file seems to be a bit arbitrary. Especially if pre-existing tooling pipelines don't support it. It would be nice if there was something like a --version option to set this value.

  • Feature:  option to specify package in which to set variables

    Feature: option to specify package in which to set variables

    Setting the variables in the main package unfortunately means that they're only visible within main. If I want to use them elsewhere (e.g., display version info in a web page built from my httpsrv package), I have to duplicate the variables in another package, and set them when my application starts.

    Therefore, I'd like an option to specify the package where I want the variables set. For example:

    $ govvv -pkg version -flags
    -X github.com/myaccount/myproject/version.GitState=dirty -X github.com/myaccount/myproject/version.GitSummary=f693f40-dirty -X github.com/myaccount/myproject/version.Version=1.7.5 -X github.com/myaccount/myproject/version.BuildDate=2016-10-18T16:33:47Z -X github.com/myaccount/myproject/version.GitCommit=f693f40 -X github.com/myaccount/myproject/version.GitBranch=staging
    

     

    IMHO, this would be the ideal behavior -- being able to pass version as the argument, and having the tool substitute the full package name (which is required for this to work). But I'd also be fine with just passing the full package name (e.g., github.com/myaccount/myproject/version) as the argument.

    I can probably work on this and submit a PR if you like.

  • Work with spf13/cobra - customise package name

    Work with spf13/cobra - customise package name

    cobra can generate applications quickly.

    However, it puts commands in a cmd package instead of main. This means that govvv can't be used because it requires package main.

    Given that govvv sets a few global variables, it should still work even if the package name was not main. The assumption of course, is that a package name of "not main" is intentional.

    Therefore, it would be nice if a flag could be specified that changed the package name govvv uses from main to something else, example: -package cmd

  • Add option to specify location of build variables

    Add option to specify location of build variables

    Currently, the build variables' location is hardcoded to the package main. This change adds a -pkg option that allows the default package location to be overridden.

  • Add option to specify version to be used in build variables

    Add option to specify version to be used in build variables

    Forcing people to use the ./VERSION file seems to be a bit arbitrary. Especially if pre-existing tooling pipelines don't support it. It would be nice if there was something like a -version option to set this value.

  • [announcement] Changing username for the repo

    [announcement] Changing username for the repo

    I am planning to change my GitHub username to ahmetb soon. If you already vendored this repo (which you should) this change is not going to break your builds, it may cause issues when you try to update the vendored package.

    Leaving this issue open for a while to discuss issues that come up because of the change.

  • 'govvv -flags -pkg' not working properly?

    'govvv -flags -pkg' not working properly?

    I think this is similarly related to #17 and #18.

    Anyways, some info on my environment (want to know anything else?): Go version: 1.12 govvv version: 0.2.0 os/version: ubuntu bionic_18.04-like :1234:

    $ govvv list ./cmd
    # This outputs correctly, for reference.
    github.com/stgarf/paperless-cli/cmd
    $ cat ./VERSION
    # For ref, this is correct and doesn't have any strange characters.
    0.0.1
    $ git describe --tags --dirty --always
    # For reference.
    fba178f
    
    $ govvv -flags -pkg $(govvv list ./cmd) -version $(cat ./VERSION)
    # The package is incorrect for the variables...
    -X main.BuildDate=2019-03-04T00:34:31Z -X main.GitCommit=fba178f -X main.GitBranch=master -X main.GitState=clean -X main.GitSummary=fba178f -X main.Version=0.0.1
    
    # Maybe bash command substitution was the problem, let's explore... notice I change the version to 0.0.2 also.
    $ govvv -flags -pkg github.com/stgarf/paperless-cli/cmd -version 0.0.2
    # Package is wrong and version is wrong...
    -X main.GitCommit=fba178f -X main.GitBranch=master -X main.GitState=clean -X main.GitSummary=fba178f -X main.Version=0.0.1 -X main.BuildDate=2019-03-04T00:47:53Z
    
    # Again, but 0.0.3 for giggles...
    $ govvv -flags -pkg github.com/stgarf/paperless-cli/cmd -version 0.0.3
    -X main.GitCommit=fba178f -X main.GitBranch=master -X main.GitState=clean -X main.GitSummary=fba178f -X main.Version=0.0.1 -X main.BuildDate=2019-03-04T00:47:58Z
    # Package is wrong and version is wrong...
    

    Am I maybe using the tool incorrectly? I'm able to pass the "proper" -ldflags and the resulting binary works as I'd expect it to...

    $ ./build.sh; ./paperless-cli version; rm paperless-cli                                                    [17:48:39]
    Building...
    Build complete.
    paperless-cli v0.1.1 built on 2019-03-04T01:48:57Z from git:68534c2-clean (master) by user@chrx
    

    and the tests are even working correctly...

    $ pwd; go test -v . -run TestGetFlags_pkgFlag
    /home/user/repos/gocode/src/github.com/ahmetb/govvv
    === RUN   TestGetFlags_pkgFlag
    Debugging flags: map[github.com/acct/coolproject/version.BuildDate:2019-03-04T01:54:48Z github.com/acct/coolproject/version.GitBranch:master github.com/acct/coolproject/version.GitCommit:8dbada4 github.com/acct/coolproject/version.GitState:clean github.com/acct/coolproject/version.GitSummary:8dbada4]
    --- PASS: TestGetFlags_pkgFlag (0.07s)
    PASS
    ok  	github.com/ahmetb/govvv	0.072s
    

    (notsure)

Bump-version - Bump a given semantic version, following a given version fragment

bump-version Bump a given semantic version, following a given version fragment.

Feb 7, 2022
Tool which gathers basic info from apk, which can be used for Android penetration testing.
Tool which gathers basic info from apk, which can be used for Android penetration testing.

APKSEC Tool which gathers basic info from apk, which can be used for Android penetration testing. REQUIREMENTS AND INSTALLATION Build APKSEC: git clon

Sep 2, 2022
Build and deploy Go applications on Kubernetes
Build and deploy Go applications on Kubernetes

ko: Easy Go Containers ko is a simple, fast container image builder for Go applications. It's ideal for use cases where your image contains a single G

Jan 5, 2023
A kubernetes plugin which enables dynamically add or remove GPU resources for a running Pod
A kubernetes plugin which enables dynamically add or remove GPU resources for a running Pod

GPU Mounter GPU Mounter is a kubernetes plugin which enables add or remove GPU resources for running Pods. This Introduction(In Chinese) is recommende

Jan 5, 2023
Addon Operator coordinates the lifecycle of Add-ons in managed OpenShift
Addon Operator coordinates the lifecycle of Add-ons in managed OpenShift

Addon Operator Addon Operator coordinates the lifecycle of Addons in managed OpenShift. dev tools setup pre-commit hooks: make pre-commit-install glob

Dec 29, 2022
Tackle Add-on to discover information from a source repository

Tackle Add-ons - Discovery - Languages This add-on explores the source code repository and finds the languages using GitHub Linguist. It's common that

Dec 24, 2021
Application open new tab in chrome when your favourite youtuber add new video.

youtube-opener This application open new tab in Chrome when your favourite youtuber add new video. It checks channel every one minute. How to run go r

Jan 16, 2022
Add, remove, and manage different versions of web-distributed software binaries. No elevated permissions required!
Add, remove, and manage different versions of web-distributed software binaries. No elevated permissions required!

A cross-platform package manager for the web! Add, remove, and manage different versions of web-distributed software binaries. No elevated permissions

Nov 21, 2022
A golang package for comparing and working with k0s version numbers

version A go-language package for managing k0s version numbers. It is based on hashicorp/go-version but adds sorting and comparison capabilities for t

Feb 7, 2022
Go Version Manager

gvm By Josh Bussdieker (jbuss, jaja, jbussdieker) while working at Moovweb Currently lovingly maintained by Benjamin Knigge Pull requests and other an

Jan 2, 2023
A live-updating version of the UNIX wc command.
A live-updating version of the UNIX wc command.

lwc A live-updating version of the UNIX wc command. Installation You can get a prebuilt binary for every major platform from the Releases page. Just e

Jul 26, 2022
Go version manager. Super simple tool to install and manage Go versions. Install go without root. Gobrew doesn't require shell rehash.

gobrew Go version manager Install or update With curl $ curl -sLk https://git.io/gobrew | sh - or with go $ go get -u github.com/kevincobain2000/gobre

Jan 5, 2023
A tool to restart a Docker container with a newer version of the image

repull A tool to restart a Docker container with a newer version of an image used by the container Often you may need to pull a newer version of an im

Nov 28, 2022
Semantic version generator using git commit keywords and overrides

Semantic version generator Project created overnight, to prove that management of semantic versioning is NOT painful and do not require arguments and

Jan 1, 2023
Mutagen Compose is a modified version of Docker Compose that offers automated integration with Mutagen.

Mutagen Compose Mutagen Compose is a (minimally) modified version of Docker Compose that offers automated integration with Mutagen. This allows you to

Dec 22, 2022
Transform latin letters to runes & vice versa. Go version.

Riimut Transform latin letters to runes & vice versa. Go version. Includes transformers for four main runic alphabets: Elder Futhark Younger Futhark M

Aug 2, 2022
Minified version of Project Sherlock written in GO

Minified version of Project Sherlock written in GO

Dec 19, 2022
UpdatedFlowtbag - An updated version of Flowtbag

License Copyright 2011 Daniel Arndt Licensed under the Apache License, Version 2

Jan 5, 2022