diff --git a/lib/analyze-action.js b/lib/analyze-action.js index db46ee6f6..d4e65e8cc 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -95738,6 +95738,23 @@ function findSarifFilesInDir(sarifPath, isSarif) { walkSarifFiles(sarifPath); return sarifFiles; } +function getSarifFilePaths(sarifPath, isSarif) { + if (!fs18.existsSync(sarifPath)) { + throw new ConfigurationError(`Path does not exist: ${sarifPath}`); + } + let sarifFiles; + if (fs18.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; +} async function getGroupedSarifFilePaths(logger, sarifPath) { const stats = fs18.statSync(sarifPath, { throwIfNoEntry: false }); if (stats === void 0) { @@ -95881,6 +95898,20 @@ 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)}`); @@ -96349,13 +96380,37 @@ async function run() { if (runStats && getUploadValue(uploadInput) === "always") { const checkoutPath = getRequiredInput("checkout_path"); const category = getOptionalInput("category"); - uploadResults = await uploadSarif( - logger, - features, - checkoutPath, - outputDir, - category - ); + if (await features.getValue("analyze_use_new_upload" /* AnalyzeUseNewUpload */)) { + uploadResults = await uploadSarif( + logger, + features, + checkoutPath, + outputDir, + category + ); + } else { + uploadResults = {}; + if (isCodeScanningEnabled(config)) { + uploadResults["code-scanning" /* CodeScanning */] = await uploadFiles( + outputDir, + getRequiredInput("checkout_path"), + getOptionalInput("category"), + features, + logger, + CodeScanning + ); + } + if (isCodeQualityEnabled(config)) { + uploadResults["code-quality" /* CodeQuality */] = await uploadFiles( + outputDir, + getRequiredInput("checkout_path"), + getOptionalInput("category"), + features, + logger, + CodeQuality + ); + } + } core14.setOutput( "sarif-id", uploadResults["code-scanning" /* CodeScanning */]?.sarifID diff --git a/src/analyze-action.ts b/src/analyze-action.ts index fa2f64fd7..4c919f4d5 100644 --- a/src/analyze-action.ts +++ b/src/analyze-action.ts @@ -19,7 +19,12 @@ import { getApiDetails, getGitHubVersion } from "./api-client"; import { runAutobuild } from "./autobuild"; import { getTotalCacheSize, shouldStoreCache } from "./caching-utils"; import { getCodeQL } from "./codeql"; -import { Config, getConfig } from "./config-utils"; +import { + Config, + getConfig, + isCodeQualityEnabled, + isCodeScanningEnabled, +} from "./config-utils"; import { uploadDatabases } from "./database-upload"; import { DependencyCacheUploadStatusReport, @@ -344,13 +349,41 @@ async function run() { const checkoutPath = actionsUtil.getRequiredInput("checkout_path"); const category = actionsUtil.getOptionalInput("category"); - uploadResults = await uploadSarif( - logger, - features, - checkoutPath, - outputDir, - category, - ); + if (await features.getValue(Feature.AnalyzeUseNewUpload)) { + uploadResults = await uploadSarif( + logger, + features, + checkoutPath, + outputDir, + category, + ); + } else { + uploadResults = {}; + + if (isCodeScanningEnabled(config)) { + uploadResults[analyses.AnalysisKind.CodeScanning] = + await uploadLib.uploadFiles( + outputDir, + actionsUtil.getRequiredInput("checkout_path"), + actionsUtil.getOptionalInput("category"), + features, + logger, + analyses.CodeScanning, + ); + } + + if (isCodeQualityEnabled(config)) { + uploadResults[analyses.AnalysisKind.CodeQuality] = + await uploadLib.uploadFiles( + outputDir, + actionsUtil.getRequiredInput("checkout_path"), + actionsUtil.getOptionalInput("category"), + features, + logger, + analyses.CodeQuality, + ); + } + } core.setOutput( "sarif-id",