Skip to content

Commit c0d6650

Browse files
committed
Add script to automatically bump the version
Closes #44
1 parent 6c1e388 commit c0d6650

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
string: ${{ runner.os }}
5151

5252
- name: Compress artifacts
53-
uses: papeloto/action-zip@v1
53+
uses: vimtor/action-zip@v1
5454
with:
5555
files: install/bin/
5656
dest: ${{ github.event.repository.name }}-${{ steps.osname.outputs.lowercase }}.zip

cmake/bump_version.cmake

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
3+
if(NOT CMAKE_SCRIPT_MODE_FILE)
4+
message(FATAL_ERROR "Usage: cmake -P bump_version.cmake [1.2.3]")
5+
endif()
6+
7+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake.toml")
8+
message(FATAL_ERROR "Cannot find cmake.toml")
9+
endif()
10+
11+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake/cmkr.cmake")
12+
message(FATAL_ERROR "Cannot find cmkr.cmake")
13+
endif()
14+
15+
file(READ "${CMAKE_SOURCE_DIR}/cmake.toml" CMAKE_TOML)
16+
string(FIND "${CMAKE_TOML}" "[project]" PROJECT_INDEX)
17+
string(SUBSTRING "${CMAKE_TOML}" ${PROJECT_INDEX} -1 CMAKE_TOML_PROJECT)
18+
set(SEMVER_REGEX "([0-9]+)\\.([0-9]+)\\.([0-9]+)")
19+
set(VERSION_REGEX "version = \"${SEMVER_REGEX}\"")
20+
if(CMAKE_TOML_PROJECT MATCHES "${VERSION_REGEX}")
21+
set(MAJOR "${CMAKE_MATCH_1}")
22+
set(MINOR "${CMAKE_MATCH_2}")
23+
set(PATCH "${CMAKE_MATCH_3}")
24+
set(OLDVERSION "${MAJOR}.${MINOR}.${PATCH}")
25+
else()
26+
message(FATAL_ERROR "Failed to match semantic version in cmake.toml")
27+
endif()
28+
29+
if(CMAKE_ARGV3)
30+
if(NOT CMAKE_ARGV3 MATCHES "${SEMVER_REGEX}")
31+
message(FATAL_ERROR "Invalid semantic version number '${CMAKE_ARGV3}'")
32+
endif()
33+
set(NEWVERSION "${CMAKE_ARGV3}")
34+
else()
35+
math(EXPR NEWPATCH "${PATCH} + 1")
36+
set(NEWVERSION "${MAJOR}.${MINOR}.${NEWPATCH}")
37+
endif()
38+
39+
message(STATUS "Version ${OLDVERSION} -> ${NEWVERSION}")
40+
41+
find_program(CMKR_EXECUTABLE "cmkr" PATHS "${CMAKE_SOURCE_DIR}/build" NO_CACHE REQUIRED)
42+
message(STATUS "Found cmkr: ${CMKR_EXECUTABLE}")
43+
44+
# Replace version in cmake.toml
45+
string(REPLACE "version = \"${OLDVERSION}\"" "version = \"${NEWVERSION}\"" CMAKE_TOML "${CMAKE_TOML}")
46+
file(CONFIGURE
47+
OUTPUT "${CMAKE_SOURCE_DIR}/cmake.toml"
48+
CONTENT "${CMAKE_TOML}"
49+
@ONLY
50+
NEWLINE_STYLE LF
51+
)
52+
53+
# Run cmkr gen
54+
execute_process(COMMAND "${CMKR_EXECUTABLE}" gen RESULT_VARIABLE CMKR_EXEC_RESULT)
55+
if(NOT CMKR_EXEC_RESULT EQUAL 0)
56+
message(FATAL_ERROR "cmkr gen failed (exit code ${CMKR_EXEC_RESULT})")
57+
endif()
58+
59+
# Replace version in cmkr.cmake
60+
file(READ "${CMAKE_SOURCE_DIR}/cmake/cmkr.cmake" CMKR_CMAKE)
61+
string(REGEX REPLACE "CMKR_TAG \"[^\"]+\"" "CMKR_TAG \"v${NEWVERSION}\"" CMKR_CMAKE "${CMKR_CMAKE}")
62+
file(CONFIGURE
63+
OUTPUT "${CMAKE_SOURCE_DIR}/cmake/cmkr.cmake"
64+
CONTENT "${CMKR_CMAKE}"
65+
@ONLY
66+
NEWLINE_STYLE LF
67+
)
68+
69+
# Print git commands
70+
message(STATUS "Git commands to create new version:\ngit commit -a -m \"Bump to ${NEWVERSION}\"\ngit tag v${NEWVERSION}\ngit push origin main v${NEWVERSION}")

0 commit comments

Comments
 (0)