Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ builds:
main: ./cmd/openfeature/
env:
- CGO_ENABLED=0
ldflags:
- -s -w
- -X main.version={{ .Version }}
- -X main.commit={{ .FullCommit }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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 }}

- -X main.date={{ .Date }}
goos:
- linux
- windows
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The values for the -X flags are not quoted. If any of the variables (VERSION, COMMIT, DATE) are overridden with a value containing spaces, the build command will fail. To make the build more robust, you should quote the values being injected.

For example, if you run make build VERSION="my version", the current LDFLAGS would be -s -w -X main.version=my version ..., which would be parsed incorrectly by the linker. Quoting the values prevents this.

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
Expand Down
Loading