Merge pull request #1811 from github/henrymercer/print-summary-once

Only print the analysis summary once
This commit is contained in:
Henry Mercer 2023-07-28 14:23:58 +01:00 committed by GitHub
commit 10c6bfee12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 10 deletions

View file

@ -5,6 +5,7 @@ See the [releases page](https://github.com/github/codeql-action/releases) for th
## [UNRELEASED] ## [UNRELEASED]
- Update default CodeQL bundle version to 2.14.1. [#1797](https://github.com/github/codeql-action/pull/1797) - Update default CodeQL bundle version to 2.14.1. [#1797](https://github.com/github/codeql-action/pull/1797)
- Avoid duplicating the analysis summary within the logs. [#1811](https://github.com/github/codeql-action/pull/1811)
## 2.21.1 - 26 Jul 2023 ## 2.21.1 - 26 Jul 2023

17
lib/codeql.js generated
View file

@ -485,12 +485,15 @@ async function getCodeQLForCmd(cmd, checkVersion) {
if (querySuitePaths) { if (querySuitePaths) {
codeqlArgs.push(...querySuitePaths); codeqlArgs.push(...querySuitePaths);
} }
// capture stdout, which contains analysis summaries // Capture the stdout, which contains the analysis summary. Don't stream it to the Actions
const returnState = await runTool(cmd, codeqlArgs); // logs to avoid printing it twice.
const analysisSummary = await runTool(cmd, codeqlArgs, {
noStreamStdout: true,
});
if (shouldWorkaroundInvalidNotifications) { if (shouldWorkaroundInvalidNotifications) {
util.fixInvalidNotificationsInFile(codeqlOutputFile, sarifFile, logger); util.fixInvalidNotificationsInFile(codeqlOutputFile, sarifFile, logger);
} }
return returnState; return analysisSummary;
}, },
async databasePrintBaseline(databasePath) { async databasePrintBaseline(databasePath) {
const codeqlArgs = [ const codeqlArgs = [
@ -718,9 +721,13 @@ async function runTool(cmd, args = [], opts = {}) {
let output = ""; let output = "";
let error = ""; let error = "";
const exitCode = await new toolrunner.ToolRunner(cmd, args, { const exitCode = await new toolrunner.ToolRunner(cmd, args, {
ignoreReturnCode: true,
listeners: { listeners: {
stdout: (data) => { stdout: (data) => {
output += data.toString("utf8"); output += data.toString("utf8");
if (!opts.noStreamStdout) {
process.stdout.write(data);
}
}, },
stderr: (data) => { stderr: (data) => {
let readStartIndex = 0; let readStartIndex = 0;
@ -730,9 +737,11 @@ async function runTool(cmd, args = [], opts = {}) {
readStartIndex = data.length - maxErrorSize + 1; readStartIndex = data.length - maxErrorSize + 1;
} }
error += data.toString("utf8", readStartIndex); error += data.toString("utf8", readStartIndex);
// Mimic the standard behavior of the toolrunner by writing stderr to stdout
process.stdout.write(data);
}, },
}, },
ignoreReturnCode: true, silent: true,
...(opts.stdin ? { input: Buffer.from(opts.stdin || "") } : {}), ...(opts.stdin ? { input: Buffer.from(opts.stdin || "") } : {}),
}).exec(); }).exec();
if (exitCode !== 0) { if (exitCode !== 0) {

File diff suppressed because one or more lines are too long

View file

@ -843,14 +843,17 @@ export async function getCodeQLForCmd(
if (querySuitePaths) { if (querySuitePaths) {
codeqlArgs.push(...querySuitePaths); codeqlArgs.push(...querySuitePaths);
} }
// capture stdout, which contains analysis summaries // Capture the stdout, which contains the analysis summary. Don't stream it to the Actions
const returnState = await runTool(cmd, codeqlArgs); // logs to avoid printing it twice.
const analysisSummary = await runTool(cmd, codeqlArgs, {
noStreamStdout: true,
});
if (shouldWorkaroundInvalidNotifications) { if (shouldWorkaroundInvalidNotifications) {
util.fixInvalidNotificationsInFile(codeqlOutputFile, sarifFile, logger); util.fixInvalidNotificationsInFile(codeqlOutputFile, sarifFile, logger);
} }
return returnState; return analysisSummary;
}, },
async databasePrintBaseline(databasePath: string): Promise<string> { async databasePrintBaseline(databasePath: string): Promise<string> {
const codeqlArgs = [ const codeqlArgs = [
@ -1131,14 +1134,18 @@ const maxErrorSize = 20_000;
async function runTool( async function runTool(
cmd: string, cmd: string,
args: string[] = [], args: string[] = [],
opts: { stdin?: string } = {}, opts: { stdin?: string; noStreamStdout?: boolean } = {},
) { ) {
let output = ""; let output = "";
let error = ""; let error = "";
const exitCode = await new toolrunner.ToolRunner(cmd, args, { const exitCode = await new toolrunner.ToolRunner(cmd, args, {
ignoreReturnCode: true,
listeners: { listeners: {
stdout: (data: Buffer) => { stdout: (data: Buffer) => {
output += data.toString("utf8"); output += data.toString("utf8");
if (!opts.noStreamStdout) {
process.stdout.write(data);
}
}, },
stderr: (data: Buffer) => { stderr: (data: Buffer) => {
let readStartIndex = 0; let readStartIndex = 0;
@ -1148,9 +1155,11 @@ async function runTool(
readStartIndex = data.length - maxErrorSize + 1; readStartIndex = data.length - maxErrorSize + 1;
} }
error += data.toString("utf8", readStartIndex); error += data.toString("utf8", readStartIndex);
// Mimic the standard behavior of the toolrunner by writing stderr to stdout
process.stdout.write(data);
}, },
}, },
ignoreReturnCode: true, silent: true,
...(opts.stdin ? { input: Buffer.from(opts.stdin || "") } : {}), ...(opts.stdin ? { input: Buffer.from(opts.stdin || "") } : {}),
}).exec(); }).exec();
if (exitCode !== 0) { if (exitCode !== 0) {