Refactor getCodeQLActionRepository out of setup-codeql

This commit is contained in:
Michael B. Gale
2026-10-06 13:45:35 +01:00
parent 909fda1468
commit cb7acf5396
5 changed files with 66 additions and 44 deletions

View File

@@ -0,0 +1,31 @@
import * as path from "path";
import test from "ava";
import * as sinon from "sinon";
import * as actionsUtil from "../actions-util";
import { getRunnerLogger } from "../logging";
import { setupTests } from "../testing-utils";
import { initializeEnvironment } from "../util";
import { getCodeQLActionRepository } from "./repository";
setupTests(test);
test.serial("getCodeQLActionRepository", (t) => {
const logger = getRunnerLogger(true);
initializeEnvironment("1.2.3");
// isRunningLocalAction() === true
delete process.env["GITHUB_ACTION_REPOSITORY"];
process.env["RUNNER_TEMP"] = path.dirname(__dirname);
const repoLocalRunner = getCodeQLActionRepository(logger);
t.deepEqual(repoLocalRunner, "github/codeql-action");
// isRunningLocalAction() === false
sinon.stub(actionsUtil, "isRunningLocalAction").returns(false);
process.env["GITHUB_ACTION_REPOSITORY"] = "xxx/yyy";
const repoEnv = getCodeQLActionRepository(logger);
t.deepEqual(repoEnv, "xxx/yyy");
});

19
src/setup/repository.ts Normal file
View File

@@ -0,0 +1,19 @@
import { isRunningLocalAction } from "../actions-util";
import { Logger } from "../logging";
import * as util from "../util";
export const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
export function getCodeQLActionRepository(logger: Logger): string {
if (isRunningLocalAction()) {
// This handles the case where the Action does not come from an Action repository,
// e.g. our integration tests which use the Action code from the current checkout.
// In these cases, the GITHUB_ACTION_REPOSITORY environment variable is not set.
logger.info(
"The CodeQL Action is checked out locally. Using the default CodeQL Action repository.",
);
return CODEQL_DEFAULT_ACTION_REPOSITORY;
}
return util.getRequiredEnvParam("GITHUB_ACTION_REPOSITORY");
}