Skip to content

Commit 7cd944c

Browse files
committed
Move UploadKind check into uploadSarif
1 parent 1bf5c82 commit 7cd944c

File tree

6 files changed

+49
-25
lines changed

6 files changed

+49
-25
lines changed

lib/analyze-action.js

Lines changed: 14 additions & 9 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: 10 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analyze-action.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,17 @@ async function run() {
339339
}
340340
core.setOutput("db-locations", dbLocations);
341341
core.setOutput("sarif-output", path.resolve(outputDir));
342-
const uploadInput = actionsUtil.getOptionalInput("upload");
343-
if (runStats && actionsUtil.getUploadValue(uploadInput) === "always") {
342+
const uploadKind = actionsUtil.getUploadValue(
343+
actionsUtil.getOptionalInput("upload"),
344+
);
345+
if (runStats) {
344346
const checkoutPath = actionsUtil.getRequiredInput("checkout_path");
345347
const category = actionsUtil.getOptionalInput("category");
346348

347349
uploadResults = await uploadSarif(
348350
logger,
349351
features,
352+
uploadKind,
350353
checkoutPath,
351354
outputDir,
352355
category,

src/upload-sarif-action.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ async function run() {
9393
const uploadResults = await uploadSarif(
9494
logger,
9595
features,
96+
"always",
9697
checkoutPath,
9798
sarifPath,
9899
category,

src/upload-sarif.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ const uploadSarifMacro = test.macro({
6464
fs.writeFileSync(sarifFile, "");
6565
}
6666

67-
const actual = await uploadSarif(logger, features, "", testPath);
67+
const actual = await uploadSarif(
68+
logger,
69+
features,
70+
"always",
71+
"",
72+
testPath,
73+
);
6874

6975
for (const analysisKind of Object.values(AnalysisKind)) {
7076
const analysisKindResult = expectedResult[analysisKind];

src/upload-sarif.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { UploadKind } from "./actions-util";
12
import * as analyses from "./analyses";
23
import { FeatureEnablement } from "./feature-flags";
34
import { Logger } from "./logging";
@@ -14,6 +15,7 @@ export type UploadSarifResults = Partial<
1415
*
1516
* @param logger The logger to use.
1617
* @param features Information about enabled features.
18+
* @param uploadKind The kind of upload that is requested.
1719
* @param checkoutPath The path where the repository was checked out at.
1820
* @param sarifPath The path to the file or directory to upload.
1921
* @param category The analysis category.
@@ -23,6 +25,7 @@ export type UploadSarifResults = Partial<
2325
export async function uploadSarif(
2426
logger: Logger,
2527
features: FeatureEnablement,
28+
uploadKind: UploadKind,
2629
checkoutPath: string,
2730
sarifPath: string,
2831
category?: string,
@@ -46,12 +49,15 @@ export async function uploadSarif(
4649
analysisConfig,
4750
);
4851

49-
uploadResults[analysisKind] = await upload_lib.uploadProcessedFiles(
50-
logger,
51-
checkoutPath,
52-
analysisConfig,
53-
processingResults,
54-
);
52+
// Only perform the actual upload of the processed files, if `uploadKind` is `always`.
53+
if (uploadKind === "always") {
54+
uploadResults[analysisKind] = await upload_lib.uploadProcessedFiles(
55+
logger,
56+
checkoutPath,
57+
analysisConfig,
58+
processingResults,
59+
);
60+
}
5561
}
5662

5763
return uploadResults;

0 commit comments

Comments
 (0)