From c8e017d3e778faac9a5b2898085a763c1198b3d1 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Thu, 18 Sep 2025 14:10:54 +0100 Subject: [PATCH] Move `isDirectory` check into `findAndUpload` --- lib/upload-sarif-action.js | 47 ++++++++++++++++++------------------ src/upload-sarif-action.ts | 49 ++++++++++++++++++++------------------ 2 files changed, 50 insertions(+), 46 deletions(-) diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index bc908440b..3a5044a3c 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -93358,20 +93358,22 @@ function filterAlertsByDiffRange(logger, sarif) { } // src/upload-sarif-action.ts -async function findAndUpload(logger, features, sarifPath, checkoutPath, analysis, category) { - const sarifFiles = findSarifFilesInDir( - sarifPath, - analysis.sarifPredicate - ); - if (sarifFiles.length !== 0) { - return await uploadSpecifiedFiles( - sarifFiles, - checkoutPath, - category, - features, - logger, - analysis +async function findAndUpload(logger, features, sarifPath, pathStats, checkoutPath, analysis, category) { + if (pathStats.isDirectory()) { + const sarifFiles = findSarifFilesInDir( + sarifPath, + analysis.sarifPredicate ); + if (sarifFiles.length !== 0) { + return await uploadSpecifiedFiles( + sarifFiles, + checkoutPath, + category, + features, + logger, + analysis + ); + } } return void 0; } @@ -93434,16 +93436,15 @@ async function run() { CodeScanning ); core13.setOutput("sarif-id", uploadResult.sarifID); - if (pathStats.isDirectory()) { - await findAndUpload( - logger, - features, - sarifPath, - checkoutPath, - CodeQuality, - fixCodeQualityCategory(logger, category) - ); - } + await findAndUpload( + logger, + features, + sarifPath, + pathStats, + checkoutPath, + CodeQuality, + fixCodeQualityCategory(logger, category) + ); if (isInTestMode()) { core13.debug("In test mode. Waiting for processing is disabled."); } else if (getRequiredInput("wait-for-processing") === "true") { diff --git a/src/upload-sarif-action.ts b/src/upload-sarif-action.ts index ee7cd6ad3..3d0fd55c5 100644 --- a/src/upload-sarif-action.ts +++ b/src/upload-sarif-action.ts @@ -39,6 +39,7 @@ interface UploadSarifStatusReport * @param logger The logger to use. * @param features Information about FFs. * @param sarifPath The path to a directory containing SARIF files. + * @param pathStats Information about `sarifPath`. * @param checkoutPath The checkout path. * @param analysis The configuration of the analysis we should upload SARIF files for. * @param category The SARIF category to use for the upload. @@ -48,24 +49,27 @@ async function findAndUpload( logger: Logger, features: Features, sarifPath: string, + pathStats: fs.Stats, checkoutPath: string, analysis: analyses.AnalysisConfig, category?: string, ): Promise { - const sarifFiles = upload_lib.findSarifFilesInDir( - sarifPath, - analysis.sarifPredicate, - ); - - if (sarifFiles.length !== 0) { - return await upload_lib.uploadSpecifiedFiles( - sarifFiles, - checkoutPath, - category, - features, - logger, - analysis, + if (pathStats.isDirectory()) { + const sarifFiles = upload_lib.findSarifFilesInDir( + sarifPath, + analysis.sarifPredicate, ); + + if (sarifFiles.length !== 0) { + return await upload_lib.uploadSpecifiedFiles( + sarifFiles, + checkoutPath, + category, + features, + logger, + analysis, + ); + } } return undefined; @@ -148,16 +152,15 @@ async function run() { // If there are `.quality.sarif` files in `sarifPath`, then upload those to the code quality service. // Code quality can currently only be enabled on top of security, so we'd currently always expect to // have a directory for the results here. - if (pathStats.isDirectory()) { - await findAndUpload( - logger, - features, - sarifPath, - checkoutPath, - analyses.CodeQuality, - actionsUtil.fixCodeQualityCategory(logger, category), - ); - } + await findAndUpload( + logger, + features, + sarifPath, + pathStats, + checkoutPath, + analyses.CodeQuality, + actionsUtil.fixCodeQualityCategory(logger, category), + ); // We don't upload results in test mode, so don't wait for processing if (isInTestMode()) {