From 98201aaf005115cc41ac5152e7327b37814d6431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingemar=20=C3=85dahl?= Date: Thu, 18 Dec 2025 11:48:36 +0100 Subject: [PATCH] Allow any action to be referenced using commit hash Support for 'tolerating' commit hashes as refs without causing `githubWorkflowCheck` to fail was introduced in #207. However, this does not permit adding additional steps or jobs which uses actions not listed in `Action.all`, since they will not be taken into consideration when replacing refs in the comparison. This CL replaces the `Action.all` value to instead traverse the generated workflow structure to find all used actions. --- src/main/scala/sbtghactions/GenerativePlugin.scala | 14 +++++++++++++- src/main/scala/sbtghactions/WorkflowStep.scala | 2 -- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/scala/sbtghactions/GenerativePlugin.scala b/src/main/scala/sbtghactions/GenerativePlugin.scala index 6c9adb17..f701968b 100644 --- a/src/main/scala/sbtghactions/GenerativePlugin.scala +++ b/src/main/scala/sbtghactions/GenerativePlugin.scala @@ -911,6 +911,18 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)} val log = state.value.log + val usedActions = githubWorkflowGeneratedCI.value + .flatMap(_.steps) + .flatMap { + case use: WorkflowStep.Use => + use.ref match { + case action: UseRef.Public => Some(action) + case _ => None + } + case _ => + None + } + def reportMismatch(file: File, expected: String, actual: String): Unit = { log.error(s"Expected:\n$expected") log.error(s"Actual:\n${diff(expected, actual)}") @@ -926,7 +938,7 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)} // To achieve this, we replace any hash with the expected version: val cleanedActual = - Action.all.foldLeft(actual)((acc, action) => + usedActions.foldLeft(actual)((acc, action) => acc.replaceAll( s"uses: ${action.owner}/${action.repo}@[a-z0-9]{40}.*", s"uses: ${action.owner}/${action.repo}@${action.ref}" diff --git a/src/main/scala/sbtghactions/WorkflowStep.scala b/src/main/scala/sbtghactions/WorkflowStep.scala index efb23bfd..b2a93daa 100644 --- a/src/main/scala/sbtghactions/WorkflowStep.scala +++ b/src/main/scala/sbtghactions/WorkflowStep.scala @@ -37,8 +37,6 @@ object Action { val upload = UseRef.Public("actions", "upload-artifact", "v5") val download = UseRef.Public("actions", "download-artifact", "v6") val configurePagefile = UseRef.Public("al-cheb", "configure-pagefile-action", "v1.5") - - val all = Seq(checkout, setupGraalvm, setupJava, setupSbt, tmate, upload, download, configurePagefile) } object WorkflowStep {