From c940782926b45a52a914843c90b72fb1494d5090 Mon Sep 17 00:00:00 2001 From: Kris Coleman Date: Wed, 21 Jan 2026 14:21:13 -0500 Subject: [PATCH 1/2] 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 0593816..00aec33 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 From f85b081aac54b318e31f9a716c17a0d62a24bd2a Mon Sep 17 00:00:00 2001 From: Kris Coleman Date: Tue, 3 Feb 2026 13:39:10 -0500 Subject: [PATCH 2/2] chore: ensures proper string quoting in LDFLAGS Properly quotes the arguments passed to the `-X` ldflag to ensure correct interpretation of version information during the build process. The embedded version information was not being interpreted correctly due to missing quotes. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 00aec33..b889d85 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ help: 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) +LDFLAGS := -s -w -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)' .PHONY: build build: