Skip to content

Commit b86a7cd

Browse files
committed
Enhance VERSION handling in Makefile to include DIST label from branch name
Signed-off-by: Yun Pan <[email protected]>
1 parent bab8d51 commit b86a7cd

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ MANDIR ?= $(DATADIR)/man
3030
TEST_IMAGE_LIST ?=
3131

3232
# Used to populate variables in version package.
33-
VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
33+
# Derive a short `DIST` label from the branch when appropriate and
34+
# safely insert it as build metadata into `VERSION` when present.
35+
# - branch `release/v1.7-labring` -> DIST=labring
36+
# - branch `v1.7` or `release/v1.7` -> DIST empty
37+
# Use compact single-line shell expressions (awk) to avoid quoting issues.
38+
DIST := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null | awk -F- '/^release\//{print $$NF; next} /^v[0-9]/ && NF>1{print $$NF}' || true)
39+
40+
VERSION ?= $(shell ver=$$(git describe --match 'v[0-9]*' --dirty='.m' --always 2>/dev/null || echo v0.0.0); if [ -n "$(DIST)" ]; then echo "$$ver" | awk -v d="$(DIST)" '{sub(/^v[0-9]+(\.[0-9]+)*/, "&+"d); print}'; else echo "$$ver"; fi)
3441
REVISION=$(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)
3542
PACKAGE=github.com/labring/containerd
3643
SHIM_CGO_ENABLED ?= 0

0 commit comments

Comments
 (0)