Skip to content

Commit ea7d5b6

Browse files
committed
chore: Fix commit SHA for GitHub PRs
1 parent 79c08fc commit ea7d5b6

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

.github/actions/cmake/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ runs:
5757
STATIC: "${{ inputs.static == 'true' && 'ON' || 'OFF' }}"
5858
TIME_TRACE: "${{ inputs.time_trace == 'true' && 'ON' || 'OFF' }}"
5959
PACKAGE: "${{ inputs.package == 'true' && 'ON' || 'OFF' }}"
60+
# GitHub creates merge commits for pull requests, so we need to use `github.event.pull_request.head.sha`
61+
# to get the actual commit SHA of the PR branch.
62+
GITHUB_HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
6063
run: |
6164
cmake \
6265
-B "${BUILD_DIR}" \

cmake/ClioVersion.cmake

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@ else ()
3030
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY
3131
)
3232

33-
set(GIT_COMMAND rev-parse --short HEAD)
34-
execute_process(
35-
COMMAND ${GIT_EXECUTABLE} ${GIT_COMMAND} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE REV
36-
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY
37-
)
33+
if (DEFINED ENV{GITHUB_HEAD_SHA})
34+
# GitHub creates merge commits for pull requests, so we need to use `github.event.pull_request.head.sha` to get the
35+
# actual commit SHA of the PR branch. We set $GITHUB_HEAD_SHA in the cmake action
36+
set(REV $ENV{GITHUB_HEAD_SHA})
37+
else ()
38+
set(GIT_COMMAND rev-parse --short HEAD)
39+
execute_process(
40+
COMMAND ${GIT_EXECUTABLE} ${GIT_COMMAND} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE REV
41+
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY
42+
)
43+
endif ()
3844

3945
set(CLIO_VERSION "${DATE}-${BRANCH}-${REV}")
4046
set(DOC_CLIO_VERSION "develop")

0 commit comments

Comments
 (0)