Throw a ConfigurationError if setup-codeql has run before init

This commit is contained in:
Michael B. Gale
2025-10-16 20:03:26 +01:00
parent 000295122d
commit c0e8887d5a
5 changed files with 20 additions and 0 deletions

5
lib/init-action.js generated
View File

@@ -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
);

View File

@@ -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);

View File

@@ -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",

View File

@@ -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,
);

View File

@@ -152,6 +152,8 @@ async function run(): Promise<void> {
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);