Specify reason for skipping SARIF upload in logs

This commit is contained in:
Paolo Tranquilli
2025-10-06 15:39:29 +02:00
parent 11e4034414
commit 680b07003d
9 changed files with 75 additions and 31 deletions
+1 -1
View File
@@ -131,7 +131,7 @@ export enum EnvVar {
/**
* Whether to skip uploading SARIF results to GitHub. Intended for testing purposes.
* This setting is implied by but is more specific than `CODEQL_ACTION_TEST_MODE`.
* This setting is implied by `CODEQL_ACTION_TEST_MODE`, but is more specific.
*/
SKIP_SARIF_UPLOAD = "CODEQL_ACTION_SKIP_SARIF_UPLOAD",
}
+6 -3
View File
@@ -20,7 +20,7 @@ import {
getErrorMessage,
getRequiredEnvParam,
parseMatrixInput,
shouldSkipSarifUpload,
getSarifUploadSkipReason,
wrapError,
} from "./util";
import {
@@ -80,11 +80,14 @@ async function maybeUploadFailedSarif(
if (
!["always", "failure-only"].includes(
actionsUtil.getUploadValue(shouldUpload),
) ||
shouldSkipSarifUpload()
)
) {
return { upload_failed_run_skipped_because: "SARIF upload is disabled" };
}
const skipReason = getSarifUploadSkipReason();
if (skipReason) {
return { upload_failed_run_skipped_because: skipReason };
}
const category = getCategoryInputOrThrow(workflow, jobName, matrix);
const checkoutPath = getCheckoutPathInputOrThrow(workflow, jobName, matrix);
const databasePath = config.dbLocation;
+3 -2
View File
@@ -357,12 +357,13 @@ async function uploadPayload(
logger.info("Uploading results");
// If in test mode we don't want to upload the results,
if (util.shouldSkipSarifUpload()) {
const skipReason = util.getSarifUploadSkipReason();
if (skipReason) {
const payloadSaveFile = path.join(
actionsUtil.getTemporaryDirectory(),
"payload.json",
);
logger.info(`SARIF upload disabled. Saving to ${payloadSaveFile}`);
logger.info(`${skipReason}. Saving to ${payloadSaveFile}`);
logger.info(`Payload: ${JSON.stringify(payload, null, 2)}`);
fs.writeFileSync(payloadSaveFile, JSON.stringify(payload, null, 2));
return "dummy-sarif-id";
+4 -3
View File
@@ -23,7 +23,7 @@ import {
checkDiskUsage,
getErrorMessage,
initializeEnvironment,
shouldSkipSarifUpload,
getSarifUploadSkipReason,
wrapError,
} from "./util";
@@ -113,8 +113,9 @@ async function run() {
core.setOutput("sarif-ids", JSON.stringify(uploadResults));
// We don't upload results in test mode, so don't wait for processing
if (shouldSkipSarifUpload()) {
core.debug("SARIF upload disabled. Waiting for processing is disabled.");
const skipReason = getSarifUploadSkipReason();
if (skipReason) {
core.debug(`${skipReason}. Waiting for processing is disabled.`);
} else if (actionsUtil.getRequiredInput("wait-for-processing") === "true") {
if (codeScanningResult !== undefined) {
await upload_lib.waitForProcessing(
+9 -3
View File
@@ -771,10 +771,16 @@ export function isInTestMode(): boolean {
}
/**
* Returns whether we specifically want to skip uploading SARIF files.
* Returns whether we specifically want to skip uploading SARIF files, and if so, why.
*/
export function shouldSkipSarifUpload(): boolean {
return isInTestMode() || process.env[EnvVar.SKIP_SARIF_UPLOAD] === "true";
export function getSarifUploadSkipReason(): string | null {
if (isInTestMode()) {
return `SARIF upload is disabled via ${EnvVar.TEST_MODE}`;
}
if (process.env[EnvVar.SKIP_SARIF_UPLOAD] === "true") {
return `SARIF upload is disabled via ${EnvVar.SKIP_SARIF_UPLOAD}`;
}
return null;
}
/**