From dbbb3a676cf0428e670c0483237b6ed603445ca2 Mon Sep 17 00:00:00 2001 From: Obed N Munoz Date: Wed, 2 Oct 2019 11:29:47 -0500 Subject: [PATCH] Add govm binary version support Version will be constructed by taking the current version (tag) plus the short commit hash. Fixes: #23 Signed-off-by: Obed N Munoz --- .goreleaser.yml | 14 ++++++++++++-- main.go | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 27f4af6..ff05f41 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -7,8 +7,18 @@ before: # you may remove this if you don't need go generate - go generate ./... builds: -- env: - - CGO_ENABLED=0 +- + env: + - CGO_ENABLED=0 + goos: + - freebsd + - linux + goarch: + - amd64 + - arm + - arm64 + ldflags: + - -s -w -X main.version={{.Tag}}-{{.ShortCommit}} archive: replacements: linux: Linux diff --git a/main.go b/main.go index 7f5668e..e4bb578 100644 --- a/main.go +++ b/main.go @@ -8,11 +8,13 @@ import ( clilib "gopkg.in/urfave/cli.v2" ) +var version = "undefined" + func main() { // Custom version printer to show the Revision revision := "" clilib.VersionPrinter = func(c *clilib.Context) { - fmt.Fprintf(c.App.Writer, "%s version %s", c.App.Name, c.App.Version) + fmt.Fprintf(c.App.Writer, "%s version %s", c.App.Name, version) if revision != "" { fmt.Fprintf(c.App.Writer, " revision %s", revision) }