Skip to content

Commit 13eb163

Browse files
committed
fix: more robust version generation from tag
Signed-off-by: Tomas Jaros <tomas.jaros@nxp.com>
1 parent a8b6c16 commit 13eb163

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

.github/workflows/build_wrapper.yaml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,29 @@ jobs:
5656
uses: actions/setup-python@v4
5757
with:
5858
python-version: "3.11"
59+
60+
- name: Validate git versioning (Windows)
61+
if: runner.os == 'Windows'
62+
run: |
63+
$version = git describe --tags --long 2>$null
64+
if ($LASTEXITCODE -ne 0) {
65+
Write-Host "Error: No git tags found. Cannot determine version."
66+
Write-Host "Available tags:"
67+
git tag -l
68+
exit 1
69+
}
70+
Write-Host "Found version: $version"
71+
72+
- name: Validate git versioning (Unix)
73+
if: runner.os != 'Windows'
74+
run: |
75+
if ! version=$(git describe --tags --long 2>/dev/null); then
76+
echo "Error: No git tags found. Cannot determine version."
77+
echo "Available tags:"
78+
git tag -l
79+
exit 1
80+
fi
81+
echo "Found version: $version"
5982
6083
- name: Install build dependencies
6184
run: |
@@ -177,4 +200,4 @@ jobs:
177200
uses: pypa/gh-action-pypi-publish@release/v1
178201
with:
179202
packages-dir: dist
180-
skip-existing: true
203+
skip-existing: false

wrapper/CMakeLists.txt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,26 @@ include_directories(${generated_files_dir})
1818

1919
# Set the path for gitversion.h in the generated files directory
2020
set(gitversion_h "${generated_files_dir}/gitversion.h")
21+
# Run git describe without --always flag
22+
execute_process(
23+
COMMAND git describe --tags --long
24+
OUTPUT_VARIABLE version
25+
OUTPUT_STRIP_TRAILING_WHITESPACE
26+
RESULT_VARIABLE git_result
27+
ERROR_VARIABLE git_error
28+
)
2129

22-
# Run git describe
23-
execute_process(COMMAND git describe --long --always OUTPUT_VARIABLE version OUTPUT_STRIP_TRAILING_WHITESPACE)
24-
30+
# Check if git describe failed
31+
if(NOT git_result EQUAL 0)
32+
message(FATAL_ERROR "Failed to get version from git: ${git_error}\n"
33+
"Make sure you have tags in your repository.\n"
34+
"Create a tag with: git tag uuu_1.0.0")
35+
endif()
36+
37+
# Validate version format
38+
if(NOT version MATCHES "^uuu_[0-9]+\\.[0-9]+\\.[0-9]+(\\-[0-9]+\\-g[0-9a-f]+)?$")
39+
message(FATAL_ERROR "Git version '${version}' doesn't match expected format 'uuu_X.Y.Z' or 'uuu_X.Y.Z-N-gHASH'")
40+
endif()
2541
# Add a custom command to generate definitions.h
2642
if (WIN32)
2743
add_custom_command(

0 commit comments

Comments
 (0)