Skip to content

Commit ced6438

Browse files
committed
Only update version in git repo and when higher
1 parent e20139c commit ced6438

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

CMakeLists.txt

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,28 @@
33

44
cmake_minimum_required(VERSION 3.8.2)
55

6+
# Default to the last updated version from version.txt.
67
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" VERSION_FILE)
7-
8-
# Get the latest release tag from git if possible.
9-
execute_process(COMMAND git describe --tags --long
10-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
11-
OUTPUT_VARIABLE LATEST_VERSION_TAG
12-
ERROR_QUIET
13-
OUTPUT_STRIP_TRAILING_WHITESPACE)
14-
15-
if("${LATEST_VERSION_TAG}" MATCHES "^v([0-9]+\\.[0-9]+\\.[0-9]+)-[0-9]+-[0-9a-z]+$")
16-
# The latest tag matched the pattern we expected, extract the version number.
17-
set(LATEST_VERSION "${CMAKE_MATCH_1}")
18-
message(STATUS "Latest tagged release: v${LATEST_VERSION}")
19-
20-
# Update version.txt so source archives without the release tags can still get the same version.
21-
file(WRITE "${VERSION_FILE}" "${LATEST_VERSION}")
22-
else()
23-
# Just read the last updated version from version.txt.
24-
file(READ "${VERSION_FILE}" LATEST_VERSION)
8+
file(READ "${VERSION_FILE}" LATEST_VERSION)
9+
10+
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git")
11+
# Get the latest release tag from git if possible.
12+
execute_process(COMMAND git describe --tags --long
13+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
14+
OUTPUT_VARIABLE LATEST_VERSION_TAG
15+
ERROR_QUIET
16+
OUTPUT_STRIP_TRAILING_WHITESPACE)
17+
18+
if(LATEST_VERSION_TAG MATCHES "^v([0-9]+\\.[0-9]+\\.[0-9]+)-[0-9]+-[0-9a-z]+$"
19+
AND CMAKE_MATCH_1 VERSION_GREATER LATEST_VERSION)
20+
# The latest tag matched the pattern we expected and it's newer, so use that as the latest version.
21+
set(LATEST_VERSION "${CMAKE_MATCH_1}")
22+
23+
# Update version.txt so source archives without the release tags still get the same version.
24+
file(WRITE "${VERSION_FILE}" "${LATEST_VERSION}")
25+
endif()
2526
endif()
2627

27-
message(STATUS "Latest version: ${LATEST_VERSION}")
28-
2928
project(cppgraphqlgen VERSION ${LATEST_VERSION})
3029

3130
set(CMAKE_CXX_STANDARD 17)

0 commit comments

Comments
 (0)