Giter Site home page Giter Site logo

govvv's Introduction

govvv

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

⚠️⚠️⚠️ 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

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

govvv's People

Contributors

ahmetb avatar maguro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

govvv's Issues

[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.

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.

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

'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
🔢

$ 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)

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)

}

govvv bump?

Hi.
Can you add govvv bump patch, govvv bump minor, govvv bump major commands?
So we can bump patch/minor/major version with govvv.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.