From 758b62a2dc5f40ff3cbb6b03f72b68710aa5dfaf Mon Sep 17 00:00:00 2001 From: Kris Coleman Date: Wed, 21 Jan 2026 14:21:13 -0500 Subject: [PATCH] chore: wire CLI version via ldflags at build time Added ldflags configuration to GoReleaser and Makefile to inject the actual CLI version, commit hash, and build date at compile time. This ensures: - GoReleaser builds embed the release version from git tags - Local builds via `make build` use git describe for versioning - The version command displays accurate version info instead of "dev" Closes #192 Signed-off-by: Kris Coleman --- .goreleaser.yaml | 5 +++++ Makefile | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 4a927e1..8191462 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -19,6 +19,11 @@ builds: main: ./cmd/openfeature/ env: - CGO_ENABLED=0 + ldflags: + - -s -w + - -X main.version={{ .Version }} + - -X main.commit={{ .FullCommit }} + - -X main.date={{ .Date }} goos: - linux - windows diff --git a/Makefile b/Makefile index d455418..62d70c8 100644 --- a/Makefile +++ b/Makefile @@ -19,12 +19,18 @@ help: @echo " fmt - Format Go code" @echo " ci - Run all CI checks locally (fmt, lint, test, verify-generate)" +# Build variables +VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") +COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown") +DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") +LDFLAGS := -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE) + .PHONY: build build: @echo "Building CLI binary..." @mkdir -p bin - @go build -o bin/openfeature ./cmd/openfeature - @echo "CLI binary built successfully at bin/openfeature" + @go build -ldflags "$(LDFLAGS)" -o bin/openfeature ./cmd/openfeature + @echo "CLI binary built successfully at bin/openfeature (version: $(VERSION))" .PHONY: install install: build