-
Notifications
You must be signed in to change notification settings - Fork 18
chore: wire CLI version via ldflags at build time #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The values for the For example, if you run |
||
|
|
||
| .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 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with the
Makefile, which uses the short commit hash (git rev-parse --short HEAD), it's better to use the short commit hash here as well. GoReleaser provides a{{ .ShortCommit }}template variable for this purpose.- -X main.commit={{ .ShortCommit }}