Skip to content

Commit 89e7146

Browse files
committed
Add and use shouldSkipGenerateFailedSarif
1 parent f83967b commit 89e7146

5 files changed

Lines changed: 70 additions & 3 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/environment.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ export enum EnvVar {
165165
*/
166166
SARIF_DUMP_DIR = "CODEQL_ACTION_SARIF_DUMP_DIR",
167167

168+
/**
169+
* Whether to skip generating a failed SARIF file. Intended for testing purposes.
170+
* This setting is more specific than `CODEQL_ACTION_TEST_MODE` and
171+
* `CODEQL_ACTION_SKIP_SARIF_UPLOAD`, which imply this option.
172+
*/
173+
SKIP_GENERATE_FAILED_SARIF = "CODEQL_ACTION_SKIP_GENERATE_FAILED_SARIF",
174+
168175
/**
169176
* Whether to skip uploading SARIF results to GitHub. Intended for testing purposes.
170177
* This setting is more specific than `CODEQL_ACTION_TEST_MODE`, which implies this option.

‎src/init-action-post-helper.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545
getRequiredEnvParam,
4646
parseMatrixInput,
4747
Result,
48-
shouldSkipSarifUpload,
48+
shouldSkipGenerateFailedSarif,
4949
Success,
5050
wrapError,
5151
} from "./util";
@@ -116,7 +116,7 @@ async function prepareFailedSarif(
116116
const jobName = getRequiredEnvParam("GITHUB_JOB");
117117
const matrix = parseMatrixInput(actionsUtil.getRequiredInput("matrix"));
118118

119-
if (shouldSkipSarifUpload()) {
119+
if (shouldSkipGenerateFailedSarif()) {
120120
return new Failure({
121121
upload_failed_run_skipped_because: "SARIF upload is disabled",
122122
});

‎src/util.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,45 @@ test("Failure.orElse returns the default value for a failure result", (t) => {
554554
t.is(result.orElse("default value"), "default value");
555555
});
556556

557+
test("shouldSkipGenerateFailedSarif", (t) => {
558+
const env = getTestEnv();
559+
560+
// Don't skip by default
561+
t.is(util.shouldSkipGenerateFailedSarif(env), false);
562+
563+
// Skip in test mode
564+
env.setAll({
565+
[EnvVar.TEST_MODE]: "true",
566+
[EnvVar.SKIP_SARIF_UPLOAD]: undefined,
567+
[EnvVar.SKIP_GENERATE_FAILED_SARIF]: undefined,
568+
});
569+
t.is(util.shouldSkipGenerateFailedSarif(env), true);
570+
571+
// Skip if explicitly requested
572+
env.setAll({
573+
[EnvVar.TEST_MODE]: undefined,
574+
[EnvVar.SKIP_SARIF_UPLOAD]: undefined,
575+
[EnvVar.SKIP_GENERATE_FAILED_SARIF]: "true",
576+
});
577+
t.is(util.shouldSkipGenerateFailedSarif(env), true);
578+
579+
// Skip if not uploading SARIF
580+
env.setAll({
581+
[EnvVar.TEST_MODE]: undefined,
582+
[EnvVar.SKIP_SARIF_UPLOAD]: "true",
583+
[EnvVar.SKIP_GENERATE_FAILED_SARIF]: undefined,
584+
});
585+
t.is(util.shouldSkipGenerateFailedSarif(env), true);
586+
587+
// Don't skip if explicitly requested
588+
env.setAll({
589+
[EnvVar.TEST_MODE]: "true",
590+
[EnvVar.SKIP_SARIF_UPLOAD]: "true",
591+
[EnvVar.SKIP_GENERATE_FAILED_SARIF]: "false",
592+
});
593+
t.is(util.shouldSkipGenerateFailedSarif(env), false);
594+
});
595+
557596
test("shouldSkipSarifUpload", (t) => {
558597
const env = getTestEnv();
559598

‎src/util.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,21 @@ export function isGoodVersion(versionSpec: string) {
732732
return !BROKEN_VERSIONS.includes(versionSpec);
733733
}
734734

735+
/**
736+
* Returns whether we specifically want to skip generating a failed SARIF.
737+
*/
738+
export function shouldSkipGenerateFailedSarif(
739+
env: ReadOnlyEnv = getEnv(),
740+
): boolean {
741+
const skipGenerateFailedSarif = env.getOptional(
742+
EnvVar.SKIP_GENERATE_FAILED_SARIF,
743+
);
744+
return (
745+
skipGenerateFailedSarif !== "false" &&
746+
(shouldSkipSarifUpload(env) || skipGenerateFailedSarif === "true")
747+
);
748+
}
749+
735750
/**
736751
* Returns whether we specifically want to skip uploading SARIF files.
737752
*/

0 commit comments

Comments
 (0)