Skip to content

Commit 9c72af5

Browse files
committed
Move codeQlVersionAtLeast out of util.ts and into CodeQL
1 parent 929f5c0 commit 9c72af5

6 files changed

Lines changed: 55 additions & 47 deletions

File tree

‎lib/entry-points.js‎

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

‎src/codeql.ts‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as path from "path";
44
import * as core from "@actions/core";
55
import * as toolrunner from "@actions/exec/lib/toolrunner";
66
import * as yaml from "js-yaml";
7+
import * as semver from "semver";
78

89
import {
910
CommandInvocationError,
@@ -73,6 +74,11 @@ export interface CodeQL {
7374
* Get a string containing the semver version of the CodeQL executable.
7475
*/
7576
getVersion(): Promise<VersionInfo>;
77+
/**
78+
* Determines whether the CLI installation represented by this {@link CodeQL} instance
79+
* has at least the {@link requiredVersion}.
80+
*/
81+
isVersionAtLeast(requiredVersion: string): Promise<boolean>;
7682
/**
7783
* Print version information about CodeQL.
7884
*/
@@ -414,6 +420,19 @@ export function createStubCodeQL(partialCodeql: Partial<CodeQL>): CodeQL {
414420
getVersion: resolveFunction(partialCodeql, "getVersion", async () => ({
415421
version: "1.0.0",
416422
})),
423+
isVersionAtLeast: resolveFunction(
424+
partialCodeql,
425+
"codeQlVersionAtLeast",
426+
async (requiredVersion) => {
427+
return (
428+
!!partialCodeql.getVersion &&
429+
semver.gte(
430+
(await partialCodeql.getVersion()).version,
431+
requiredVersion,
432+
)
433+
);
434+
},
435+
),
417436
printVersion: resolveFunction(partialCodeql, "printVersion"),
418437
supportsFeature: resolveFunction(
419438
partialCodeql,
@@ -517,6 +536,9 @@ async function getCodeQLForCmd(
517536
}
518537
return result;
519538
},
539+
async isVersionAtLeast(requiredVersion: string) {
540+
return semver.gte((await this.getVersion()).version, requiredVersion);
541+
},
520542
async printVersion() {
521543
// Reuse the cached version information rather than invoking the CLI again.
522544
core.info(JSON.stringify(await this.getVersion(), null, 2));
@@ -1011,7 +1033,7 @@ async function getCodeQLForCmd(
10111033
// CodeQL object is created.
10121034
if (
10131035
checkVersion &&
1014-
!(await util.codeQlVersionAtLeast(codeql, CODEQL_MINIMUM_VERSION))
1036+
!(await codeql.isVersionAtLeast(CODEQL_MINIMUM_VERSION))
10151037
) {
10161038
throw new util.ConfigurationError(
10171039
`Expected a CodeQL CLI with version at least ${CODEQL_MINIMUM_VERSION} but got version ${
@@ -1021,7 +1043,7 @@ async function getCodeQLForCmd(
10211043
} else if (
10221044
checkVersion &&
10231045
process.env[EnvVar.SUPPRESS_DEPRECATED_SOON_WARNING] !== "true" &&
1024-
!(await util.codeQlVersionAtLeast(codeql, CODEQL_NEXT_MINIMUM_VERSION))
1046+
!(await codeql.isVersionAtLeast(CODEQL_NEXT_MINIMUM_VERSION))
10251047
) {
10261048
const result = await codeql.getVersion();
10271049
core.warning(

‎src/config-utils.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ import {
8282
GitHubVersion,
8383
ConfigurationError,
8484
BuildMode,
85-
codeQlVersionAtLeast,
8685
cloneObject,
8786
isDefined,
8887
checkDiskUsage,
@@ -652,10 +651,7 @@ async function runnerHasSufficientMemory(
652651
logger: Logger,
653652
): Promise<boolean> {
654653
if (
655-
await codeQlVersionAtLeast(
656-
codeql,
657-
CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE,
658-
)
654+
await codeql.isVersionAtLeast(CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE)
659655
) {
660656
logger.debug(
661657
`Skipping memory check for overlay analysis because CodeQL version is at least ${CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE}.`,
@@ -899,7 +895,7 @@ async function validateOverlayDatabaseMode(
899895
);
900896
return new Failure(OverlayDisabledReason.IncompatibleBuildMode);
901897
}
902-
if (!(await codeQlVersionAtLeast(codeql, CODEQL_OVERLAY_MINIMUM_VERSION))) {
898+
if (!(await codeql.isVersionAtLeast(CODEQL_OVERLAY_MINIMUM_VERSION))) {
903899
logger.warning(
904900
`Cannot build an ${overlayDatabaseMode} database because ` +
905901
`the CodeQL CLI is older than ${CODEQL_OVERLAY_MINIMUM_VERSION}. ` +

‎src/feature-flags.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ class OfflineFeatures implements FeatureEnablement {
589589
// Never use this feature if the CLI version explicitly can't support it.
590590
const minimumVersion = config.minimumVersion;
591591
if (codeql && minimumVersion) {
592-
if (!(await util.codeQlVersionAtLeast(codeql, minimumVersion))) {
592+
if (!(await codeql.isVersionAtLeast(minimumVersion))) {
593593
this.logger.debug(
594594
`Feature ${feature} is disabled because the CodeQL CLI version is older than the minimum ` +
595595
`version ${minimumVersion}.`,

‎src/init-action.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ import {
8888
checkDiskUsage,
8989
checkForTimeout,
9090
checkGitHubVersionInRange,
91-
codeQlVersionAtLeast,
9291
DEFAULT_DEBUG_ARTIFACT_NAME,
9392
DEFAULT_DEBUG_DATABASE_NAME,
9493
getCodeQLMemoryLimit,
@@ -686,7 +685,7 @@ async function run(
686685
`${EnvVar.JAVA_EXTRACTOR_MINIMIZE_DEPENDENCY_JARS} is already set to '${process.env[EnvVar.JAVA_EXTRACTOR_MINIMIZE_DEPENDENCY_JARS]}', so the Action will not override it.`,
687686
);
688687
} else if (
689-
(await codeQlVersionAtLeast(codeql, CODEQL_VERSION_JAR_MINIMIZATION)) &&
688+
(await codeql.isVersionAtLeast(CODEQL_VERSION_JAR_MINIMIZATION)) &&
690689
config.dependencyCachingEnabled &&
691690
config.buildMode === BuildMode.None &&
692691
config.languages.includes(BuiltInLanguage.java)

‎src/util.ts‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -565,13 +565,6 @@ export function initializeEnvironment(version: string, env: Env = getEnv()) {
565565
env.export(EnvVar.VERSION, version);
566566
}
567567

568-
export async function codeQlVersionAtLeast(
569-
codeql: CodeQL,
570-
requiredVersion: string,
571-
): Promise<boolean> {
572-
return semver.gte((await codeql.getVersion()).version, requiredVersion);
573-
}
574-
575568
export function getBaseDatabaseOidsFilePath(
576569
config: ActionConfig<"dbLocation">,
577570
): string {

0 commit comments

Comments
 (0)