Skip to content

Commit 680b070

Browse files
committed
Specify reason for skipping SARIF upload in logs
1 parent 11e4034 commit 680b070

File tree

9 files changed

+75
-31
lines changed

9 files changed

+75
-31
lines changed

lib/analyze-action.js

Lines changed: 11 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action-post.js

Lines changed: 16 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.js

Lines changed: 11 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-sarif-action.js

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export enum EnvVar {
131131

132132
/**
133133
* Whether to skip uploading SARIF results to GitHub. Intended for testing purposes.
134-
* This setting is implied by but is more specific than `CODEQL_ACTION_TEST_MODE`.
134+
* This setting is implied by `CODEQL_ACTION_TEST_MODE`, but is more specific.
135135
*/
136136
SKIP_SARIF_UPLOAD = "CODEQL_ACTION_SKIP_SARIF_UPLOAD",
137137
}

src/init-action-post-helper.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
getErrorMessage,
2121
getRequiredEnvParam,
2222
parseMatrixInput,
23-
shouldSkipSarifUpload,
23+
getSarifUploadSkipReason,
2424
wrapError,
2525
} from "./util";
2626
import {
@@ -80,11 +80,14 @@ async function maybeUploadFailedSarif(
8080
if (
8181
!["always", "failure-only"].includes(
8282
actionsUtil.getUploadValue(shouldUpload),
83-
) ||
84-
shouldSkipSarifUpload()
83+
)
8584
) {
8685
return { upload_failed_run_skipped_because: "SARIF upload is disabled" };
8786
}
87+
const skipReason = getSarifUploadSkipReason();
88+
if (skipReason) {
89+
return { upload_failed_run_skipped_because: skipReason };
90+
}
8891
const category = getCategoryInputOrThrow(workflow, jobName, matrix);
8992
const checkoutPath = getCheckoutPathInputOrThrow(workflow, jobName, matrix);
9093
const databasePath = config.dbLocation;

src/upload-lib.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,13 @@ async function uploadPayload(
357357
logger.info("Uploading results");
358358

359359
// If in test mode we don't want to upload the results,
360-
if (util.shouldSkipSarifUpload()) {
360+
const skipReason = util.getSarifUploadSkipReason();
361+
if (skipReason) {
361362
const payloadSaveFile = path.join(
362363
actionsUtil.getTemporaryDirectory(),
363364
"payload.json",
364365
);
365-
logger.info(`SARIF upload disabled. Saving to ${payloadSaveFile}`);
366+
logger.info(`${skipReason}. Saving to ${payloadSaveFile}`);
366367
logger.info(`Payload: ${JSON.stringify(payload, null, 2)}`);
367368
fs.writeFileSync(payloadSaveFile, JSON.stringify(payload, null, 2));
368369
return "dummy-sarif-id";

src/upload-sarif-action.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
checkDiskUsage,
2424
getErrorMessage,
2525
initializeEnvironment,
26-
shouldSkipSarifUpload,
26+
getSarifUploadSkipReason,
2727
wrapError,
2828
} from "./util";
2929

@@ -113,8 +113,9 @@ async function run() {
113113
core.setOutput("sarif-ids", JSON.stringify(uploadResults));
114114

115115
// We don't upload results in test mode, so don't wait for processing
116-
if (shouldSkipSarifUpload()) {
117-
core.debug("SARIF upload disabled. Waiting for processing is disabled.");
116+
const skipReason = getSarifUploadSkipReason();
117+
if (skipReason) {
118+
core.debug(`${skipReason}. Waiting for processing is disabled.`);
118119
} else if (actionsUtil.getRequiredInput("wait-for-processing") === "true") {
119120
if (codeScanningResult !== undefined) {
120121
await upload_lib.waitForProcessing(

src/util.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,10 +771,16 @@ export function isInTestMode(): boolean {
771771
}
772772

773773
/**
774-
* Returns whether we specifically want to skip uploading SARIF files.
774+
* Returns whether we specifically want to skip uploading SARIF files, and if so, why.
775775
*/
776-
export function shouldSkipSarifUpload(): boolean {
777-
return isInTestMode() || process.env[EnvVar.SKIP_SARIF_UPLOAD] === "true";
776+
export function getSarifUploadSkipReason(): string | null {
777+
if (isInTestMode()) {
778+
return `SARIF upload is disabled via ${EnvVar.TEST_MODE}`;
779+
}
780+
if (process.env[EnvVar.SKIP_SARIF_UPLOAD] === "true") {
781+
return `SARIF upload is disabled via ${EnvVar.SKIP_SARIF_UPLOAD}`;
782+
}
783+
return null;
778784
}
779785

780786
/**

0 commit comments

Comments
 (0)