From 207c99a47508e90b6736992b28daa6319c63c14f Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 25 Jan 2026 09:30:34 +0000 Subject: [PATCH] [build] Allow GITVERSION to be specified as an environment variable When using GitHub Actions with a job container that does not have the git tools installed, the actions/checkout step will download a snapshot instead of performing a git clone, and will therefore not create a .git directory. Allow the GITVERSION variable to be specified externally, so that the test suite logs can still display the commit of the build being tested. Signed-off-by: Michael Brown --- src/Makefile | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Makefile b/src/Makefile index b93c08f9d..6d7df0e2c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -215,27 +215,24 @@ VERSION_MINOR := 21 VERSION_PATCH := 1 EXTRAVERSION := + ifneq ($(wildcard ../.git/HEAD),) -GITHEAD := $(shell cat ../.git/HEAD) -ifneq ($(firstword $(GITHEAD)),ref:) -GITCOMMIT := $(GITHEAD) -else -GITREF := $(word 2,$(GITHEAD)) +GITVERSION := $(shell cat ../.git/HEAD) +ifeq ($(firstword $(GITVERSION)),ref:) +GITREF := $(word 2,$(GITVERSION)) ifneq ($(wildcard ../.git/$(GITREF)),) -GITCOMMIT := $(shell cat ../.git/$(GITREF)) +GITVERSION := $(shell cat ../.git/$(GITREF)) else -GITCOMMIT := $(shell awk -v ref="$(GITREF)" '$$2 == ref { print $1 }' \ +GITVERSION := $(shell awk -v ref="$(GITREF)" '$$2 == ref { print $1 }' \ ../.git/packed-refs) endif endif -ifeq ($(GITCOMMIT),) +ifeq ($(GITVERSION),) $(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) ifneq ($(GITVERSION),) -VERSION += ($(GITVERSION)) +VERSION += (g$(shell echo "$(GITVERSION)" | cut -c1-5)) endif version : @$(ECHO) "$(VERSION)"