From 50601762ea63865e1852fdf110a64b4e23b6dcdc Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 27 Oct 2025 16:07:57 +0000 Subject: [PATCH] Also skip workflow validation for `dynamic` workflows --- lib/init-action.js | 2 +- src/init.test.ts | 23 +++++++++++++++++++++++ src/init.ts | 14 +++++++++++--- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/init-action.js b/lib/init-action.js index 103f85087..415bbdd1c 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -91829,7 +91829,7 @@ async function getWorkflowAbsolutePath(logger) { // src/init.ts async function checkWorkflow(logger, codeql) { - if (process.env["CODEQL_ACTION_SKIP_WORKFLOW_VALIDATION" /* SKIP_WORKFLOW_VALIDATION */] !== "true") { + if (!isDynamicWorkflow() && process.env["CODEQL_ACTION_SKIP_WORKFLOW_VALIDATION" /* SKIP_WORKFLOW_VALIDATION */] !== "true") { core12.startGroup("Validating workflow"); const validateWorkflowResult = await validateWorkflow(codeql, logger); if (validateWorkflowResult === void 0) { diff --git a/src/init.test.ts b/src/init.test.ts index a4d5d48aa..bd267fb26 100644 --- a/src/init.test.ts +++ b/src/init.test.ts @@ -4,6 +4,7 @@ import path from "path"; import test, { ExecutionContext } from "ava"; import * as sinon from "sinon"; +import * as actionsUtil from "./actions-util"; import { createStubCodeQL } from "./codeql"; import { EnvVar } from "./environment"; import { @@ -28,6 +29,7 @@ test("checkWorkflow - validates workflow if `SKIP_WORKFLOW_VALIDATION` is not se const messages: LoggedMessage[] = []; const codeql = createStubCodeQL({}); + sinon.stub(actionsUtil, "isDynamicWorkflow").returns(false); const validateWorkflow = sinon.stub(workflow, "validateWorkflow"); validateWorkflow.resolves(undefined); @@ -46,6 +48,7 @@ test("checkWorkflow - logs problems with workflow validation", async (t) => { const messages: LoggedMessage[] = []; const codeql = createStubCodeQL({}); + sinon.stub(actionsUtil, "isDynamicWorkflow").returns(false); const validateWorkflow = sinon.stub(workflow, "validateWorkflow"); validateWorkflow.resolves("problem"); @@ -66,6 +69,7 @@ test("checkWorkflow - skips validation if `SKIP_WORKFLOW_VALIDATION` is `true`", const messages: LoggedMessage[] = []; const codeql = createStubCodeQL({}); + sinon.stub(actionsUtil, "isDynamicWorkflow").returns(false); const validateWorkflow = sinon.stub(workflow, "validateWorkflow"); await checkWorkflow(getRecordingLogger(messages), codeql); @@ -77,6 +81,25 @@ test("checkWorkflow - skips validation if `SKIP_WORKFLOW_VALIDATION` is `true`", t.is(messages.length, 0); }); +test("checkWorkflow - skips validation for `dynamic` workflows", async (t) => { + const messages: LoggedMessage[] = []; + const codeql = createStubCodeQL({}); + + const isDynamicWorkflow = sinon + .stub(actionsUtil, "isDynamicWorkflow") + .returns(true); + const validateWorkflow = sinon.stub(workflow, "validateWorkflow"); + + await checkWorkflow(getRecordingLogger(messages), codeql); + + t.assert(isDynamicWorkflow.calledOnce); + t.assert( + validateWorkflow.notCalled, + "`checkWorkflow` called `validateWorkflow` unexpectedly", + ); + t.is(messages.length, 0); +}); + test("cleanupDatabaseClusterDirectory cleans up where possible", async (t) => { await withTmpDir(async (tmpDir: string) => { const dbLocation = path.resolve(tmpDir, "dbs"); diff --git a/src/init.ts b/src/init.ts index f0a3b1dd5..7d8df61f6 100644 --- a/src/init.ts +++ b/src/init.ts @@ -6,7 +6,11 @@ import * as toolrunner from "@actions/exec/lib/toolrunner"; import * as io from "@actions/io"; import * as yaml from "js-yaml"; -import { getOptionalInput, isSelfHostedRunner } from "./actions-util"; +import { + getOptionalInput, + isDynamicWorkflow, + isSelfHostedRunner, +} from "./actions-util"; import { GitHubApiDetails } from "./api-client"; import { CodeQL, setupCodeQL } from "./codeql"; import * as configUtils from "./config-utils"; @@ -27,8 +31,12 @@ import { validateWorkflow } from "./workflow"; * @param codeql The CodeQL instance. */ export async function checkWorkflow(logger: Logger, codeql: CodeQL) { - // Check the workflow for problems, unless `SKIP_WORKFLOW_VALIDATION` is `true`. - if (process.env[EnvVar.SKIP_WORKFLOW_VALIDATION] !== "true") { + // Check the workflow for problems, unless `SKIP_WORKFLOW_VALIDATION` is `true` + // or the workflow trigger is `dynamic`. + if ( + !isDynamicWorkflow() && + process.env[EnvVar.SKIP_WORKFLOW_VALIDATION] !== "true" + ) { core.startGroup("Validating workflow"); const validateWorkflowResult = await validateWorkflow(codeql, logger); if (validateWorkflowResult === undefined) {