Introduce areAllRunsProducedByCodeQL function
This commit is contained in:
parent
70aa50b057
commit
3bd271cec3
3 changed files with 36 additions and 28 deletions
26
lib/upload-lib.js
generated
26
lib/upload-lib.js
generated
|
|
@ -69,22 +69,26 @@ function combineSarifFiles(sarifFiles) {
|
||||||
}
|
}
|
||||||
return combinedSarif;
|
return combinedSarif;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Checks whether all the runs in the given SARIF files were produced by CodeQL.
|
||||||
|
* @param sarifFiles The list of SARIF files to check.
|
||||||
|
*/
|
||||||
|
function areAllRunsProducedByCodeQL(sarifFiles) {
|
||||||
|
for (const sarifFile of sarifFiles) {
|
||||||
|
const sarifObject = JSON.parse(fs.readFileSync(sarifFile, "utf8"));
|
||||||
|
const allRunsCodeQL = sarifObject.runs?.every((run) => run.tool?.driver?.name === "CodeQL");
|
||||||
|
if (!allRunsCodeQL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
// Takes a list of paths to sarif files and combines them together using the
|
// Takes a list of paths to sarif files and combines them together using the
|
||||||
// CLI `github merge-results` command when all SARIF files are produced by
|
// CLI `github merge-results` command when all SARIF files are produced by
|
||||||
// CodeQL. Otherwise, it will fall back to combining the files in the action.
|
// CodeQL. Otherwise, it will fall back to combining the files in the action.
|
||||||
// Returns the contents of the combined sarif file.
|
// Returns the contents of the combined sarif file.
|
||||||
async function combineSarifFilesUsingCLI(sarifFiles, gitHubVersion, features, logger) {
|
async function combineSarifFilesUsingCLI(sarifFiles, gitHubVersion, features, logger) {
|
||||||
// First check if all files are produced by CodeQL.
|
if (!areAllRunsProducedByCodeQL(sarifFiles)) {
|
||||||
let allCodeQL = true;
|
|
||||||
for (const sarifFile of sarifFiles) {
|
|
||||||
const sarifObject = JSON.parse(fs.readFileSync(sarifFile, "utf8"));
|
|
||||||
const allRunsCodeQL = sarifObject.runs?.every((run) => run.tool?.driver?.name === "CodeQL");
|
|
||||||
if (!allRunsCodeQL) {
|
|
||||||
allCodeQL = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!allCodeQL) {
|
|
||||||
logger.warning("Not all SARIF files were produced by CodeQL. Merging files in the action.");
|
logger.warning("Not all SARIF files were produced by CodeQL. Merging files in the action.");
|
||||||
// If not, use the naive method of combining the files.
|
// If not, use the naive method of combining the files.
|
||||||
return combineSarifFiles(sarifFiles);
|
return combineSarifFiles(sarifFiles);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -61,19 +61,11 @@ function combineSarifFiles(sarifFiles: string[]): SarifFile {
|
||||||
return combinedSarif;
|
return combinedSarif;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a list of paths to sarif files and combines them together using the
|
/**
|
||||||
// CLI `github merge-results` command when all SARIF files are produced by
|
* Checks whether all the runs in the given SARIF files were produced by CodeQL.
|
||||||
// CodeQL. Otherwise, it will fall back to combining the files in the action.
|
* @param sarifFiles The list of SARIF files to check.
|
||||||
// Returns the contents of the combined sarif file.
|
*/
|
||||||
async function combineSarifFilesUsingCLI(
|
function areAllRunsProducedByCodeQL(sarifFiles: string[]): boolean {
|
||||||
sarifFiles: string[],
|
|
||||||
gitHubVersion: GitHubVersion,
|
|
||||||
features: Features,
|
|
||||||
logger: Logger,
|
|
||||||
): Promise<SarifFile> {
|
|
||||||
// First check if all files are produced by CodeQL.
|
|
||||||
let allCodeQL = true;
|
|
||||||
|
|
||||||
for (const sarifFile of sarifFiles) {
|
for (const sarifFile of sarifFiles) {
|
||||||
const sarifObject = JSON.parse(
|
const sarifObject = JSON.parse(
|
||||||
fs.readFileSync(sarifFile, "utf8"),
|
fs.readFileSync(sarifFile, "utf8"),
|
||||||
|
|
@ -84,12 +76,24 @@ async function combineSarifFilesUsingCLI(
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!allRunsCodeQL) {
|
if (!allRunsCodeQL) {
|
||||||
allCodeQL = false;
|
return false;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!allCodeQL) {
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Takes a list of paths to sarif files and combines them together using the
|
||||||
|
// CLI `github merge-results` command when all SARIF files are produced by
|
||||||
|
// CodeQL. Otherwise, it will fall back to combining the files in the action.
|
||||||
|
// Returns the contents of the combined sarif file.
|
||||||
|
async function combineSarifFilesUsingCLI(
|
||||||
|
sarifFiles: string[],
|
||||||
|
gitHubVersion: GitHubVersion,
|
||||||
|
features: Features,
|
||||||
|
logger: Logger,
|
||||||
|
): Promise<SarifFile> {
|
||||||
|
if (!areAllRunsProducedByCodeQL(sarifFiles)) {
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Not all SARIF files were produced by CodeQL. Merging files in the action.",
|
"Not all SARIF files were produced by CodeQL. Merging files in the action.",
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue