Skip to content

Commit e0b9da7

Browse files
committed
Introduce CODEQL_ACTION_SKIP_SARIF_UPLOAD
This triggers a subset of the behavior of `CODEQL_ACTION_TEST_MODE`, specifically just skipping the SARIF upload step. This is required for our internal testing where we want the SARIF file (via `CODEQL_ACTION_DUMP_SARIF_DIR`) but don't want to actually upload it, but we don't want the rest of the behaviour of `CODEQL_ACTION_TEST_MODE` that is specific for `codeql-action` own CI checks.
1 parent 065c6cf commit e0b9da7

File tree

9 files changed

+50
-35
lines changed

9 files changed

+50
-35
lines changed

lib/analyze-action.js

Lines changed: 6 additions & 5 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 & 6 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 & 5 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: 8 additions & 7 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 implied but is more specific than `CODEQL_ACTION_TEST_MODE`.
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: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,18 +356,16 @@ 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 in test mode we don't want to upload the results,
360+
if (util.shouldSkipSarifUpload()) {
361361
const payloadSaveFile = path.join(
362362
actionsUtil.getTemporaryDirectory(),
363363
"payload.json",
364364
);
365-
logger.info(
366-
`In test mode. Results are not uploaded. Saving to ${payloadSaveFile}`,
367-
);
365+
logger.info(`SARIF upload disabled. Saving to ${payloadSaveFile}`);
368366
logger.info(`Payload: ${JSON.stringify(payload, null, 2)}`);
369367
fs.writeFileSync(payloadSaveFile, JSON.stringify(payload, null, 2));
370-
return "test-mode-sarif-id";
368+
return "dummy-sarif-id";
371369
}
372370

373371
const client = api.getApiClient();

src/upload-sarif-action.ts

Lines changed: 3 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,8 @@ 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("SARIF upload disabled. Waiting for processing is disabled.");
118118
} else if (actionsUtil.getRequiredInput("wait-for-processing") === "true") {
119119
if (codeScanningResult !== undefined) {
120120
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 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)