Always merge SARIF files in analyze action

This commit is contained in:
Koen Vlaswinkel
2024-03-22 16:32:47 +01:00
parent 84ba7fb56d
commit c39396ebb7
6 changed files with 49 additions and 7 deletions
+10
View File
@@ -183,6 +183,16 @@ async function run() {
}
else {
logger.info("Not uploading results");
// TODO: Do not merge this code
const sarifFiles = uploadLib.getSarifFilePaths(outputDir);
// Merge the SARIF files into a single file. This will tell us whether the
// merge works.
const sarif = (await features.getValue(feature_flags_1.Feature.CliSarifMerge))
? await uploadLib.combineSarifFilesUsingCLI(sarifFiles, gitHubVersion, features, logger)
: uploadLib.combineSarifFiles(sarifFiles);
// Write the combined SARIF file to disk
fs.writeFileSync(path_1.default.join(outputDir, "combined-sarif.sarif"), JSON.stringify(sarif, null, 2), "utf-8");
logger.info(`Combined SARIF file written to ${path_1.default.join(outputDir, "combined-sarif.sarif")} with ${sarif.runs.length} runs`);
}
// Possibly upload the database bundles for remote queries
await (0, database_upload_1.uploadDatabases)(repositoryNwo, config, apiDetails, logger);
File diff suppressed because one or more lines are too long
+4 -1
View File
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InvalidSarifUploadError = exports.validateUniqueCategory = exports.waitForProcessing = exports.buildPayload = exports.validateSarifFileSchema = exports.uploadFromActions = exports.findSarifFilesInDir = exports.populateRunAutomationDetails = void 0;
exports.InvalidSarifUploadError = exports.validateUniqueCategory = exports.waitForProcessing = exports.buildPayload = exports.validateSarifFileSchema = exports.getSarifFilePaths = exports.uploadFromActions = exports.findSarifFilesInDir = exports.populateRunAutomationDetails = exports.combineSarifFilesUsingCLI = exports.combineSarifFiles = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const zlib_1 = __importDefault(require("zlib"));
@@ -69,6 +69,7 @@ function combineSarifFiles(sarifFiles) {
}
return combinedSarif;
}
exports.combineSarifFiles = combineSarifFiles;
/**
* Checks whether all the runs in the given SARIF files were produced by CodeQL.
* @param sarifFiles The list of SARIF files to check.
@@ -127,6 +128,7 @@ async function combineSarifFilesUsingCLI(sarifFiles, gitHubVersion, features, lo
});
return JSON.parse(fs.readFileSync(outputFile, "utf8"));
}
exports.combineSarifFilesUsingCLI = combineSarifFilesUsingCLI;
// Populates the run.automationDetails.id field using the analysis_key and environment
// and return an updated sarif file contents.
function populateRunAutomationDetails(sarif, category, analysis_key, environment) {
@@ -237,6 +239,7 @@ function getSarifFilePaths(sarifPath) {
}
return sarifFiles;
}
exports.getSarifFilePaths = getSarifFilePaths;
// Counts the number of results in the given SARIF file
function countResultsInSarif(sarif) {
let numResults = 0;
File diff suppressed because one or more lines are too long