Skip to content

Commit b331445

Browse files
authored
Set all version flags at build time so they have correct values (#593)
1 parent c0f2d40 commit b331445

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

.goreleaser.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ builds:
1717
-
1818
env:
1919
- CGO_ENABLED=0
20+
- BUILDER=GoReleaser
2021
goos:
2122
- linux
2223
- darwin

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
export GO111MODULE=on
44

5+
GIT_COMMIT ?= $(shell git rev-parse --verify HEAD)
6+
GIT_VERSION ?= $(shell git describe --tags --always --dirty="-dev")
7+
DATE ?= $(shell date -u '+%Y-%m-%d %H:%M UTC')
8+
BUILDER ?= Makefile
9+
VERSION_FLAGS := -X "main.version=$(GIT_VERSION)" -X "main.date=$(DATE)" -X "main.commit=$(GIT_COMMIT)" -X "main.builtBy=$(BUILDER)"
10+
511
install:
612
@go mod vendor
713

814
build:
9-
@go build
15+
@go build -ldflags='$(VERSION_FLAGS)'
1016

1117
test:
1218
@go test -v ./...

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func init() {
214214
// Output build info (version, commit, date and builtBy)
215215
if versionFlag {
216216
fmt.Printf(
217-
"Current revive version %v commit %v, built @%v by %v.\n",
217+
"Version:\t%s\nCommit:\t\t%s\nBuilt\t\t%s by %s\n",
218218
version,
219219
commit,
220220
date,

0 commit comments

Comments
 (0)