Add build target with version injection via ldflags
- Update Makefile to inject VERSION and GIT_COMMIT at build time - Change Version from const to var to allow ldflags injection - Add build target to create binary with proper version info
This commit is contained in:
parent
82f09a16ec
commit
42161ce489
11
Makefile
11
Makefile
@ -1,4 +1,8 @@
|
|||||||
.PHONY: test lint check-fmt fmt
|
VERSION := 1.0.0
|
||||||
|
GIT_COMMIT := $(shell git rev-parse HEAD)
|
||||||
|
LDFLAGS := -X 'git.eeqj.de/sneak/smartconfig.Version=$(VERSION)' -X 'git.eeqj.de/sneak/smartconfig.GitCommit=$(GIT_COMMIT)'
|
||||||
|
|
||||||
|
.PHONY: test lint check-fmt fmt build
|
||||||
|
|
||||||
test: lint check-fmt
|
test: lint check-fmt
|
||||||
go test -v ./...
|
go test -v ./...
|
||||||
@ -14,4 +18,7 @@ check-fmt:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
|
|
||||||
|
build:
|
||||||
|
go build -ldflags "$(LDFLAGS)" -o smartconfig ./cmd/smartconfig
|
@ -1,7 +1,7 @@
|
|||||||
package smartconfig
|
package smartconfig
|
||||||
|
|
||||||
// Version is the current version of smartconfig
|
// Version is the current version of smartconfig (set at build time with -ldflags)
|
||||||
const Version = "1.0.0"
|
var Version = "dev"
|
||||||
|
|
||||||
// GitCommit is the git commit hash (set at build time with -ldflags)
|
// GitCommit is the git commit hash (set at build time with -ldflags)
|
||||||
var GitCommit = "unknown"
|
var GitCommit = "unknown"
|
||||||
|
Loading…
Reference in New Issue
Block a user