Skip to content

Commit 9310334

Browse files
authored
Merge pull request #4086 from github/mbg/thread-action-state-to-codeql
Make a `Logger` available to `getCodeQLForCmd`
2 parents 1f87aed + 38055a3 commit 9310334

13 files changed

Lines changed: 38 additions & 44 deletions

lib/entry-points.js

Lines changed: 20 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analyze-action-post.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export async function runWrapper() {
3838
logger,
3939
);
4040
if (config !== undefined) {
41-
const codeql = await getCodeQL(config.codeQLCmd);
41+
const codeql = await getCodeQL(logger, config.codeQLCmd);
4242
const version = await codeql.getVersion();
4343
await debugArtifacts.uploadCombinedSarifArtifacts(
4444
logger,

src/analyze-action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ async function run({ startedAt, logger }: ActionState<["Base", "Logger"]>) {
255255
);
256256
}
257257

258-
const codeql = await getCodeQL(config.codeQLCmd);
258+
const codeql = await getCodeQL(logger, config.codeQLCmd);
259259

260260
if (hasBadExpectErrorInput()) {
261261
throw new util.ConfigurationError(

src/autobuild-action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async function run({ startedAt, logger }: ActionState<["Base", "Logger"]>) {
9999
);
100100
}
101101

102-
const codeql = await getCodeQL(config.codeQLCmd);
102+
const codeql = await getCodeQL(logger, config.codeQLCmd);
103103

104104
languages = await determineAutobuildLanguages(codeql, config, logger);
105105
if (languages !== undefined) {

src/autobuild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export async function runAutobuild(
155155
logger: Logger,
156156
) {
157157
logger.startGroup(`Attempting to automatically build ${language} code`);
158-
const codeQL = await getCodeQL(config.codeQLCmd);
158+
const codeQL = await getCodeQL(logger, config.codeQLCmd);
159159
if (language === BuiltInLanguage.cpp) {
160160
await setupCppAutobuild(codeQL, logger);
161161
}

src/codeql.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,6 @@ const injectedConfigMacro = makeMacro({
580580
"",
581581
undefined,
582582
undefined,
583-
getRunnerLogger(true),
584583
);
585584

586585
const args = runnerConstructorStub.firstCall.args[1] as string[];
@@ -856,7 +855,6 @@ test.serial(
856855
"",
857856
undefined,
858857
"/path/to/qlconfig.yml",
859-
getRunnerLogger(true),
860858
);
861859

862860
const args = runnerConstructorStub.firstCall.args[1] as string[];
@@ -887,7 +885,6 @@ test.serial(
887885
"",
888886
undefined,
889887
undefined, // undefined qlconfigFile
890-
getRunnerLogger(true),
891888
);
892889

893890
const args = runnerConstructorStub.firstCall.args[1] as any[];
@@ -1066,7 +1063,6 @@ test.serial(
10661063
"sourceRoot",
10671064
undefined,
10681065
undefined,
1069-
getRunnerLogger(false),
10701066
);
10711067

10721068
t.true(runnerConstructorStub.calledOnce);

src/codeql.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from "./feature-flags";
2424
import { isAnalyzingDefaultBranch } from "./git-utils";
2525
import { Language } from "./languages";
26-
import { Logger } from "./logging";
26+
import { getRunnerLogger, Logger } from "./logging";
2727
import { writeBaseDatabaseOidsFile, writeOverlayChangesFile } from "./overlay";
2828
import { OverlayDatabaseMode } from "./overlay/overlay-database-mode";
2929
import * as setupCodeql from "./setup-codeql";
@@ -91,7 +91,6 @@ export interface CodeQL {
9191
sourceRoot: string,
9292
processName: string | undefined,
9393
qlconfigFile: string | undefined,
94-
logger: Logger,
9594
): Promise<void>;
9695
/**
9796
* Runs the autobuilder for the given language.
@@ -346,7 +345,7 @@ export async function setupCodeQL(
346345
);
347346
}
348347

349-
cachedCodeQL = await getCodeQLForCmd(codeqlCmd, checkVersion);
348+
cachedCodeQL = await getCodeQLForCmd(logger, codeqlCmd, checkVersion);
350349
return {
351350
codeql: cachedCodeQL,
352351
toolsDownloadStatusReport,
@@ -372,9 +371,9 @@ export async function setupCodeQL(
372371
/**
373372
* Use the CodeQL executable located at the given path.
374373
*/
375-
export async function getCodeQL(cmd: string): Promise<CodeQL> {
374+
export async function getCodeQL(logger: Logger, cmd: string): Promise<CodeQL> {
376375
if (cachedCodeQL === undefined) {
377-
cachedCodeQL = await getCodeQLForCmd(cmd, true);
376+
cachedCodeQL = await getCodeQLForCmd(logger, cmd, true);
378377
}
379378
return cachedCodeQL;
380379
}
@@ -481,8 +480,9 @@ export function createStubCodeQL(partialCodeql: Partial<CodeQL>): CodeQL {
481480
*/
482481
export async function getCodeQLForTesting(
483482
cmd = "codeql-for-testing",
483+
logger: Logger = getRunnerLogger(true),
484484
): Promise<CodeQL> {
485-
return getCodeQLForCmd(cmd, false);
485+
return getCodeQLForCmd(logger, cmd, false);
486486
}
487487

488488
/**
@@ -494,6 +494,7 @@ export async function getCodeQLForTesting(
494494
* @returns A new CodeQL object
495495
*/
496496
async function getCodeQLForCmd(
497+
logger: Logger,
497498
cmd: string,
498499
checkVersion: boolean,
499500
): Promise<CodeQL> {
@@ -539,7 +540,6 @@ async function getCodeQLForCmd(
539540
sourceRoot: string,
540541
processName: string | undefined,
541542
qlconfigFile: string | undefined,
542-
logger: Logger,
543543
) {
544544
const extraArgs = config.languages.map(
545545
(language) => `--language=${language}`,

src/init-action-post-helper.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ async function prepareFailedSarif(
123123
const category = `/language:${language}`;
124124
const checkoutPath = ".";
125125
const result = await generateFailedSarif(
126+
logger,
126127
features,
127128
config,
128129
category,
@@ -146,6 +147,7 @@ async function prepareFailedSarif(
146147
const checkoutPath = getCheckoutPathInputOrThrow(workflow, jobName, matrix);
147148

148149
const result = await generateFailedSarif(
150+
logger,
149151
features,
150152
config,
151153
category,
@@ -156,14 +158,15 @@ async function prepareFailedSarif(
156158
}
157159

158160
async function generateFailedSarif(
161+
logger: Logger,
159162
features: FeatureEnablement,
160163
config: Config,
161164
category: string | undefined,
162165
checkoutPath: string,
163166
sarifFile?: string,
164167
) {
165168
const databasePath = config.dbLocation;
166-
const codeql = await getCodeQL(config.codeQLCmd);
169+
const codeql = await getCodeQL(logger, config.codeQLCmd);
167170

168171
// Set the filename for the SARIF file if not already set.
169172
if (sarifFile === undefined) {

src/init-action-post.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async function run(startedAt: Date) {
7575
"Debugging artifacts are unavailable since the 'init' Action failed before it could produce any.",
7676
);
7777
} else {
78-
const codeql = await getCodeQL(config.codeQLCmd);
78+
const codeql = await getCodeQL(logger, config.codeQLCmd);
7979

8080
uploadFailedSarifResult = await initActionPostHelper.uploadFailureInfo(
8181
debugArtifacts.tryUploadAllAvailableDebugArtifacts,

src/init-action.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,6 @@ async function run(
689689
sourceRoot,
690690
"Runner.Worker.exe",
691691
qlconfigFile,
692-
logger,
693692
);
694693

695694
// To check custom query packs for compatibility with overlay analysis, we
@@ -718,7 +717,6 @@ async function run(
718717
sourceRoot,
719718
"Runner.Worker.exe",
720719
qlconfigFile,
721-
logger,
722720
);
723721
}
724722

0 commit comments

Comments
 (0)