diff --git a/.github/workflows/build_all.yml b/.github/workflows/build_all.yml index ea72150189..db95d67040 100644 --- a/.github/workflows/build_all.yml +++ b/.github/workflows/build_all.yml @@ -97,12 +97,15 @@ jobs: ver_pure=$(grep 'set(SoftFever_VERSION' version.inc | cut -d '"' -f2) if [[ "${{ github.event_name }}" == "pull_request" ]]; then ver="PR-${{ github.event.number }}" + git_commit_hash="${{ github.event.pull_request.head.sha }}" else ver=V$ver_pure + git_commit_hash="" fi echo "ver=$ver" >> $GITHUB_ENV echo "ver_pure=$ver_pure" >> $GITHUB_ENV echo "date=$(date +'%Y%m%d')" >> $GITHUB_ENV + echo "git_commit_hash=$git_commit_hash" >> $GITHUB_ENV shell: bash - uses: flathub-infra/flatpak-github-actions/flatpak-builder@master with: diff --git a/.github/workflows/build_orca.yml b/.github/workflows/build_orca.yml index bebcaba1b2..29984fab2e 100644 --- a/.github/workflows/build_orca.yml +++ b/.github/workflows/build_orca.yml @@ -47,12 +47,15 @@ jobs: ver_pure=$(grep 'set(SoftFever_VERSION' version.inc | cut -d '"' -f2) if [[ "${{ github.event_name }}" == "pull_request" ]]; then ver="PR-${{ github.event.number }}" + git_commit_hash="${{ github.event.pull_request.head.sha }}" else ver=V$ver_pure + git_commit_hash="" fi echo "ver=$ver" >> $GITHUB_ENV echo "ver_pure=$ver_pure" >> $GITHUB_ENV echo "date=$(date +'%Y%m%d')" >> $GITHUB_ENV + echo "git_commit_hash=$git_commit_hash" >> $GITHUB_ENV shell: bash - name: Get the version and date on Windows @@ -65,16 +68,19 @@ jobs: if ($eventName -eq 'pull_request') { $ver = "PR" + $prNumber + $git_commit_hash = "${{ github.event.pull_request.head.sha }}" } else { $versionContent = Get-Content version.inc -Raw if ($versionContent -match 'set\(SoftFever_VERSION "(.*?)"\)') { $ver = $matches[1] } $ver = "V$ver" + $git_commit_hash = "" } echo "ver=$ver" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 echo "date=$date" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + echo "git_commit_hash=$git_commit_hash" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 echo "date: ${{ env.date }} version: ${{ env.ver }}" shell: pwsh diff --git a/CMakeLists.txt b/CMakeLists.txt index f58a5876ed..6bd575188d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,14 +69,27 @@ endif() find_package(Git) if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git") - # Check current Git commit hash - execute_process( - COMMAND ${GIT_EXECUTABLE} log -1 --format=%h - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_COMMIT_HASH - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - add_definitions("-DGIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"") + if(DEFINED ENV{git_commit_hash} AND NOT "$ENV{git_commit_hash}" STREQUAL "") + message(STATUS "Specified git commit hash: $ENV{git_commit_hash}") + + # Convert the given hash to short hash + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --short "$ENV{git_commit_hash}" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + add_definitions("-DGIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"") + else() + # Check current Git commit hash + execute_process( + COMMAND ${GIT_EXECUTABLE} log -1 --format=%h + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + add_definitions("-DGIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"") + endif() endif() if(DEFINED ENV{SLIC3R_STATIC})