-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcodeql-version.ts
More file actions
51 lines (44 loc) · 1.45 KB
/
codeql-version.ts
File metadata and controls
51 lines (44 loc) · 1.45 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
import { debug, warning } from "@actions/core";
import { valid } from "semver";
const DEFAULT_VERSION_FEATURE_FLAG_PREFIX = "default_codeql_version_";
const DEFAULT_VERSION_FEATURE_FLAG_SUFFIX = "_enabled";
function getCliVersionFromFeatureFlag(f: string): string | undefined {
if (
!f.startsWith(DEFAULT_VERSION_FEATURE_FLAG_PREFIX) ||
!f.endsWith(DEFAULT_VERSION_FEATURE_FLAG_SUFFIX)
) {
return undefined;
}
const version = f
.substring(
DEFAULT_VERSION_FEATURE_FLAG_PREFIX.length,
f.length - DEFAULT_VERSION_FEATURE_FLAG_SUFFIX.length,
)
.replace(/_/g, ".");
if (!valid(version)) {
warning(
`Ignoring feature flag ${f} as it does not specify a valid CodeQL version.`,
);
return undefined;
}
return version;
}
export function getDefaultCliVersion(
features: Record<string, boolean>,
): string | undefined {
const enabledFeatureFlagCliVersions = Object.entries(features)
.map(([f, isEnabled]) =>
isEnabled ? getCliVersionFromFeatureFlag(f) : undefined,
)
.filter((f): f is string => f !== undefined);
if (enabledFeatureFlagCliVersions.length === 0) {
return undefined;
}
const maxCliVersion = enabledFeatureFlagCliVersions.reduce(
(maxVersion, currentVersion) =>
currentVersion > maxVersion ? currentVersion : maxVersion,
enabledFeatureFlagCliVersions[0],
);
debug(`Derived default CLI version of ${maxCliVersion} from feature flags.`);
return maxCliVersion;
}