Move UploadKind check into uploadSarif

This commit is contained in:
Michael B. Gale
2025-10-21 23:41:40 +01:00
parent 899bf2fd1e
commit 596de7f1bc
6 changed files with 49 additions and 25 deletions

View File

@@ -344,8 +344,10 @@ async function run() {
}
core.setOutput("db-locations", dbLocations);
core.setOutput("sarif-output", path.resolve(outputDir));
const uploadInput = actionsUtil.getOptionalInput("upload");
if (runStats && actionsUtil.getUploadValue(uploadInput) === "always") {
const uploadKind = actionsUtil.getUploadValue(
actionsUtil.getOptionalInput("upload"),
);
if (runStats) {
const checkoutPath = actionsUtil.getRequiredInput("checkout_path");
const category = actionsUtil.getOptionalInput("category");
@@ -353,6 +355,7 @@ async function run() {
uploadResults = await uploadSarif(
logger,
features,
uploadKind,
checkoutPath,
outputDir,
category,

View File

@@ -93,6 +93,7 @@ async function run() {
const uploadResults = await uploadSarif(
logger,
features,
"always",
checkoutPath,
sarifPath,
category,

View File

@@ -64,7 +64,13 @@ const uploadSarifMacro = test.macro({
fs.writeFileSync(sarifFile, "");
}
const actual = await uploadSarif(logger, features, "", testPath);
const actual = await uploadSarif(
logger,
features,
"always",
"",
testPath,
);
for (const analysisKind of Object.values(AnalysisKind)) {
const analysisKindResult = expectedResult[analysisKind];

View File

@@ -1,3 +1,4 @@
import { UploadKind } from "./actions-util";
import * as analyses from "./analyses";
import { FeatureEnablement } from "./feature-flags";
import { Logger } from "./logging";
@@ -14,6 +15,7 @@ export type UploadSarifResults = Partial<
*
* @param logger The logger to use.
* @param features Information about enabled features.
* @param uploadKind The kind of upload that is requested.
* @param checkoutPath The path where the repository was checked out at.
* @param sarifPath The path to the file or directory to upload.
* @param category The analysis category.
@@ -23,6 +25,7 @@ export type UploadSarifResults = Partial<
export async function uploadSarif(
logger: Logger,
features: FeatureEnablement,
uploadKind: UploadKind,
checkoutPath: string,
sarifPath: string,
category?: string,
@@ -46,12 +49,15 @@ export async function uploadSarif(
analysisConfig,
);
uploadResults[analysisKind] = await upload_lib.uploadProcessedFiles(
logger,
checkoutPath,
analysisConfig,
processingResults,
);
// Only perform the actual upload of the processed files, if `uploadKind` is `always`.
if (uploadKind === "always") {
uploadResults[analysisKind] = await upload_lib.uploadProcessedFiles(
logger,
checkoutPath,
analysisConfig,
processingResults,
);
}
}
return uploadResults;