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:
Jeffrey Paul 2025-07-22 13:50:24 +02:00
parent 82f09a16ec
commit 42161ce489
2 changed files with 11 additions and 4 deletions

View File

@ -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
go test -v ./...
@ -14,4 +18,7 @@ check-fmt:
fi
fmt:
go fmt ./...
go fmt ./...
build:
go build -ldflags "$(LDFLAGS)" -o smartconfig ./cmd/smartconfig

View File

@ -1,7 +1,7 @@
package smartconfig
// Version is the current version of smartconfig
const Version = "1.0.0"
// Version is the current version of smartconfig (set at build time with -ldflags)
var Version = "dev"
// GitCommit is the git commit hash (set at build time with -ldflags)
var GitCommit = "unknown"