Skip to content

Commit b9c94bb

Browse files
Add support for versioning in git archives
While releasing UMF we should update VERSION file with the current version. It will be used only if git is not available or tags were not fetched. To underline it is not a "detailed version" we will add "-dev" in CMake version parsing, so it will stand out (comparing to e.g. versions like "1.0.3-dev1-...").
1 parent 7bce62d commit b9c94bb

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

.github/copilot-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ cmake -B build -DCMAKE_BUILD_TYPE=Debug \
3535
2. `VERSION` file fallback
3636
3. "0.0.0" default
3737
- `set_version_variables()` in `cmake/helpers.cmake` handles version detection
38-
- For releases: create `VERSION` file with semver format (e.g., "1.0.3-dev")
38+
- For releases: create `VERSION` file with semver format (e.g., "1.0.3")
3939

4040
### Code Formatting
4141
- **Always format code before committing**: `make format-apply`

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ if(UMF_CMAKE_VERSION VERSION_EQUAL "0.0.0")
3232
message(
3333
WARNING
3434
"UMF version is set to 0.0.0, which most likely is not expected! "
35-
"Please checkout the git tags to get a proper version.")
35+
"Please install git and checkout the git tags to get a proper version."
36+
)
3637
endif()
3738

3839
if(PROJECT_VERSION_PATCH GREATER 0)

RELEASE_STEPS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ Prepare changes for the release:
5050
- Once all changes are done, build locally (and/or verify changes on CI), including:
5151
- Verify if scanners/linters/checkers passed
5252
- Verify if version is set properly, especially in `.dll` and `.so` files
53+
- Create/update a VERSION file for GitHub ZIP downloads (users without git):
54+
- `echo "$VERSION" > VERSION`
55+
- It will always contain "the last released version". In logs/CMake build it will introduce itself as `$VERSION-dev`, only if git is not available
5356
- Commit these changes and tag the release:
57+
- `git add VERSION`
5458
- `git commit -a -S -m "$VERSION release"`
5559
- `git tag -a -s -m "Version $VERSION" v$VERSION`
5660
- Verify if commit and tag are properly signed:

cmake/helpers.cmake

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ include(CheckCCompilerFlag)
1111
include(CheckCXXCompilerFlag)
1212

1313
# This function establishes version variables based on the git describe output.
14-
# If there's no git available in the system, the version will be set to "0.0.0".
15-
# If git reports only a hash, the version will be set to "0.0.0.git.<hash>".
16-
# Otherwise we'll use 3-component version: major.minor.patch, just for CMake's
17-
# sake. A few extra variables will be set for Win dll metadata.
14+
# If there's no git available in the system, it falls back to reading a VERSION
15+
# file from the project root. If neither git nor VERSION file is available, the
16+
# version will be set to "0.0.0". If git reports only a hash, the version will
17+
# be set to "0.0.0.git.<hash>". Otherwise we'll use 3-component version:
18+
# major.minor.patch, just for CMake's sake. A few extra variables will be set
19+
# for Win dll metadata.
1820
#
1921
# Important note: CMake does not support rc or git information. According to
2022
# semver rules, 1.5.1-rc1 should be less than 1.5.1, but it seems hard to
@@ -78,8 +80,24 @@ function(set_version_variables)
7880
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
7981

8082
if(NOT GIT_VERSION)
81-
# no git or it reported no version. Use default ver: "0.0.0"
82-
return()
83+
# no git or it reported no version. Try fallback to VERSION file
84+
if(EXISTS "${UMF_CMAKE_SOURCE_DIR}/VERSION")
85+
file(READ "${UMF_CMAKE_SOURCE_DIR}/VERSION" FILE_VERSION)
86+
string(STRIP ${FILE_VERSION} FILE_VERSION)
87+
if(FILE_VERSION)
88+
set(GIT_VERSION "v${FILE_VERSION}-dev")
89+
message(
90+
STATUS
91+
"Using version from VERSION file: ${FILE_VERSION}. To get detailed version, use git and fetch tags."
92+
)
93+
else()
94+
# VERSION file exists but is empty, use default ver: "0.0.0"
95+
return()
96+
endif()
97+
else()
98+
# no git and no VERSION file. Use default ver: "0.0.0"
99+
return()
100+
endif()
83101
endif()
84102

85103
# v1.5.0 - we're exactly on a tag -> UMF ver: "1.5.0"

0 commit comments

Comments
 (0)