# 2. Building from a source code archive not generated by "git archive" (i.e.,
# version_info has not been substituted). In this case we fail the
# configuration.
-# 3. Building from a Git repository. In this case the version will be a proper
+# 3. Building from a GitHub Actions job.
+# 4. Building from a Git repository. In this case the version will be a proper
# version if building a tagged commit, otherwise "branch.hash(+dirty)". In
# case Git is not available, the version will be "unknown".
-#
-# CCACHE_VERSION_ORIGIN is set to "archive" in scenario 1 and "git" in scenario
-# 3.
set(version_info "$Format:%H %D$")
set(CCACHE_VERSION "unknown")
# Untagged commit.
set(CCACHE_VERSION "${hash}")
endif()
-elseif(EXISTS "${CMAKE_SOURCE_DIR}/.git")
+elseif(DEFINED ENV{GITHUB_REF})
# Scenario 3.
+ set(CCACHE_VERSION_ORIGIN github)
+ if("$ENV{GITHUB_REF}" MATCHES "^refs/tags/v(.+)$")
+ set(CCACHE_VERSION "${CMAKE_MATCH_1}")
+ else()
+ string(SUBSTRING "$ENV{GITHUB_SHA}" 0 8 hash)
+ set(CCACHE_VERSION "$ENV{GITHUB_REF_NAME}.${hash}")
+ endif()
+elseif(EXISTS "${CMAKE_SOURCE_DIR}/.git")
+ # Scenario 4.
set(CCACHE_VERSION_ORIGIN git)
find_package(Git QUIET)