Skip to content

Commit e180f80

Browse files
committed
Allow to explicitly not skip the SARIF upload
1 parent bf0e2ed commit e180f80

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);
@@ -493,3 +493,31 @@ test("Failure.orElse returns the default value for a failure result", (t) => {
493493
const result = new util.Failure(new Error("test error"));
494494
t.is(result.orElse("default value"), "default value");
495495
});
496+
497+
test("shouldSkipSarifUpload", (t) => {
498+
const env = getTestEnv();
499+
500+
// Don't skip by default
501+
t.is(util.shouldSkipSarifUpload(env), false);
502+
503+
// Skip in test mode
504+
env.setAll({
505+
[EnvVar.TEST_MODE]: "true",
506+
[EnvVar.SKIP_SARIF_UPLOAD]: undefined,
507+
});
508+
t.is(util.shouldSkipSarifUpload(env), true);
509+
510+
// Skip if explicitly requested
511+
env.setAll({
512+
[EnvVar.TEST_MODE]: undefined,
513+
[EnvVar.SKIP_SARIF_UPLOAD]: "true",
514+
});
515+
t.is(util.shouldSkipSarifUpload(env), true);
516+
517+
// Don't skip if explicitly requested
518+
env.setAll({
519+
[EnvVar.TEST_MODE]: "true",
520+
[EnvVar.SKIP_SARIF_UPLOAD]: "false",
521+
});
522+
t.is(util.shouldSkipSarifUpload(env), false);
523+
});

‎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";
@@ -687,8 +687,12 @@ export function isGoodVersion(versionSpec: string) {
687687
/**
688688
* Returns whether we specifically want to skip uploading SARIF files.
689689
*/
690-
export function shouldSkipSarifUpload(): boolean {
691-
return isInTestMode() || process.env[EnvVar.SKIP_SARIF_UPLOAD] === "true";
690+
export function shouldSkipSarifUpload(env: ReadOnlyEnv = getEnv()): boolean {
691+
const skipSarifUpload = env.getOptional(EnvVar.SKIP_SARIF_UPLOAD);
692+
return (
693+
skipSarifUpload !== "false" &&
694+
(env.isSkippingUploadsInTests() || skipSarifUpload === "true")
695+
);
692696
}
693697

694698
/**

0 commit comments

Comments
 (0)