]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
build: Detect ccache version from GitHub Actions environment
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 8 Aug 2025 18:33:41 +0000 (20:33 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 21 Aug 2025 19:26:29 +0000 (21:26 +0200)
cmake/CcacheVersion.cmake

index 34e7c965636a083450c46a6974ced90fe2d89a4e..f9541e426e361ef459ab7e4d9ae02e91a38a93a0 100644 (file)
 # 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")
@@ -38,8 +36,17 @@ if(version_info MATCHES "^([0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a
     # 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)