Skip to content

Commit f83967b

Browse files
committed
Allow to explicitly not skip the SARIF upload
1 parent f80ca03 commit f83967b

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/util.test.ts‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as sinon from "sinon";
1111
import * as api from "./api-client";
1212
import { EnvVar } from "./environment";
1313
import { getRunnerLogger } from "./logging";
14-
import { setupTests } from "./testing-utils";
14+
import { getTestEnv, setupTests } from "./testing-utils";
1515
import * as util from "./util";
1616

1717
setupTests(test);
@@ -553,3 +553,31 @@ test("Failure.orElse returns the default value for a failure result", (t) => {
553553
const result = new util.Failure(new Error("test error"));
554554
t.is(result.orElse("default value"), "default value");
555555
});
556+
557+
test("shouldSkipSarifUpload", (t) => {
558+
const env = getTestEnv();
559+
560+
// Don't skip by default
561+
t.is(util.shouldSkipSarifUpload(env), false);
562+
563+
// Skip in test mode
564+
env.setAll({
565+
[EnvVar.TEST_MODE]: "true",
566+
[EnvVar.SKIP_SARIF_UPLOAD]: undefined,
567+
});
568+
t.is(util.shouldSkipSarifUpload(env), true);
569+
570+
// Skip if explicitly requested
571+
env.setAll({
572+
[EnvVar.TEST_MODE]: undefined,
573+
[EnvVar.SKIP_SARIF_UPLOAD]: "true",
574+
});
575+
t.is(util.shouldSkipSarifUpload(env), true);
576+
577+
// Don't skip if explicitly requested
578+
env.setAll({
579+
[EnvVar.TEST_MODE]: "true",
580+
[EnvVar.SKIP_SARIF_UPLOAD]: "false",
581+
});
582+
t.is(util.shouldSkipSarifUpload(env), false);
583+
});

‎src/util.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import type { Config } from "./config-utils";
1818
import {
1919
EnvVar,
2020
getRequiredEnvParam,
21-
isInTestMode,
2221
exportEnvVar,
2322
getEnv,
2423
type Env,
24+
type ReadOnlyEnv,
2525
} from "./environment";
2626
import * as json from "./json";
2727
import { Language } from "./languages";
@@ -735,8 +735,12 @@ export function isGoodVersion(versionSpec: string) {
735735
/**
736736
* Returns whether we specifically want to skip uploading SARIF files.
737737
*/
738-
export function shouldSkipSarifUpload(): boolean {
739-
return isInTestMode() || process.env[EnvVar.SKIP_SARIF_UPLOAD] === "true";
738+
export function shouldSkipSarifUpload(env: ReadOnlyEnv = getEnv()): boolean {
739+
const skipSarifUpload = env.getOptional(EnvVar.SKIP_SARIF_UPLOAD);
740+
return (
741+
skipSarifUpload !== "false" &&
742+
(env.isSkippingUploadsInTests() || skipSarifUpload === "true")
743+
);
740744
}
741745

742746
/**

0 commit comments

Comments
 (0)