mirror of
https://github.com/github/codeql-action.git
synced 2026-04-28 18:08:53 +00:00
Specify reason for skipping SARIF upload in logs
This commit is contained in:
+1
-1
@@ -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",
|
||||
}
|
||||
|
||||
@@ -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
@@ -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";
|
||||
|
||||
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user