From 596de7f1bc1027a9856c6855d3b8ef29fd4820c7 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Tue, 21 Oct 2025 23:41:40 +0100 Subject: [PATCH] Move `UploadKind` check into `uploadSarif` --- lib/analyze-action.js | 23 ++++++++++++++--------- lib/upload-sarif-action.js | 17 ++++++++++------- src/analyze-action.ts | 7 +++++-- src/upload-sarif-action.ts | 1 + src/upload-sarif.test.ts | 8 +++++++- src/upload-sarif.ts | 18 ++++++++++++------ 6 files changed, 49 insertions(+), 25 deletions(-) diff --git a/lib/analyze-action.js b/lib/analyze-action.js index a43be6256..887d7e3bf 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -96180,7 +96180,7 @@ function filterAlertsByDiffRange(logger, sarif) { } // src/upload-sarif.ts -async function uploadSarif(logger, features, checkoutPath, sarifPath, category) { +async function uploadSarif(logger, features, uploadKind, checkoutPath, sarifPath, category) { const sarifGroups = await getGroupedSarifFilePaths( logger, sarifPath @@ -96198,12 +96198,14 @@ async function uploadSarif(logger, features, checkoutPath, sarifPath, category) category, analysisConfig ); - uploadResults[analysisKind] = await uploadProcessedFiles( - logger, - checkoutPath, - analysisConfig, - processingResults - ); + if (uploadKind === "always") { + uploadResults[analysisKind] = await uploadProcessedFiles( + logger, + checkoutPath, + analysisConfig, + processingResults + ); + } } return uploadResults; } @@ -96402,14 +96404,17 @@ async function run() { } core14.setOutput("db-locations", dbLocations); core14.setOutput("sarif-output", import_path4.default.resolve(outputDir)); - const uploadInput = getOptionalInput("upload"); - if (runStats && getUploadValue(uploadInput) === "always") { + const uploadKind = getUploadValue( + getOptionalInput("upload") + ); + if (runStats) { const checkoutPath = getRequiredInput("checkout_path"); const category = getOptionalInput("category"); if (await features.getValue("analyze_use_new_upload" /* AnalyzeUseNewUpload */)) { uploadResults = await uploadSarif( logger, features, + uploadKind, checkoutPath, outputDir, category diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index a23b7d469..547ef8f10 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -93620,7 +93620,7 @@ function filterAlertsByDiffRange(logger, sarif) { } // src/upload-sarif.ts -async function uploadSarif(logger, features, checkoutPath, sarifPath, category) { +async function uploadSarif(logger, features, uploadKind, checkoutPath, sarifPath, category) { const sarifGroups = await getGroupedSarifFilePaths( logger, sarifPath @@ -93638,12 +93638,14 @@ async function uploadSarif(logger, features, checkoutPath, sarifPath, category) category, analysisConfig ); - uploadResults[analysisKind] = await uploadProcessedFiles( - logger, - checkoutPath, - analysisConfig, - processingResults - ); + if (uploadKind === "always") { + uploadResults[analysisKind] = await uploadProcessedFiles( + logger, + checkoutPath, + analysisConfig, + processingResults + ); + } } return uploadResults; } @@ -93698,6 +93700,7 @@ async function run() { const uploadResults = await uploadSarif( logger, features, + "always", checkoutPath, sarifPath, category diff --git a/src/analyze-action.ts b/src/analyze-action.ts index b6aa05ebe..36517624d 100644 --- a/src/analyze-action.ts +++ b/src/analyze-action.ts @@ -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, diff --git a/src/upload-sarif-action.ts b/src/upload-sarif-action.ts index a2ef43eb4..8a8bca8b7 100644 --- a/src/upload-sarif-action.ts +++ b/src/upload-sarif-action.ts @@ -93,6 +93,7 @@ async function run() { const uploadResults = await uploadSarif( logger, features, + "always", checkoutPath, sarifPath, category, diff --git a/src/upload-sarif.test.ts b/src/upload-sarif.test.ts index e932b65ff..f3305c92a 100644 --- a/src/upload-sarif.test.ts +++ b/src/upload-sarif.test.ts @@ -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]; diff --git a/src/upload-sarif.ts b/src/upload-sarif.ts index df3461643..7fc2d2cd3 100644 --- a/src/upload-sarif.ts +++ b/src/upload-sarif.ts @@ -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;