Skip to content

Commit

Permalink
Add govm binary version support
Browse files Browse the repository at this point in the history
Version will be constructed by taking the current version (tag)
plus the short commit hash.

Fixes: #23

Signed-off-by: Obed N Munoz <[email protected]>
  • Loading branch information
obedmr committed Oct 2, 2019
1 parent 95f11bf commit dbbb3a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 12 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit dbbb3a6

Please sign in to comment.