Skip to content

Commit 8301b8b

Browse files
authored
Merge pull request #3180 from github/redsun82/skip-sarif-upload
Introduce `CODEQL_ACTION_SKIP_SARIF_UPLOAD`
2 parents 7bdfa97 + 1707898 commit 8301b8b

File tree

9 files changed

+53
-25
lines changed

9 files changed

+53
-25
lines changed

lib/analyze-action.js

Lines changed: 6 additions & 3 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: 7 additions & 4 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: 6 additions & 3 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: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/environment.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,10 @@ export enum EnvVar {
128128
* whether the upload is disabled. This is intended for testing and debugging purposes.
129129
*/
130130
SARIF_DUMP_DIR = "CODEQL_ACTION_SARIF_DUMP_DIR",
131+
132+
/**
133+
* Whether to skip uploading SARIF results to GitHub. Intended for testing purposes.
134+
* This setting is more specific than `CODEQL_ACTION_TEST_MODE`, which implies this option.
135+
*/
136+
SKIP_SARIF_UPLOAD = "CODEQL_ACTION_SKIP_SARIF_UPLOAD",
131137
}

src/init-action-post-helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import {
1919
delay,
2020
getErrorMessage,
2121
getRequiredEnvParam,
22-
isInTestMode,
2322
parseMatrixInput,
23+
shouldSkipSarifUpload,
2424
wrapError,
2525
} from "./util";
2626
import {
@@ -81,7 +81,7 @@ async function maybeUploadFailedSarif(
8181
!["always", "failure-only"].includes(
8282
actionsUtil.getUploadValue(shouldUpload),
8383
) ||
84-
isInTestMode()
84+
shouldSkipSarifUpload()
8585
) {
8686
return { upload_failed_run_skipped_because: "SARIF upload is disabled" };
8787
}

src/upload-lib.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,18 +356,17 @@ async function uploadPayload(
356356
): Promise<string> {
357357
logger.info("Uploading results");
358358

359-
// If in test mode we don't want to upload the results
360-
if (util.isInTestMode()) {
359+
if (util.shouldSkipSarifUpload()) {
361360
const payloadSaveFile = path.join(
362361
actionsUtil.getTemporaryDirectory(),
363362
`payload-${analysis.kind}.json`,
364363
);
365364
logger.info(
366-
`In test mode. Results are not uploaded. Saving to ${payloadSaveFile}`,
365+
`SARIF upload disabled by an environment variable. Saving to ${payloadSaveFile}`,
367366
);
368367
logger.info(`Payload: ${JSON.stringify(payload, null, 2)}`);
369368
fs.writeFileSync(payloadSaveFile, JSON.stringify(payload, null, 2));
370-
return "test-mode-sarif-id";
369+
return "dummy-sarif-id";
371370
}
372371

373372
const client = api.getApiClient();

src/upload-sarif-action.ts

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

@@ -113,8 +113,10 @@ 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 (isInTestMode()) {
117-
core.debug("In test mode. Waiting for processing is disabled.");
116+
if (shouldSkipSarifUpload()) {
117+
core.debug(
118+
"SARIF upload disabled by an environment variable. Waiting for processing is disabled.",
119+
);
118120
} else if (actionsUtil.getRequiredInput("wait-for-processing") === "true") {
119121
if (codeScanningResult !== undefined) {
120122
await upload_lib.waitForProcessing(

src/util.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,12 +764,19 @@ export function isGoodVersion(versionSpec: string) {
764764
/**
765765
* Returns whether we are in test mode. This is used by CodeQL Action PR checks.
766766
*
767-
* In test mode, we don't upload SARIF results or status reports to the GitHub API.
767+
* In test mode, we skip several uploads (SARIF results, status reports, DBs, ...).
768768
*/
769769
export function isInTestMode(): boolean {
770770
return process.env[EnvVar.TEST_MODE] === "true";
771771
}
772772

773+
/**
774+
* Returns whether we specifically want to skip uploading SARIF files.
775+
*/
776+
export function shouldSkipSarifUpload(): boolean {
777+
return isInTestMode() || process.env[EnvVar.SKIP_SARIF_UPLOAD] === "true";
778+
}
779+
773780
/**
774781
* Get the testing environment.
775782
*

0 commit comments

Comments
 (0)