diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index eb67a1367..5f86c6396 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -92985,23 +92985,6 @@ function findSarifFilesInDir(sarifPath, isSarif) { walkSarifFiles(sarifPath); return sarifFiles; } -function getSarifFilePaths(sarifPath, isSarif) { - if (!fs14.existsSync(sarifPath)) { - throw new ConfigurationError(`Path does not exist: ${sarifPath}`); - } - let sarifFiles; - if (fs14.lstatSync(sarifPath).isDirectory()) { - sarifFiles = findSarifFilesInDir(sarifPath, isSarif); - if (sarifFiles.length === 0) { - throw new ConfigurationError( - `No SARIF files found to upload in "${sarifPath}".` - ); - } - } else { - sarifFiles = [sarifPath]; - } - return sarifFiles; -} function countResultsInSarif(sarif) { let numResults = 0; const parsedSarif = JSON.parse(sarif); @@ -93097,20 +93080,6 @@ function buildPayload(commitOid, ref, analysisKey, analysisName, zippedSarif, wo } return payloadObj; } -async function uploadFiles(inputSarifPath, checkoutPath, category, features, logger, uploadTarget) { - const sarifPaths = getSarifFilePaths( - inputSarifPath, - uploadTarget.sarifPredicate - ); - return uploadSpecifiedFiles( - sarifPaths, - checkoutPath, - category, - features, - logger, - uploadTarget - ); -} async function uploadSpecifiedFiles(sarifPaths, checkoutPath, category, features, logger, uploadTarget) { logger.startGroup(`Uploading ${uploadTarget.name} results`); logger.info(`Processing sarif files: ${JSON.stringify(sarifPaths)}`); @@ -93432,15 +93401,18 @@ async function run() { if (pathStats === void 0) { throw new ConfigurationError(`Path does not exist: ${sarifPath}.`); } - const uploadResult = await uploadFiles( - sarifPath, - checkoutPath, - category, - features, + const uploadResult = await findAndUpload( logger, - CodeScanning + features, + sarifPath, + pathStats, + checkoutPath, + CodeScanning, + category ); - core13.setOutput("sarif-id", uploadResult.sarifID); + if (uploadResult !== void 0) { + core13.setOutput("sarif-id", uploadResult.sarifID); + } await findAndUpload( logger, features, @@ -93453,13 +93425,19 @@ async function run() { if (isInTestMode()) { core13.debug("In test mode. Waiting for processing is disabled."); } else if (getRequiredInput("wait-for-processing") === "true") { - await waitForProcessing( - getRepositoryNwo(), - uploadResult.sarifID, - logger - ); + if (uploadResult !== void 0) { + await waitForProcessing( + getRepositoryNwo(), + uploadResult.sarifID, + logger + ); + } } - await sendSuccessStatusReport(startedAt, uploadResult.statusReport, logger); + await sendSuccessStatusReport( + startedAt, + uploadResult?.statusReport || {}, + logger + ); } catch (unwrappedError) { const error2 = isThirdPartyAnalysis("upload-sarif" /* UploadSarif */) && unwrappedError instanceof InvalidSarifUploadError ? new ConfigurationError(unwrappedError.message) : wrapError(unwrappedError); const message = error2.message; diff --git a/src/upload-sarif-action.ts b/src/upload-sarif-action.ts index 8fb8c35c3..29f998e81 100644 --- a/src/upload-sarif-action.ts +++ b/src/upload-sarif-action.ts @@ -145,15 +145,18 @@ async function run() { throw new ConfigurationError(`Path does not exist: ${sarifPath}.`); } - const uploadResult = await upload_lib.uploadFiles( - sarifPath, - checkoutPath, - category, - features, + const uploadResult = await findAndUpload( logger, + features, + sarifPath, + pathStats, + checkoutPath, analyses.CodeScanning, + category, ); - core.setOutput("sarif-id", uploadResult.sarifID); + if (uploadResult !== undefined) { + core.setOutput("sarif-id", uploadResult.sarifID); + } // 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 @@ -172,15 +175,21 @@ async function run() { if (isInTestMode()) { core.debug("In test mode. Waiting for processing is disabled."); } else if (actionsUtil.getRequiredInput("wait-for-processing") === "true") { - await upload_lib.waitForProcessing( - getRepositoryNwo(), - uploadResult.sarifID, - logger, - ); + if (uploadResult !== undefined) { + await upload_lib.waitForProcessing( + getRepositoryNwo(), + uploadResult.sarifID, + logger, + ); + } // The code quality service does not currently have an endpoint to wait for SARIF processing, // so we can't wait for that here. } - await sendSuccessStatusReport(startedAt, uploadResult.statusReport, logger); + await sendSuccessStatusReport( + startedAt, + uploadResult?.statusReport || {}, + logger, + ); } catch (unwrappedError) { const error = isThirdPartyAnalysis(ActionName.UploadSarif) &&