-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathcli-version.ts
More file actions
57 lines (51 loc) · 1.43 KB
/
cli-version.ts
File metadata and controls
57 lines (51 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import type { SemVer } from "semver";
import { parse } from "semver";
import { runJsonCodeQlCliCommand } from "./cli-command";
import type { Logger } from "../common/logging";
import { getErrorMessage } from "../common/helpers-pure";
interface VersionResult {
version: string;
features: CliFeatures | undefined;
}
export interface CliFeatures {
featuresInVersionResult?: boolean;
mrvaPackCreate?: boolean;
generateSummarySymbolMap?: boolean;
queryServerRunQueries?: boolean;
}
export interface VersionAndFeatures {
version: SemVer;
features: CliFeatures;
}
/**
* Get the version of a CodeQL CLI.
*/
export async function getCodeQlCliVersion(
codeQlPath: string,
logger: Logger,
): Promise<VersionAndFeatures | undefined> {
try {
const output: VersionResult = await runJsonCodeQlCliCommand<VersionResult>(
codeQlPath,
["version"],
["--format=json"],
"Checking CodeQL version",
logger,
);
const version = parse(output.version.trim()) || undefined;
if (version === undefined) {
return undefined;
}
return {
version,
features: output.features ?? {},
};
} catch (e) {
// Failed to run the version command. This might happen if the cli version is _really_ old, or it is corrupted.
// Either way, we can't determine compatibility.
void logger.log(
`Failed to run 'codeql version'. Reason: ${getErrorMessage(e)}`,
);
return undefined;
}
}