Skip to content

Commit da433f7

Browse files
committed
Only get tag version when branch name matches release branch
1 parent cebf7c6 commit da433f7

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

cmake/version.cmake

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,42 @@ set(tmp_version "HEAD")
44
set(TAG_VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+(\\.(a|b|rc)\\.[0-9]+)?")
55
set(COMMIT_VERSION_REGEX "[0-9a-f]+[0-9a-f]+[0-9a-f]+[0-9a-f]+[0-9a-f]+")
66
while ("${PADDLE_VERSION}" STREQUAL "")
7+
# Check current branch name
78
execute_process(
8-
COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 --always ${tmp_version}
9+
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref ${tmp_version}
910
WORKING_DIRECTORY ${PADDLE_SOURCE_DIR}
10-
OUTPUT_VARIABLE GIT_TAG_NAME
11-
RESULT_VARIABLE GIT_RESULT
11+
OUTPUT_VARIABLE GIT_BRANCH_NAME
12+
RESULT_VARIABLE GIT_BRANCH_RESULT
1213
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
13-
if (NOT ${GIT_RESULT})
14-
# Check the tag is a correct version
15-
if (${GIT_TAG_NAME} MATCHES "${COMMIT_VERSION_REGEX}")
16-
# if no tag was found, set PADDLE_VERSION to latest
17-
set(PADDLE_VERSION "latest")
18-
elseif (${GIT_TAG_NAME} MATCHES "v${TAG_VERSION_REGEX}")
19-
string(REPLACE "v" "" PADDLE_VERSION ${GIT_TAG_NAME})
20-
else() # otherwise, get the previous git tag name.
21-
set(tmp_version "${GIT_TAG_NAME}~1")
14+
if (NOT ${GIT_BRANCH_RESULT})
15+
execute_process(
16+
COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 --always ${tmp_version}
17+
WORKING_DIRECTORY ${PADDLE_SOURCE_DIR}
18+
OUTPUT_VARIABLE GIT_TAG_NAME
19+
RESULT_VARIABLE GIT_RESULT
20+
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
21+
if (NOT ${GIT_RESULT})
22+
# Check if current branch is release branch
23+
if (${GIT_BRANCH_NAME} MATCHES "release/${TAG_VERSION_REGEX}")
24+
# Check the tag is a correct version
25+
if (${GIT_TAG_NAME} MATCHES "${COMMIT_VERSION_REGEX}")
26+
# if no tag was found, set PADDLE_VERSION to latest
27+
set(PADDLE_VERSION "latest")
28+
elseif (${GIT_TAG_NAME} MATCHES "v${TAG_VERSION_REGEX}")
29+
string(REPLACE "v" "" PADDLE_VERSION ${GIT_TAG_NAME})
30+
else() # otherwise, get the previous git tag name.
31+
set(tmp_version "${GIT_TAG_NAME}~1")
32+
endif()
33+
else() # otherwise, we always set PADDLE_VERSION to latest
34+
set(PADDLE_VERSION "latest")
35+
endif()
36+
else()
37+
set(PADDLE_VERSION "0.0.0")
38+
message(WARNING "Cannot add paddle version from git tag")
2239
endif()
2340
else()
2441
set(PADDLE_VERSION "0.0.0")
25-
message(WARNING "Cannot add paddle version from git tag")
42+
message(WARNING "Cannot add paddle version for wrong git branch result")
2643
endif()
2744
endwhile()
2845

0 commit comments

Comments
 (0)