From 99fe83948eb780db2b4bd9b5f63c498673f3b857 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 16 Sep 2026 12:44:04 +0100 Subject: [PATCH] Refactor: Add `determineCheckoutPath` function for `analyze` action --- lib/entry-points.js | 13 +++++++------ src/analyze-action.ts | 11 +++++------ src/analyze.ts | 12 ++++++++++++ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/entry-points.js b/lib/entry-points.js index 3fbacc32e..ef7547dda 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -153801,6 +153801,9 @@ var CodeQLAnalysisError = class extends Error { message; error; }; +function determineCheckoutPath(action) { + return action.actions.getRequiredInput("checkout_path"); +} async function setupPythonExtractor(logger) { const codeqlPython = process.env["CODEQL_PYTHON"]; if (codeqlPython === void 0 || codeqlPython.length === 0) { @@ -156544,11 +156547,9 @@ async function runAutobuildIfLegacyGoWorkflow(config, logger) { ); await runAutobuild(config, "go" /* go */, logger); } -async function run({ - startedAt, - logger, - actions -}) { +async function run(action) { + const startedAt = action.startedAt; + const logger = action.logger; let uploadResults = void 0; let runStats = void 0; let config = void 0; @@ -156614,7 +156615,7 @@ async function run({ getOptionalInput("ram") || process.env["CODEQL_RAM"], logger ); - const checkoutPath = actions.getRequiredInput("checkout_path"); + const checkoutPath = determineCheckoutPath(action); const diffRangePackDir = await setupDiffInformedQueryRun( logger, checkoutPath diff --git a/src/analyze-action.ts b/src/analyze-action.ts index 7963fa52b..67b025ead 100644 --- a/src/analyze-action.ts +++ b/src/analyze-action.ts @@ -10,6 +10,7 @@ import * as analyses from "./analyses"; import { CodeQLAnalysisError, dbIsFinalized, + determineCheckoutPath, QueriesStatusReport, runFinalize, runQueries, @@ -212,13 +213,11 @@ async function runAutobuildIfLegacyGoWorkflow(config: Config, logger: Logger) { await runAutobuild(config, BuiltInLanguage.go, logger); } -async function run({ - startedAt, - logger, - actions, -}: ActionState<["Base", "Logger", "Actions"]>) { +async function run(action: ActionState<["Base", "Logger", "Env", "Actions"]>) { // To capture errors appropriately, keep as much code within the try-catch as // possible, and only use safe functions outside. + const startedAt = action.startedAt; + const logger = action.logger; let uploadResults: | Partial> @@ -311,7 +310,7 @@ async function run({ logger, ); - const checkoutPath = actions.getRequiredInput("checkout_path"); + const checkoutPath = determineCheckoutPath(action); // Setup diff informed analysis if needed (based on whether init created the file) const diffRangePackDir = await setupDiffInformedQueryRun( diff --git a/src/analyze.ts b/src/analyze.ts index 8f9071168..3580f80aa 100644 --- a/src/analyze.ts +++ b/src/analyze.ts @@ -5,6 +5,7 @@ import { performance } from "perf_hooks"; import * as io from "@actions/io"; import * as yaml from "js-yaml"; +import type { ActionState } from "./action-common"; import { getTemporaryDirectory } from "./actions-util"; import * as analyses from "./analyses"; import { setupCppAutobuild } from "./autobuild"; @@ -85,6 +86,17 @@ export interface QueriesStatusReport event_reports?: EventReport[]; } +/** + * Determines the path at which the repository being analysed is checked out at. + * Returns the value of the required `checkout_path` input and validates that it + * refers to the root of a repository. + * + * @param action The action state. + */ +export function determineCheckoutPath(action: ActionState<["Actions"]>) { + return action.actions.getRequiredInput("checkout_path"); +} + async function setupPythonExtractor(logger: Logger) { const codeqlPython = process.env["CODEQL_PYTHON"]; if (codeqlPython === undefined || codeqlPython.length === 0) {