Skip to content

Commit

Permalink
Merge pull request #1133 from github/henrymercer/log-diagnostics-when…
Browse files Browse the repository at this point in the history
…-debug-enabled

Print diagnostic messages when debugging mode is enabled
  • Loading branch information
henrymercer authored Jul 12, 2022
2 parents b7da732 + 3a5fa35 commit b380175
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [UNRELEASED]

- You can now quickly debug a job that uses the CodeQL Action by re-running the job from the GitHub UI and selecting the "Enable debug logging" option. [#1132](https://github.com/github/codeql-action/pull/1132)
- You can now see diagnostic messages produced by the analysis in the logs of the `analyze` Action by enabling debug mode. To enable debug mode, pass `debug: true` to the `init` Action, or [enable step debug logging](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging#enabling-step-debug-logging). This feature is available for CodeQL CLI version 2.10.0 and later. [#1133](https://github.com/github/codeql-action/pull/1133)

## 2.1.15 - 28 Jun 2022

Expand Down
6 changes: 3 additions & 3 deletions lib/analyze.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analyze.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/codeql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codeql.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/codeql.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codeql.test.js.map

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ export async function runQueries(
const analysisSummary = await runInterpretResults(
language,
querySuitePaths,
sarifFile
sarifFile,
config.debugMode
);
if (!cliCanCountBaseline)
await injectLinesOfCode(sarifFile, language, locPromise);
Expand Down Expand Up @@ -337,7 +338,8 @@ export async function runQueries(
async function runInterpretResults(
language: Language,
queries: string[],
sarifFile: string
sarifFile: string,
enableDebugLogging: boolean
): Promise<string> {
const databasePath = util.getCodeQLDatabasePath(config, language);
const codeql = await getCodeQL(config.codeQLCmd);
Expand All @@ -347,6 +349,7 @@ export async function runQueries(
sarifFile,
addSnippetsFlag,
threadsFlag,
enableDebugLogging ? "-vv" : "-v",
automationDetailsId
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/codeql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ test("databaseInterpretResults() does not set --sarif-add-query-help for 2.7.0",
const runnerConstructorStub = stubToolRunnerConstructor();
const codeqlObject = await codeql.getCodeQLForTesting();
sinon.stub(codeqlObject, "getVersion").resolves("2.7.0");
await codeqlObject.databaseInterpretResults("", [], "", "", "", "");
await codeqlObject.databaseInterpretResults("", [], "", "", "", "-v", "");
t.false(
runnerConstructorStub.firstCall.args[1].includes("--sarif-add-query-help"),
"--sarif-add-query-help should be absent, but it is present"
Expand All @@ -421,7 +421,7 @@ test("databaseInterpretResults() sets --sarif-add-query-help for 2.7.1", async (
const runnerConstructorStub = stubToolRunnerConstructor();
const codeqlObject = await codeql.getCodeQLForTesting();
sinon.stub(codeqlObject, "getVersion").resolves("2.7.1");
await codeqlObject.databaseInterpretResults("", [], "", "", "", "");
await codeqlObject.databaseInterpretResults("", [], "", "", "", "-v", "");
t.true(
runnerConstructorStub.firstCall.args[1].includes("--sarif-add-query-help"),
"--sarif-add-query-help should be present, but it is absent"
Expand Down
4 changes: 3 additions & 1 deletion src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export interface CodeQL {
sarifFile: string,
addSnippetsFlag: string,
threadsFlag: string,
verbosityFlag: string | undefined,
automationDetailsId: string | undefined
): Promise<string>;
/**
Expand Down Expand Up @@ -942,14 +943,15 @@ async function getCodeQLForCmd(
sarifFile: string,
addSnippetsFlag: string,
threadsFlag: string,
verbosityFlag: string,
automationDetailsId: string | undefined
): Promise<string> {
const codeqlArgs = [
"database",
"interpret-results",
threadsFlag,
"--format=sarif-latest",
"-v",
verbosityFlag,
`--output=${sarifFile}`,
addSnippetsFlag,
...getExtraOptionsFromEnv(["database", "interpret-results"]),
Expand Down

0 comments on commit b380175

Please sign in to comment.