Refactor: Add determineCheckoutPath function for analyze action

This commit is contained in:
Michael B. Gale
2026-09-16 12:44:04 +01:00
parent 416ff0dea1
commit 99fe83948e
3 changed files with 24 additions and 12 deletions

13
lib/entry-points.js generated
View File

@@ -153801,6 +153801,9 @@ var CodeQLAnalysisError = class extends Error {
message; message;
error; error;
}; };
function determineCheckoutPath(action) {
return action.actions.getRequiredInput("checkout_path");
}
async function setupPythonExtractor(logger) { async function setupPythonExtractor(logger) {
const codeqlPython = process.env["CODEQL_PYTHON"]; const codeqlPython = process.env["CODEQL_PYTHON"];
if (codeqlPython === void 0 || codeqlPython.length === 0) { if (codeqlPython === void 0 || codeqlPython.length === 0) {
@@ -156544,11 +156547,9 @@ async function runAutobuildIfLegacyGoWorkflow(config, logger) {
); );
await runAutobuild(config, "go" /* go */, logger); await runAutobuild(config, "go" /* go */, logger);
} }
async function run({ async function run(action) {
startedAt, const startedAt = action.startedAt;
logger, const logger = action.logger;
actions
}) {
let uploadResults = void 0; let uploadResults = void 0;
let runStats = void 0; let runStats = void 0;
let config = void 0; let config = void 0;
@@ -156614,7 +156615,7 @@ async function run({
getOptionalInput("ram") || process.env["CODEQL_RAM"], getOptionalInput("ram") || process.env["CODEQL_RAM"],
logger logger
); );
const checkoutPath = actions.getRequiredInput("checkout_path"); const checkoutPath = determineCheckoutPath(action);
const diffRangePackDir = await setupDiffInformedQueryRun( const diffRangePackDir = await setupDiffInformedQueryRun(
logger, logger,
checkoutPath checkoutPath

View File

@@ -10,6 +10,7 @@ import * as analyses from "./analyses";
import { import {
CodeQLAnalysisError, CodeQLAnalysisError,
dbIsFinalized, dbIsFinalized,
determineCheckoutPath,
QueriesStatusReport, QueriesStatusReport,
runFinalize, runFinalize,
runQueries, runQueries,
@@ -212,13 +213,11 @@ async function runAutobuildIfLegacyGoWorkflow(config: Config, logger: Logger) {
await runAutobuild(config, BuiltInLanguage.go, logger); await runAutobuild(config, BuiltInLanguage.go, logger);
} }
async function run({ async function run(action: ActionState<["Base", "Logger", "Env", "Actions"]>) {
startedAt,
logger,
actions,
}: ActionState<["Base", "Logger", "Actions"]>) {
// To capture errors appropriately, keep as much code within the try-catch as // To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside. // possible, and only use safe functions outside.
const startedAt = action.startedAt;
const logger = action.logger;
let uploadResults: let uploadResults:
| Partial<Record<analyses.AnalysisKind, UploadResult>> | Partial<Record<analyses.AnalysisKind, UploadResult>>
@@ -311,7 +310,7 @@ async function run({
logger, logger,
); );
const checkoutPath = actions.getRequiredInput("checkout_path"); const checkoutPath = determineCheckoutPath(action);
// Setup diff informed analysis if needed (based on whether init created the file) // Setup diff informed analysis if needed (based on whether init created the file)
const diffRangePackDir = await setupDiffInformedQueryRun( const diffRangePackDir = await setupDiffInformedQueryRun(

View File

@@ -5,6 +5,7 @@ import { performance } from "perf_hooks";
import * as io from "@actions/io"; import * as io from "@actions/io";
import * as yaml from "js-yaml"; import * as yaml from "js-yaml";
import type { ActionState } from "./action-common";
import { getTemporaryDirectory } from "./actions-util"; import { getTemporaryDirectory } from "./actions-util";
import * as analyses from "./analyses"; import * as analyses from "./analyses";
import { setupCppAutobuild } from "./autobuild"; import { setupCppAutobuild } from "./autobuild";
@@ -85,6 +86,17 @@ export interface QueriesStatusReport
event_reports?: EventReport[]; 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) { async function setupPythonExtractor(logger: Logger) {
const codeqlPython = process.env["CODEQL_PYTHON"]; const codeqlPython = process.env["CODEQL_PYTHON"];
if (codeqlPython === undefined || codeqlPython.length === 0) { if (codeqlPython === undefined || codeqlPython.length === 0) {