Skip to content

Commit

Permalink
Add logging for CodeQL CLI Version and add tests to the logger for it.
Browse files Browse the repository at this point in the history
  • Loading branch information
NlightNFotis committed May 9, 2024
1 parent 80f8aff commit 67b9169
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/setup-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/setup-codeql.js.map

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions lib/setup-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/setup-codeql.test.js.map

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

17 changes: 16 additions & 1 deletion src/setup-codeql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getRunnerLogger } from "./logging";
import * as setupCodeql from "./setup-codeql";
import {
LINKED_CLI_VERSION,
LoggedMessage,
SAMPLE_DEFAULT_CLI_VERSION,
SAMPLE_DOTCOM_API_DETAILS,
getRecordingLogger,
Expand Down Expand Up @@ -97,7 +98,7 @@ test("getCodeQLSource sets CLI version for a semver tagged bundle", async (t) =>
});

test("getCodeQLSource correctly returns bundled CLI version when tools == linked", async (t) => {
const loggedMessages = [];
const loggedMessages: LoggedMessage[] = [];
const logger = getRecordingLogger(loggedMessages);

await withTmpDir(async (tmpDir) => {
Expand All @@ -110,8 +111,22 @@ test("getCodeQLSource correctly returns bundled CLI version when tools == linked
logger,
);

// Assert first that we got the right version of the CodeQL CLI,
// and that we're sourcing it using the correct method for that.
t.is(source.toolsVersion, LINKED_CLI_VERSION.cliVersion);
t.is(source.sourceType, "download");

// Ensure that we're adequately notifying the user of the version we're using.
const expected_message: LoggedMessage = {
type: "info",
message: `Using CodeQL CLI version: ${LINKED_CLI_VERSION.cliVersion} from download.`,
};

loggedMessages.forEach((msg) => {
console.log(msg.message);
});

t.assert(loggedMessages.includes(expected_message));
});
});

Expand Down
2 changes: 2 additions & 0 deletions src/setup-codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ export async function setupCodeQLBundle(
logger,
);

logger.info("Using CodeQL CLI version " + source.toolsVersion + " from " + source.sourceType + ".");

let codeqlFolder: string;
let toolsVersion = source.toolsVersion;
let toolsDownloadDurationMs: number | undefined;
Expand Down

0 comments on commit 67b9169

Please sign in to comment.