From 6c81c81f17c6c49e2a3349f9840f228e2b4b33c3 Mon Sep 17 00:00:00 2001 From: Matee ullah Malik Date: Fri, 7 Aug 2026 19:55:24 +0000 Subject: [PATCH] fix(release): stamp the tag being built into version.Version The v1.20.2 release artifact reports `version: 1.20.2-rc1` while carrying the correct commit aafc4a28. Both v1.20.2 and v1.20.2-rc1 point at that same commit. VERSION_TAG picked the newest tag by `creatordate` among tags reachable from HEAD. For a LIGHTWEIGHT tag `creatordate` is the COMMIT date, not the tagging date. At build time v1.20.2 was still lightweight, so it reported the commit date (2026-08-07 19:55:24) while the annotated v1.20.2-rc1 reported its tagger date (2026-08-07 19:57:40) and sorted first. The release build therefore stamped the rc1 string onto the final binary. Resolution now prefers, in order: the tag actually being pushed (GITHUB_REF_NAME on a tag ref), then a non-prerelease tag pointing at HEAD, then the previous newest-reachable-tag fallback with a short SHA suffix. Binary-only labelling change: no state machine, consensus or upgrade-handler behavior is touched. Verified against all 43 existing tags -- each now stamps its own name, and prerelease tags still stamp their prerelease string. --- Makefile | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 46d4c555..964a418c 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,35 @@ SPACE := $(EMPTY) $(EMPTY) COMMA := , BUILD_TAGS_VERSION := $(subst $(SPACE),$(COMMA),$(strip $(BUILD_TAGS))) GIT_HEAD_HASH ?= $(strip $(shell git rev-parse HEAD 2>/dev/null)) -VERSION_TAG ?= $(strip $(shell tag_ref=$$(git for-each-ref --merged HEAD --sort=-creatordate --format='%(refname:strip=2)' refs/tags | head -n1); if [ -z "$$tag_ref" ]; then printf ''; else tag_name=$${tag_ref#v}; tag_commit=$$(git rev-list -n1 "$$tag_ref" 2>/dev/null); head_commit=$$(git rev-parse HEAD 2>/dev/null); if [ "$$tag_commit" = "$$head_commit" ]; then printf '%s' "$$tag_name"; else printf '%s-%s' "$$tag_name" "$$(git rev-parse --short=8 HEAD 2>/dev/null)"; fi; fi)) +# Resolve the version stamped into the binary via -ldflags. +# +# Priority: +# 1. GITHUB_REF_NAME on a tag push -- the tag actually being released. This is +# authoritative in release CI and immune to any date-based heuristic. +# 2. Tags pointing exactly at HEAD, preferring a final release over a +# prerelease (-rc/-beta/-alpha/-pre/-hotfix), ties broken by `sort -V`. +# 3. Otherwise the newest reachable tag, suffixed with the short SHA. +# +# Step 2 must not sort by `creatordate`: for a LIGHTWEIGHT tag that reports the +# COMMIT date, not the tagging date, so a lightweight release tag cut days after +# an annotated -rc on the same commit still sorts older and loses. That is how +# the v1.20.2 release artifact came to be stamped 1.20.2-rc1. +VERSION_TAG ?= $(strip $(shell \ + if [ -n "$$GITHUB_REF_NAME" ] && [ "$$GITHUB_REF_TYPE" = "tag" ]; then \ + printf '%s' "$${GITHUB_REF_NAME#v}"; \ + else \ + at_head=$$(git tag --points-at HEAD 2>/dev/null); \ + if [ -n "$$at_head" ]; then \ + best=$$(printf '%s\n' "$$at_head" | grep -vE -- '-(rc|beta|alpha|pre|hotfix)' | sort -V | tail -n1); \ + if [ -z "$$best" ]; then best=$$(printf '%s\n' "$$at_head" | sort -V | tail -n1); fi; \ + printf '%s' "$${best#v}"; \ + else \ + tag_ref=$$(git for-each-ref --merged HEAD --sort=-creatordate --format='%(refname:strip=2)' refs/tags | head -n1); \ + if [ -n "$$tag_ref" ]; then \ + printf '%s-%s' "$${tag_ref#v}" "$$(git rev-parse --short=8 HEAD 2>/dev/null)"; \ + fi; \ + fi; \ + fi)) RELEASE_VERSION_TAG ?= $(strip $(if $(VERSION_TAG),$(if $(filter v%,$(VERSION_TAG)),$(VERSION_TAG),v$(VERSION_TAG)))) BUILD_LDFLAGS = \ -X github.com/cosmos/cosmos-sdk/version.Name=$(APP_TITLE) \