Skip to content

Commit 6e9aec6

Browse files
authored
Add and use shouldSkipGenerateFailedSarif
1 parent a9cd2f9 commit 6e9aec6

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
@@ -44,7 +44,7 @@ import {
4444
getRequiredEnvParam,
4545
parseMatrixInput,
4646
Result,
47-
shouldSkipSarifUpload,
47+
shouldSkipGenerateFailedSarif,
4848
Success,
4949
wrapError,
5050
} from "./util";
@@ -115,7 +115,7 @@ async function prepareFailedSarif(
115115
const jobName = getRequiredEnvParam("GITHUB_JOB");
116116
const matrix = parseMatrixInput(actionsUtil.getRequiredInput("matrix"));
117117

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

‎src/util.test.ts‎

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

497+
test("shouldSkipGenerateFailedSarif", (t) => {
498+
const env = getTestEnv();
499+
500+
// Don't skip by default
501+
t.is(util.shouldSkipGenerateFailedSarif(env), false);
502+
503+
// Skip in test mode
504+
env.setAll({
505+
[EnvVar.TEST_MODE]: "true",
506+
[EnvVar.SKIP_SARIF_UPLOAD]: undefined,
507+
[EnvVar.SKIP_GENERATE_FAILED_SARIF]: undefined,
508+
});
509+
t.is(util.shouldSkipGenerateFailedSarif(env), true);
510+
511+
// Skip if explicitly requested
512+
env.setAll({
513+
[EnvVar.TEST_MODE]: undefined,
514+
[EnvVar.SKIP_SARIF_UPLOAD]: undefined,
515+
[EnvVar.SKIP_GENERATE_FAILED_SARIF]: "true",
516+
});
517+
t.is(util.shouldSkipGenerateFailedSarif(env), true);
518+
519+
// Skip if not uploading SARIF
520+
env.setAll({
521+
[EnvVar.TEST_MODE]: undefined,
522+
[EnvVar.SKIP_SARIF_UPLOAD]: "true",
523+
[EnvVar.SKIP_GENERATE_FAILED_SARIF]: undefined,
524+
});
525+
t.is(util.shouldSkipGenerateFailedSarif(env), true);
526+
527+
// Don't skip if explicitly requested
528+
env.setAll({
529+
[EnvVar.TEST_MODE]: "true",
530+
[EnvVar.SKIP_SARIF_UPLOAD]: "true",
531+
[EnvVar.SKIP_GENERATE_FAILED_SARIF]: "false",
532+
});
533+
t.is(util.shouldSkipGenerateFailedSarif(env), false);
534+
});
535+
497536
test("shouldSkipSarifUpload", (t) => {
498537
const env = getTestEnv();
499538

‎src/util.ts‎

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

687+
/**
688+
* Returns whether we specifically want to skip generating a failed SARIF.
689+
*/
690+
export function shouldSkipGenerateFailedSarif(
691+
env: ReadOnlyEnv = getEnv(),
692+
): boolean {
693+
const skipGenerateFailedSarif = env.getOptional(
694+
EnvVar.SKIP_GENERATE_FAILED_SARIF,
695+
);
696+
return (
697+
skipGenerateFailedSarif !== "false" &&
698+
(shouldSkipSarifUpload(env) || skipGenerateFailedSarif === "true")
699+
);
700+
}
701+
687702
/**
688703
* Returns whether we specifically want to skip uploading SARIF files.
689704
*/

0 commit comments

Comments
 (0)