From faa42c85032dd509a22db44b7e63296092e33d35 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 21 Jan 2026 22:23:49 +0000 Subject: [PATCH] [build] Do not use "git describe" to construct version number Using "git describe" to automatically construct the version number has caused more problems than it has solved. In particular, it causes errors when building from a shallow clone of the repository, which is a common scenario in modern automated build environments. Define the base version number (currently 1.21.1+) as a set of hardcoded constants within the Makefile, to be updated whenever a release is made. It is extremely useful to have the git commit ID present in the startup banner. End users tend to provide screenshots of failures, and having the commit ID printed at startup makes it trivial to identify which version of the code is in use. Identify the git version (if building from a git tree) by directly reading from .git/HEAD and associated files. This allows the git commit ID to potentially be included even if the build environment does not have the git tools installed. Use the default shallow clone in the GitHub Actions workflow, since we no longer require access to the full commit history. Signed-off-by: Michael Brown --- .github/workflows/build.yml | 6 ------ src/Makefile | 34 +++++++++++++++++++--------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8a8e3e81a..6f63efefb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,8 +33,6 @@ jobs: steps: - name: Check out code uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Cache permissions run: | sudo chown $(id -un) /var/cache/apt/archives @@ -69,8 +67,6 @@ jobs: steps: - name: Check out code uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Cache permissions run: | sudo chown $(id -un) /var/cache/apt/archives @@ -99,8 +95,6 @@ jobs: steps: - name: Check out code uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Cache permissions run: | sudo chown $(id -un) /var/cache/apt/archives diff --git a/src/Makefile b/src/Makefile index f9d782f97..b93c08f9d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -210,23 +210,27 @@ install : # # Version number calculations # -ifneq ($(wildcard ../.git),) -VERSIONS := $(shell git describe --tags --always --long --abbrev=1 --match "v*") -VERSION_TUPLE := $(subst ., ,$(subst -, ,$(patsubst v%,%,$(VERSIONS)))) -VERSION_MAJOR := $(word 1,$(VERSION_TUPLE)) -VERSION_MINOR := $(word 2,$(VERSION_TUPLE)) -VERSION_PATCH := $(word 3,$(VERSION_TUPLE)) -ifeq ($(word 4,$(VERSION_TUPLE)),0) -EXTRAVERSION := -else +VERSION_MAJOR := 1 +VERSION_MINOR := 21 +VERSION_PATCH := 1 EXTRAVERSION := + -endif -GITVERSION = $(word 5,$(VERSION_TUPLE)) +ifneq ($(wildcard ../.git/HEAD),) +GITHEAD := $(shell cat ../.git/HEAD) +ifneq ($(firstword $(GITHEAD)),ref:) +GITCOMMIT := $(GITHEAD) else -VERSION_MAJOR = 1 -VERSION_MINOR = 0 -VERSION_PATCH = 0 -EXTRAVERSION = + +GITREF := $(word 2,$(GITHEAD)) +ifneq ($(wildcard ../.git/$(GITREF)),) +GITCOMMIT := $(shell cat ../.git/$(GITREF)) +else +GITCOMMIT := $(shell awk -v ref="$(GITREF)" '$$2 == ref { print $1 }' \ + ../.git/packed-refs) +endif +endif +ifeq ($(GITCOMMIT),) +$(error Unable to determine git commit ID) +endif +GITVERSION := g$(shell echo "$(GITCOMMIT)" | cut -c1-5) endif MM_VERSION = $(VERSION_MAJOR).$(VERSION_MINOR) VERSION = $(MM_VERSION).$(VERSION_PATCH)$(EXTRAVERSION)