Skip to content

Commit

Permalink
Don't invoke CLI when command not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael B. Gale committed Jun 15, 2023
1 parent 899b5a2 commit 7a9f099
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 12 deletions.
6 changes: 5 additions & 1 deletion 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.

41 changes: 37 additions & 4 deletions lib/resolve-environment.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/resolve-environment.js.map

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

5 changes: 5 additions & 0 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ export const CODEQL_VERSION_SECURITY_EXPERIMENTAL_SUITE = "2.12.1";
*/
export const CODEQL_VERSION_INIT_WITH_QLCONFIG = "2.12.4";

/**
* Versions 2.13.4+ of the CodeQL CLI support the `resolve build-environment` command.
*/
export const CODEQL_VERSION_RESOLVE_ENVIRONMENT = "2.13.4";

/**
* Set up CodeQL CLI access.
*
Expand Down
28 changes: 23 additions & 5 deletions src/resolve-environment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getCodeQL } from "./codeql";
import { CODEQL_VERSION_RESOLVE_ENVIRONMENT, getCodeQL } from "./codeql";
import { Language } from "./languages";
import { Logger } from "./logging";
import * as util from "./util";

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

if (workingDir !== undefined) {
logger.info(`Using ${workingDir} as the working directory.`);
const codeql = await getCodeQL(cmd);
let result = {};

// If the CodeQL version in use does not support the `resolve build-environment`
// command, just return an empty configuration. Otherwise invoke the CLI.
if (
!(await util.codeQlVersionAbove(
codeql,
CODEQL_VERSION_RESOLVE_ENVIRONMENT
))
) {
logger.warning(
"Unsupported CodeQL CLI version for `resolve build-environment` command, " +
"returning an empty configuration."
);
} else {
if (workingDir !== undefined) {
logger.info(`Using ${workingDir} as the working directory.`);
}

result = await codeql.resolveBuildEnvironment(workingDir, language);
}

const codeql = await getCodeQL(cmd);
const result = await codeql.resolveBuildEnvironment(workingDir, language);
logger.endGroup();
return result;
}

0 comments on commit 7a9f099

Please sign in to comment.