Skip to content

Commit 805a22c

Browse files
committed
fix: correct version string for development builds
- Use git describe --exact-match to detect tagged commits - Check for dirty working tree with git status --porcelain - Use tag version ONLY if exact match AND clean working tree - Otherwise fallback to v0.0.0-dev+<commit-hash> format - Fixes issue where development builds showed old release tags This ensures that: 1. Tagged commits with clean tree show release version (e.g., v1.0.0-beta.62) 2. Development builds show v0.0.0-dev+<commit-hash> format 3. Dirty working tree always shows dev version Signed-off-by: NETIZEN-11 <niteshkumar121411@gmail.com>
1 parent 2cd4e75 commit 805a22c

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,23 @@ YEAR_GEN := $(shell date '+%Y')
2121

2222
GOBIN := $(shell go env GOPATH)/bin
2323
GIT_COMMIT := $(shell git rev-parse --short HEAD)
24+
GIT_TAG := $(shell git describe --tags --exact-match 2>/dev/null)
25+
DIRTY := $(shell git status --porcelain)
26+
27+
# Version logic:
28+
# - Use tag ONLY if exact match AND clean working tree
29+
# - Otherwise fallback to dev version
30+
ifeq ($(GIT_TAG),)
31+
VERSION := v0.0.0-dev+$(GIT_COMMIT)
32+
else ifneq ($(DIRTY),)
33+
VERSION := v0.0.0-dev+$(GIT_COMMIT)
34+
else
35+
VERSION := $(GIT_TAG)
36+
endif
2437

2538
export KPT_FN_WASM_RUNTIME ?= nodejs
2639

27-
LDFLAGS := -ldflags "-X github.com/kptdev/kpt/run.version=${GIT_COMMIT}
40+
LDFLAGS := -ldflags "-X github.com/kptdev/kpt/run.version=${VERSION}
2841
ifeq ($(OS),Windows_NT)
2942
# Do nothing
3043
else

0 commit comments

Comments
 (0)