mirror of
https://github.com/ipxe/ipxe
synced 2026-01-24 13:13:42 +03:00
[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 <mcb30@ipxe.org>
This commit is contained in:
6
.github/workflows/build.yml
vendored
6
.github/workflows/build.yml
vendored
@@ -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
|
||||
|
||||
34
src/Makefile
34
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)
|
||||
|
||||
Reference in New Issue
Block a user