Skip to content

Commit e07e3ae

Browse files
committed
Refine DIST label extraction and VERSION handling in Makefile for improved metadata management
Signed-off-by: Yun Pan <dinoallo@netc.it>
1 parent 471de41 commit e07e3ae

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

Makefile

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

3232
# Used to populate variables in version package.
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)
33+
#
34+
# Derive a short `DIST` label from the current branch when appropriate and
35+
# insert it as semver build metadata (`+<dist>`) into `VERSION` only when
36+
# a label is present and `git describe` does not already include build metadata.
37+
# Behavior and examples:
38+
# - branch `release/1.7+labring` -> DIST=`labring` -> VERSION becomes `v1.7.27+labring-...`
39+
# - branch `release/v1.7-labring` -> DIST=`labring` -> (legacy `-` format supported)
40+
# - branch `v1.7+labring` -> DIST=`labring` -> VERSION becomes `v1.7.27+labring-...`
41+
# - branch `v1.7` or `release/v1.7` -> DIST empty -> VERSION unchanged (no `+` added)
42+
#
43+
# Notes:
44+
# - If `git describe` itself already contains a `+` (build metadata), no extra
45+
# `+DIST` will be inserted to avoid duplicate build metadata.
46+
# - The extraction prefers the `+` separator (new format) and falls back to
47+
# `-` for older branch names (for backward compatibility).
48+
# - In detached HEAD or CI checkouts where a branch name is not available,
49+
# `DIST` will be empty and no build metadata will be added.
50+
DIST := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null | awk '{b=$$0; if (b=="") {print ""; exit} if (index(b,"+")>0) { n=split(b,a,"+"); print a[n]; exit } if (substr(b,1,8)=="release/" && index(b,"-")>0) { n=split(b,a,"-"); print a[n]; exit } if (substr(b,1,1)=="v" && index(b,"-")>0) { n=split(b,a,"-"); print a[n]; exit } print "" }' || true)
51+
52+
VERSION ?= $(shell ver=$$(git describe --match 'v[0-9]*' --dirty='.m' --always 2>/dev/null || echo v0.0.0); if [ -n "$(DIST)" ]; then if echo "$$ver" | grep -q '+'; then echo "$$ver"; else echo "$$ver" | awk -v d="$(DIST)" '{sub(/^v[0-9]+(\.[0-9]+)*/, "&+"d); print}'; fi; else echo "$$ver"; fi)
4153
REVISION=$(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)
4254
PACKAGE=github.com/labring/containerd
4355
SHIM_CGO_ENABLED ?= 0

0 commit comments

Comments
 (0)