Skip to content

Commit

Permalink
Set all version flags at build time so they have correct values (#593)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvejmz authored Oct 15, 2021
1 parent c0f2d40 commit b331445
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ builds:
-
env:
- CGO_ENABLED=0
- BUILDER=GoReleaser
goos:
- linux
- darwin
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

export GO111MODULE=on

GIT_COMMIT ?= $(shell git rev-parse --verify HEAD)
GIT_VERSION ?= $(shell git describe --tags --always --dirty="-dev")
DATE ?= $(shell date -u '+%Y-%m-%d %H:%M UTC')
BUILDER ?= Makefile
VERSION_FLAGS := -X "main.version=$(GIT_VERSION)" -X "main.date=$(DATE)" -X "main.commit=$(GIT_COMMIT)" -X "main.builtBy=$(BUILDER)"

install:
@go mod vendor

build:
@go build
@go build -ldflags='$(VERSION_FLAGS)'

test:
@go test -v ./...
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func init() {
// Output build info (version, commit, date and builtBy)
if versionFlag {
fmt.Printf(
"Current revive version %v commit %v, built @%v by %v.\n",
"Version:\t%s\nCommit:\t\t%s\nBuilt\t\t%s by %s\n",
version,
commit,
date,
Expand Down

0 comments on commit b331445

Please sign in to comment.