From c0e8887d5a9cec04772d252b454d925dbdc4184f Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Thu, 16 Oct 2025 20:03:26 +0100 Subject: [PATCH] Throw a `ConfigurationError` if `setup-codeql` has run before `init` --- lib/init-action.js | 5 +++++ lib/setup-codeql-action.js | 1 + src/environment.ts | 3 +++ src/init-action.ts | 9 +++++++++ src/setup-codeql-action.ts | 2 ++ 5 files changed, 20 insertions(+) diff --git a/lib/init-action.js b/lib/init-action.js index a113b2728..a07463f14 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -90784,6 +90784,11 @@ async function run() { if (statusReportBase !== void 0) { await sendStatusReport(statusReportBase); } + if (process.env["CODEQL_ACTION_SETUP_CODEQL_HAS_RUN" /* SETUP_CODEQL_ACTION_HAS_RUN */] === "true") { + throw new ConfigurationError( + `The 'init' action should not be run in the same workflow as 'setup-codeql'.` + ); + } const codeQLDefaultVersionInfo = await features.getDefaultCliVersion( gitHubVersion.type ); diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index a3e2b317b..a93c6f15a 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -87583,6 +87583,7 @@ async function run() { toolsSource = initCodeQLResult.toolsSource; core12.setOutput("codeql-path", codeql.getPath()); core12.setOutput("codeql-version", (await codeql.getVersion()).version); + core12.exportVariable("CODEQL_ACTION_SETUP_CODEQL_HAS_RUN" /* SETUP_CODEQL_ACTION_HAS_RUN */, "true"); } catch (unwrappedError) { const error2 = wrapError(unwrappedError); core12.setFailed(error2.message); diff --git a/src/environment.ts b/src/environment.ts index 7f554c762..698664122 100644 --- a/src/environment.ts +++ b/src/environment.ts @@ -47,6 +47,9 @@ export enum EnvVar { /** Whether the CodeQL Action has already warned the user about low disk space. */ HAS_WARNED_ABOUT_DISK_SPACE = "CODEQL_ACTION_HAS_WARNED_ABOUT_DISK_SPACE", + /** Whether the `setup-codeql` action has been run. */ + SETUP_CODEQL_ACTION_HAS_RUN = "CODEQL_ACTION_SETUP_CODEQL_HAS_RUN", + /** Whether the init action has been run. */ INIT_ACTION_HAS_RUN = "CODEQL_ACTION_INIT_HAS_RUN", diff --git a/src/init-action.ts b/src/init-action.ts index 13fa6c5b2..704985170 100644 --- a/src/init-action.ts +++ b/src/init-action.ts @@ -201,6 +201,7 @@ async function run() { ? await loadPropertiesFromApi(gitHubVersion, logger, repositoryNwo) : {}; + // Create a unique identifier for this run. const jobRunUuid = uuidV4(); logger.info(`Job run UUID is ${jobRunUuid}.`); core.exportVariable(EnvVar.JOB_RUN_UUID, jobRunUuid); @@ -229,6 +230,14 @@ async function run() { if (statusReportBase !== undefined) { await sendStatusReport(statusReportBase); } + + // Throw a `ConfigurationError` if the `setup-codeql` action has been run. + if (process.env[EnvVar.SETUP_CODEQL_ACTION_HAS_RUN] === "true") { + throw new ConfigurationError( + `The 'init' action should not be run in the same workflow as 'setup-codeql'.`, + ); + } + const codeQLDefaultVersionInfo = await features.getDefaultCliVersion( gitHubVersion.type, ); diff --git a/src/setup-codeql-action.ts b/src/setup-codeql-action.ts index 2ab5515f1..af817b76a 100644 --- a/src/setup-codeql-action.ts +++ b/src/setup-codeql-action.ts @@ -152,6 +152,8 @@ async function run(): Promise { core.setOutput("codeql-path", codeql.getPath()); core.setOutput("codeql-version", (await codeql.getVersion()).version); + + core.exportVariable(EnvVar.SETUP_CODEQL_ACTION_HAS_RUN, "true"); } catch (unwrappedError) { const error = wrapError(unwrappedError); core.setFailed(error.message);