Remove duplicate locations from failed run SARIF
This commit is contained in:
parent
ade432fd68
commit
c8935d5a9d
9 changed files with 40 additions and 12 deletions
|
|
@ -197,7 +197,9 @@ export interface CodeQL {
|
|||
databaseExportDiagnostics(
|
||||
databasePath: string,
|
||||
sarifFile: string,
|
||||
automationDetailsId: string | undefined
|
||||
automationDetailsId: string | undefined,
|
||||
tempDir: string,
|
||||
logger: Logger
|
||||
): Promise<void>;
|
||||
/**
|
||||
* Run 'codeql diagnostics export'.
|
||||
|
|
@ -1023,15 +1025,21 @@ export async function getCodeQLForCmd(
|
|||
async databaseExportDiagnostics(
|
||||
databasePath: string,
|
||||
sarifFile: string,
|
||||
automationDetailsId: string | undefined
|
||||
automationDetailsId: string | undefined,
|
||||
tempDir: string,
|
||||
logger: Logger
|
||||
): Promise<void> {
|
||||
const intermediateSarifFile = path.join(
|
||||
tempDir,
|
||||
"codeql-intermediate-results.sarif"
|
||||
);
|
||||
const args = [
|
||||
"database",
|
||||
"export-diagnostics",
|
||||
`${databasePath}`,
|
||||
"--db-cluster", // Database is always a cluster for CodeQL versions that support diagnostics.
|
||||
"--format=sarif-latest",
|
||||
`--output=${sarifFile}`,
|
||||
`--output=${intermediateSarifFile}`,
|
||||
"--sarif-include-diagnostics", // ExportDiagnosticsEnabled is always true if this command is run.
|
||||
"-vvv",
|
||||
...getExtraOptionsFromEnv(["diagnostics", "export"]),
|
||||
|
|
@ -1040,6 +1048,13 @@ export async function getCodeQLForCmd(
|
|||
args.push("--sarif-category", automationDetailsId);
|
||||
}
|
||||
await new toolrunner.ToolRunner(cmd, args).exec();
|
||||
|
||||
// Fix invalid notifications in the SARIF file output by CodeQL.
|
||||
let sarif = JSON.parse(
|
||||
fs.readFileSync(intermediateSarifFile, "utf8")
|
||||
) as util.SarifFile;
|
||||
sarif = util.fixInvalidNotifications(sarif, logger);
|
||||
fs.writeFileSync(sarifFile, JSON.stringify(sarif));
|
||||
},
|
||||
async diagnosticsExport(
|
||||
sarifFile: string,
|
||||
|
|
|
|||
|
|
@ -398,7 +398,9 @@ async function testFailedSarifUpload(
|
|||
databaseExportDiagnosticsStub.calledOnceWith(
|
||||
config.dbLocation,
|
||||
sinon.match.string,
|
||||
category
|
||||
category,
|
||||
sinon.match.any,
|
||||
sinon.match.any
|
||||
),
|
||||
`Actual args were: ${databaseExportDiagnosticsStub.args}`
|
||||
);
|
||||
|
|
|
|||
|
|
@ -79,7 +79,13 @@ async function maybeUploadFailedSarif(
|
|||
await codeql.diagnosticsExport(sarifFile, category, config, features);
|
||||
} else {
|
||||
// We call 'database export-diagnostics' to find any per-database diagnostics.
|
||||
await codeql.databaseExportDiagnostics(databasePath, sarifFile, category);
|
||||
await codeql.databaseExportDiagnostics(
|
||||
databasePath,
|
||||
sarifFile,
|
||||
category,
|
||||
config.tempDir,
|
||||
logger
|
||||
);
|
||||
}
|
||||
|
||||
core.info(`Uploading failed SARIF file ${sarifFile}`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue