Skip to content

Commit 7a9f099

Browse files
committed
Don't invoke CLI when command not supported
1 parent 899b5a2 commit 7a9f099

File tree

6 files changed

+72
-12
lines changed

6 files changed

+72
-12
lines changed

lib/codeql.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/resolve-environment.js

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

lib/resolve-environment.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/codeql.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ export const CODEQL_VERSION_SECURITY_EXPERIMENTAL_SUITE = "2.12.1";
304304
*/
305305
export const CODEQL_VERSION_INIT_WITH_QLCONFIG = "2.12.4";
306306

307+
/**
308+
* Versions 2.13.4+ of the CodeQL CLI support the `resolve build-environment` command.
309+
*/
310+
export const CODEQL_VERSION_RESOLVE_ENVIRONMENT = "2.13.4";
311+
307312
/**
308313
* Set up CodeQL CLI access.
309314
*

src/resolve-environment.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { getCodeQL } from "./codeql";
1+
import { CODEQL_VERSION_RESOLVE_ENVIRONMENT, getCodeQL } from "./codeql";
22
import { Language } from "./languages";
33
import { Logger } from "./logging";
4+
import * as util from "./util";
45

56
export async function runResolveBuildEnvironment(
67
cmd: string,
@@ -10,12 +11,29 @@ export async function runResolveBuildEnvironment(
1011
) {
1112
logger.startGroup(`Attempting to resolve build environment for ${language}`);
1213

13-
if (workingDir !== undefined) {
14-
logger.info(`Using ${workingDir} as the working directory.`);
14+
const codeql = await getCodeQL(cmd);
15+
let result = {};
16+
17+
// If the CodeQL version in use does not support the `resolve build-environment`
18+
// command, just return an empty configuration. Otherwise invoke the CLI.
19+
if (
20+
!(await util.codeQlVersionAbove(
21+
codeql,
22+
CODEQL_VERSION_RESOLVE_ENVIRONMENT
23+
))
24+
) {
25+
logger.warning(
26+
"Unsupported CodeQL CLI version for `resolve build-environment` command, " +
27+
"returning an empty configuration."
28+
);
29+
} else {
30+
if (workingDir !== undefined) {
31+
logger.info(`Using ${workingDir} as the working directory.`);
32+
}
33+
34+
result = await codeql.resolveBuildEnvironment(workingDir, language);
1535
}
1636

17-
const codeql = await getCodeQL(cmd);
18-
const result = await codeql.resolveBuildEnvironment(workingDir, language);
1937
logger.endGroup();
2038
return result;
2139
}

0 commit comments

Comments
 (0)