Skip to content

Commit c8935d5

Browse files
committed
Remove duplicate locations from failed run SARIF
1 parent ade432f commit c8935d5

9 files changed

+40
-12
lines changed

lib/codeql.js

+7-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action-post-helper.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action-post-helper.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action-post-helper.test.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action-post-helper.test.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/codeql.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ export interface CodeQL {
197197
databaseExportDiagnostics(
198198
databasePath: string,
199199
sarifFile: string,
200-
automationDetailsId: string | undefined
200+
automationDetailsId: string | undefined,
201+
tempDir: string,
202+
logger: Logger
201203
): Promise<void>;
202204
/**
203205
* Run 'codeql diagnostics export'.
@@ -1023,15 +1025,21 @@ export async function getCodeQLForCmd(
10231025
async databaseExportDiagnostics(
10241026
databasePath: string,
10251027
sarifFile: string,
1026-
automationDetailsId: string | undefined
1028+
automationDetailsId: string | undefined,
1029+
tempDir: string,
1030+
logger: Logger
10271031
): Promise<void> {
1032+
const intermediateSarifFile = path.join(
1033+
tempDir,
1034+
"codeql-intermediate-results.sarif"
1035+
);
10281036
const args = [
10291037
"database",
10301038
"export-diagnostics",
10311039
`${databasePath}`,
10321040
"--db-cluster", // Database is always a cluster for CodeQL versions that support diagnostics.
10331041
"--format=sarif-latest",
1034-
`--output=${sarifFile}`,
1042+
`--output=${intermediateSarifFile}`,
10351043
"--sarif-include-diagnostics", // ExportDiagnosticsEnabled is always true if this command is run.
10361044
"-vvv",
10371045
...getExtraOptionsFromEnv(["diagnostics", "export"]),
@@ -1040,6 +1048,13 @@ export async function getCodeQLForCmd(
10401048
args.push("--sarif-category", automationDetailsId);
10411049
}
10421050
await new toolrunner.ToolRunner(cmd, args).exec();
1051+
1052+
// Fix invalid notifications in the SARIF file output by CodeQL.
1053+
let sarif = JSON.parse(
1054+
fs.readFileSync(intermediateSarifFile, "utf8")
1055+
) as util.SarifFile;
1056+
sarif = util.fixInvalidNotifications(sarif, logger);
1057+
fs.writeFileSync(sarifFile, JSON.stringify(sarif));
10431058
},
10441059
async diagnosticsExport(
10451060
sarifFile: string,

src/init-action-post-helper.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,9 @@ async function testFailedSarifUpload(
398398
databaseExportDiagnosticsStub.calledOnceWith(
399399
config.dbLocation,
400400
sinon.match.string,
401-
category
401+
category,
402+
sinon.match.any,
403+
sinon.match.any
402404
),
403405
`Actual args were: ${databaseExportDiagnosticsStub.args}`
404406
);

src/init-action-post-helper.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ async function maybeUploadFailedSarif(
7979
await codeql.diagnosticsExport(sarifFile, category, config, features);
8080
} else {
8181
// We call 'database export-diagnostics' to find any per-database diagnostics.
82-
await codeql.databaseExportDiagnostics(databasePath, sarifFile, category);
82+
await codeql.databaseExportDiagnostics(
83+
databasePath,
84+
sarifFile,
85+
category,
86+
config.tempDir,
87+
logger
88+
);
8389
}
8490

8591
core.info(`Uploading failed SARIF file ${sarifFile}`);

0 commit comments

Comments
 (0)