From 8b734d3bc2f0f9afb51c200eb4a311cc6ea5782e Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 16 Feb 2026 08:54:19 +0000 Subject: [PATCH] Improve variable names and comments Also set default `GITHUB_EVENT_NAME` in `setupActionsVars` --- lib/analyze-action.js | 6 ++++-- lib/init-action-post.js | 6 ++++-- lib/init-action.js | 6 ++++-- lib/setup-codeql-action.js | 6 ++++-- lib/upload-lib.js | 6 ++++-- lib/upload-sarif-action.js | 6 ++++-- src/setup-codeql.test.ts | 17 +++++++++-------- src/setup-codeql.ts | 20 +++++++++++--------- src/testing-utils.ts | 1 + 9 files changed, 45 insertions(+), 29 deletions(-) diff --git a/lib/analyze-action.js b/lib/analyze-action.js index ff5731b50..98b0a926a 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -108980,9 +108980,11 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian let cliVersion2; let tagName; let url2; + const canForceNightlyWithFF = isDynamicWorkflow() || isInTestMode(); const forceNightlyValueFF = await features.getValue("force_nightly" /* ForceNightly */); - const forceNightly = forceNightlyValueFF && (isDynamicWorkflow() || isInTestMode()); - if (forceNightly || toolsInput !== void 0 && CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput)) { + const forceNightly = forceNightlyValueFF && canForceNightlyWithFF; + const nightlyRequestedByToolsInput = toolsInput !== void 0 && CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput); + if (forceNightly || nightlyRequestedByToolsInput) { if (forceNightly) { logger.info( `Using the latest CodeQL CLI nightly, as forced by the ${"force_nightly" /* ForceNightly */} feature flag.` diff --git a/lib/init-action-post.js b/lib/init-action-post.js index e943a4f54..9459efd2f 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -166042,9 +166042,11 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian let cliVersion2; let tagName; let url2; + const canForceNightlyWithFF = isDynamicWorkflow() || isInTestMode(); const forceNightlyValueFF = await features.getValue("force_nightly" /* ForceNightly */); - const forceNightly = forceNightlyValueFF && (isDynamicWorkflow() || isInTestMode()); - if (forceNightly || toolsInput !== void 0 && CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput)) { + const forceNightly = forceNightlyValueFF && canForceNightlyWithFF; + const nightlyRequestedByToolsInput = toolsInput !== void 0 && CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput); + if (forceNightly || nightlyRequestedByToolsInput) { if (forceNightly) { logger.info( `Using the latest CodeQL CLI nightly, as forced by the ${"force_nightly" /* ForceNightly */} feature flag.` diff --git a/lib/init-action.js b/lib/init-action.js index 5712761bc..59e73dc0c 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -107383,9 +107383,11 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian let cliVersion2; let tagName; let url; + const canForceNightlyWithFF = isDynamicWorkflow() || isInTestMode(); const forceNightlyValueFF = await features.getValue("force_nightly" /* ForceNightly */); - const forceNightly = forceNightlyValueFF && (isDynamicWorkflow() || isInTestMode()); - if (forceNightly || toolsInput !== void 0 && CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput)) { + const forceNightly = forceNightlyValueFF && canForceNightlyWithFF; + const nightlyRequestedByToolsInput = toolsInput !== void 0 && CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput); + if (forceNightly || nightlyRequestedByToolsInput) { if (forceNightly) { logger.info( `Using the latest CodeQL CLI nightly, as forced by the ${"force_nightly" /* ForceNightly */} feature flag.` diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index c2b1a5119..cc4537622 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -105125,9 +105125,11 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian let cliVersion2; let tagName; let url; + const canForceNightlyWithFF = isDynamicWorkflow() || isInTestMode(); const forceNightlyValueFF = await features.getValue("force_nightly" /* ForceNightly */); - const forceNightly = forceNightlyValueFF && (isDynamicWorkflow() || isInTestMode()); - if (forceNightly || toolsInput !== void 0 && CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput)) { + const forceNightly = forceNightlyValueFF && canForceNightlyWithFF; + const nightlyRequestedByToolsInput = toolsInput !== void 0 && CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput); + if (forceNightly || nightlyRequestedByToolsInput) { if (forceNightly) { logger.info( `Using the latest CodeQL CLI nightly, as forced by the ${"force_nightly" /* ForceNightly */} feature flag.` diff --git a/lib/upload-lib.js b/lib/upload-lib.js index 5562a4e0c..f8e896652 100644 --- a/lib/upload-lib.js +++ b/lib/upload-lib.js @@ -107823,9 +107823,11 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian let cliVersion2; let tagName; let url2; + const canForceNightlyWithFF = isDynamicWorkflow() || isInTestMode(); const forceNightlyValueFF = await features.getValue("force_nightly" /* ForceNightly */); - const forceNightly = forceNightlyValueFF && (isDynamicWorkflow() || isInTestMode()); - if (forceNightly || toolsInput !== void 0 && CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput)) { + const forceNightly = forceNightlyValueFF && canForceNightlyWithFF; + const nightlyRequestedByToolsInput = toolsInput !== void 0 && CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput); + if (forceNightly || nightlyRequestedByToolsInput) { if (forceNightly) { logger.info( `Using the latest CodeQL CLI nightly, as forced by the ${"force_nightly" /* ForceNightly */} feature flag.` diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index e154e97e7..72b1c63d8 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -108385,9 +108385,11 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian let cliVersion2; let tagName; let url2; + const canForceNightlyWithFF = isDynamicWorkflow() || isInTestMode(); const forceNightlyValueFF = await features.getValue("force_nightly" /* ForceNightly */); - const forceNightly = forceNightlyValueFF && (isDynamicWorkflow() || isInTestMode()); - if (forceNightly || toolsInput !== void 0 && CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput)) { + const forceNightly = forceNightlyValueFF && canForceNightlyWithFF; + const nightlyRequestedByToolsInput = toolsInput !== void 0 && CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput); + if (forceNightly || nightlyRequestedByToolsInput) { if (forceNightly) { logger.info( `Using the latest CodeQL CLI nightly, as forced by the ${"force_nightly" /* ForceNightly */} feature flag.` diff --git a/src/setup-codeql.test.ts b/src/setup-codeql.test.ts index c93271975..5b1587ab0 100644 --- a/src/setup-codeql.test.ts +++ b/src/setup-codeql.test.ts @@ -334,8 +334,6 @@ test("getCodeQLSource correctly returns nightly CLI version when forced by FF", const logger = getRecordingLogger(loggedMessages); const features = createFeatures([Feature.ForceNightly]); - process.env["GITHUB_EVENT_NAME"] = "dynamic"; - const expectedDate = "30260213"; const expectedTag = `codeql-bundle-${expectedDate}`; @@ -356,6 +354,8 @@ test("getCodeQLSource correctly returns nightly CLI version when forced by FF", await withTmpDir(async (tmpDir) => { setupActionsVars(tmpDir, tmpDir); + process.env["GITHUB_EVENT_NAME"] = "dynamic"; + const source = await setupCodeql.getCodeQLSource( undefined, SAMPLE_DEFAULT_CLI_VERSION, @@ -393,8 +393,6 @@ test("getCodeQLSource correctly returns latest version from toolcache when tools const logger = getRecordingLogger(loggedMessages); const features = createFeatures([Feature.AllowToolcacheInput]); - process.env["GITHUB_EVENT_NAME"] = "dynamic"; - const latestToolcacheVersion = "3.2.1"; const latestVersionPath = "/path/to/latest"; const testVersions = ["2.3.1", latestToolcacheVersion, "1.2.3"]; @@ -408,6 +406,8 @@ test("getCodeQLSource correctly returns latest version from toolcache when tools await withTmpDir(async (tmpDir) => { setupActionsVars(tmpDir, tmpDir); + process.env["GITHUB_EVENT_NAME"] = "dynamic"; + const source = await setupCodeql.getCodeQLSource( "toolcache", SAMPLE_DEFAULT_CLI_VERSION, @@ -463,16 +463,17 @@ const toolcacheInputFallbackMacro = test.macro({ const logger = getRecordingLogger(loggedMessages); const features = createFeatures(featureList); - for (const [k, v] of Object.entries(environment)) { - process.env[k] = v; - } - const findAllVersionsStub = sinon .stub(toolcache, "findAllVersions") .returns(testVersions); await withTmpDir(async (tmpDir) => { setupActionsVars(tmpDir, tmpDir); + + for (const [k, v] of Object.entries(environment)) { + process.env[k] = v; + } + const source = await setupCodeql.getCodeQLSource( "toolcache", SAMPLE_DEFAULT_CLI_VERSION, diff --git a/src/setup-codeql.ts b/src/setup-codeql.ts index e907da456..37358fb81 100644 --- a/src/setup-codeql.ts +++ b/src/setup-codeql.ts @@ -321,17 +321,19 @@ export async function getCodeQLSource( */ let url: string | undefined; - // We only allow forcing the nightly CLI via the FF for `dynamic` events (or in test mode). - // For advanced workflows, a value from `CODEQL_NIGHTLY_TOOLS_INPUTS` can be specified. + // We allow forcing the nightly CLI via the FF for `dynamic` events (or in test mode) where the + // `tools` input cannot be adjusted to explicitly request it. + const canForceNightlyWithFF = isDynamicWorkflow() || util.isInTestMode(); const forceNightlyValueFF = await features.getValue(Feature.ForceNightly); - const forceNightly = - forceNightlyValueFF && (isDynamicWorkflow() || util.isInTestMode()); + const forceNightly = forceNightlyValueFF && canForceNightlyWithFF; - if ( - forceNightly || - (toolsInput !== undefined && - CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput)) - ) { + // For advanced workflows, a value from `CODEQL_NIGHTLY_TOOLS_INPUTS` can be specified explicitly + // for the `tools` input in the workflow file. + const nightlyRequestedByToolsInput = + toolsInput !== undefined && + CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput); + + if (forceNightly || nightlyRequestedByToolsInput) { if (forceNightly) { logger.info( `Using the latest CodeQL CLI nightly, as forced by the ${Feature.ForceNightly} feature flag.`, diff --git a/src/testing-utils.ts b/src/testing-utils.ts index aff778043..d69c266a2 100644 --- a/src/testing-utils.ts +++ b/src/testing-utils.ts @@ -145,6 +145,7 @@ export function setupActionsVars(tempDir: string, toolsDir: string) { process.env["RUNNER_TEMP"] = tempDir; process.env["RUNNER_TOOL_CACHE"] = toolsDir; process.env["GITHUB_WORKSPACE"] = tempDir; + process.env["GITHUB_EVENT_NAME"] = "push"; } export interface LoggedMessage {