diff --git a/lib/entry-points.js b/lib/entry-points.js index 7fdec233b..f5cb6b25c 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -34719,7 +34719,7 @@ var require_cacheUtils = __commonJS({ var crypto3 = __importStar2(require("crypto")); var fs32 = __importStar2(require("fs")); var path30 = __importStar2(require("path")); - var semver11 = __importStar2(require_semver3()); + var semver12 = __importStar2(require_semver3()); var util4 = __importStar2(require("util")); var constants_1 = require_constants7(); var versionSalt = "1.0"; @@ -34812,7 +34812,7 @@ var require_cacheUtils = __commonJS({ function getCompressionMethod() { return __awaiter2(this, void 0, void 0, function* () { const versionOutput = yield getVersion("zstd", ["--quiet"]); - const version = semver11.clean(versionOutput); + const version = semver12.clean(versionOutput); core29.debug(`zstd version: ${version}`); if (versionOutput === "") { return constants_1.CompressionMethod.Gzip; @@ -106361,7 +106361,7 @@ var require_manifest = __commonJS({ exports2._findMatch = _findMatch; exports2._getOsVersion = _getOsVersion; exports2._readLinuxVersionFile = _readLinuxVersionFile; - var semver11 = __importStar2(require_semver2()); + var semver12 = __importStar2(require_semver2()); var core_1 = require_core(); var os7 = require("os"); var cp = require("child_process"); @@ -106375,7 +106375,7 @@ var require_manifest = __commonJS({ for (const candidate of candidates) { const version = candidate.version; (0, core_1.debug)(`check ${version} satisfies ${versionSpec}`); - if (semver11.satisfies(version, versionSpec) && (!stable || candidate.stable === stable)) { + if (semver12.satisfies(version, versionSpec) && (!stable || candidate.stable === stable)) { file = candidate.files.find((item) => { (0, core_1.debug)(`${item.arch}===${archFilter} && ${item.platform}===${platFilter}`); let chk = item.arch === archFilter && item.platform === platFilter; @@ -106384,7 +106384,7 @@ var require_manifest = __commonJS({ if (osVersion === item.platform_version) { chk = true; } else { - chk = semver11.satisfies(osVersion, item.platform_version); + chk = semver12.satisfies(osVersion, item.platform_version); } } return chk; @@ -106644,7 +106644,7 @@ var require_tool_cache = __commonJS({ var os7 = __importStar2(require("os")); var path30 = __importStar2(require("path")); var httpm = __importStar2(require_lib()); - var semver11 = __importStar2(require_semver2()); + var semver12 = __importStar2(require_semver2()); var stream2 = __importStar2(require("stream")); var util4 = __importStar2(require("util")); var assert_1 = require("assert"); @@ -106917,7 +106917,7 @@ var require_tool_cache = __commonJS({ } function cacheDir2(sourceDir, tool, version, arch2) { return __awaiter2(this, void 0, void 0, function* () { - version = semver11.clean(version) || version; + version = semver12.clean(version) || version; arch2 = arch2 || os7.arch(); core29.debug(`Caching tool ${tool} ${version} ${arch2}`); core29.debug(`source dir: ${sourceDir}`); @@ -106935,7 +106935,7 @@ var require_tool_cache = __commonJS({ } function cacheFile(sourceFile, targetFile, tool, version, arch2) { return __awaiter2(this, void 0, void 0, function* () { - version = semver11.clean(version) || version; + version = semver12.clean(version) || version; arch2 = arch2 || os7.arch(); core29.debug(`Caching tool ${tool} ${version} ${arch2}`); core29.debug(`source file: ${sourceFile}`); @@ -106965,7 +106965,7 @@ var require_tool_cache = __commonJS({ } let toolPath = ""; if (versionSpec) { - versionSpec = semver11.clean(versionSpec) || ""; + versionSpec = semver12.clean(versionSpec) || ""; const cachePath = path30.join(_getCacheDirectory(), toolName, versionSpec, arch2); core29.debug(`checking cache: ${cachePath}`); if (fs32.existsSync(cachePath) && fs32.existsSync(`${cachePath}.complete`)) { @@ -107045,7 +107045,7 @@ var require_tool_cache = __commonJS({ } function _createToolPath(tool, version, arch2) { return __awaiter2(this, void 0, void 0, function* () { - const folderPath = path30.join(_getCacheDirectory(), tool, semver11.clean(version) || version, arch2 || ""); + const folderPath = path30.join(_getCacheDirectory(), tool, semver12.clean(version) || version, arch2 || ""); core29.debug(`destination ${folderPath}`); const markerPath = `${folderPath}.complete`; yield io9.rmRF(folderPath); @@ -107055,15 +107055,15 @@ var require_tool_cache = __commonJS({ }); } function _completeToolPath(tool, version, arch2) { - const folderPath = path30.join(_getCacheDirectory(), tool, semver11.clean(version) || version, arch2 || ""); + const folderPath = path30.join(_getCacheDirectory(), tool, semver12.clean(version) || version, arch2 || ""); const markerPath = `${folderPath}.complete`; fs32.writeFileSync(markerPath, ""); core29.debug("finished caching tool"); } function isExplicitVersion(versionSpec) { - const c = semver11.clean(versionSpec) || ""; + const c = semver12.clean(versionSpec) || ""; core29.debug(`isExplicit: ${c}`); - const valid4 = semver11.valid(c) != null; + const valid4 = semver12.valid(c) != null; core29.debug(`explicit? ${valid4}`); return valid4; } @@ -107071,14 +107071,14 @@ var require_tool_cache = __commonJS({ let version = ""; core29.debug(`evaluating ${versions.length} versions`); versions = versions.sort((a, b) => { - if (semver11.gt(a, b)) { + if (semver12.gt(a, b)) { return 1; } return -1; }); for (let i = versions.length - 1; i >= 0; i--) { const potential = versions[i]; - const satisfied = semver11.satisfies(potential, versionSpec); + const satisfied = semver12.satisfies(potential, versionSpec); if (satisfied) { version = potential; break; @@ -169862,9 +169862,6 @@ function initializeEnvironment(version, env = getEnv()) { env.export("CODEQL_ACTION_FEATURE_WILL_UPLOAD" /* FEATURE_WILL_UPLOAD */, "true"); env.export("CODEQL_ACTION_VERSION" /* VERSION */, version); } -async function codeQlVersionAtLeast(codeql, requiredVersion) { - return semver.gte((await codeql.getVersion()).version, requiredVersion); -} function getBaseDatabaseOidsFilePath(config) { return path.join(config.dbLocation, BASE_DATABASE_OIDS_FILE_NAME); } @@ -172262,7 +172259,7 @@ var OfflineFeatures = class { } const minimumVersion2 = config.minimumVersion; if (codeql && minimumVersion2) { - if (!await codeQlVersionAtLeast(codeql, minimumVersion2)) { + if (!await codeql.isVersionAtLeast(minimumVersion2)) { this.logger.debug( `Feature ${feature} is disabled because the CodeQL CLI version is older than the minimum version ${minimumVersion2}.` ); @@ -172685,6 +172682,7 @@ var fs16 = __toESM(require("fs")); var path15 = __toESM(require("path")); var core12 = __toESM(require_core()); var toolrunner3 = __toESM(require_toolrunner()); +var semver10 = __toESM(require_semver2()); // src/cli-errors.ts var SUPPORTED_PLATFORMS = [ @@ -174673,10 +174671,7 @@ function runnerHasSufficientDiskSpace(diskUsage, logger2, minimumDiskSpaceMb) { return true; } async function runnerHasSufficientMemory(codeql, ramInput, logger2) { - if (await codeQlVersionAtLeast( - codeql, - CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE - )) { + if (await codeql.isVersionAtLeast(CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE)) { logger2.debug( `Skipping memory check for overlay analysis because CodeQL version is at least ${CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE}.` ); @@ -174814,7 +174809,7 @@ async function validateOverlayDatabaseMode(overlayDatabaseMode, useOverlayDataba ); return new Failure("incompatible-build-mode" /* IncompatibleBuildMode */); } - if (!await codeQlVersionAtLeast(codeql, CODEQL_OVERLAY_MINIMUM_VERSION)) { + if (!await codeql.isVersionAtLeast(CODEQL_OVERLAY_MINIMUM_VERSION)) { logger2.warning( `Cannot build an ${overlayDatabaseMode} database because the CodeQL CLI is older than ${CODEQL_OVERLAY_MINIMUM_VERSION}. Falling back to creating a normal full database instead.` ); @@ -177088,6 +177083,9 @@ async function getCodeQLForCmd(logger2, cmd, checkVersion) { } return result; }, + async isVersionAtLeast(requiredVersion) { + return semver10.gte((await this.getVersion()).version, requiredVersion); + }, async printVersion() { core12.info(JSON.stringify(await this.getVersion(), null, 2)); }, @@ -177476,11 +177474,11 @@ Output was: ${extractorPath}` await runCli(cmd, args); } }; - if (checkVersion && !await codeQlVersionAtLeast(codeql, CODEQL_MINIMUM_VERSION)) { + if (checkVersion && !await codeql.isVersionAtLeast(CODEQL_MINIMUM_VERSION)) { throw new ConfigurationError( `Expected a CodeQL CLI with version at least ${CODEQL_MINIMUM_VERSION} but got version ${(await codeql.getVersion()).version}` ); - } else if (checkVersion && process.env["CODEQL_ACTION_SUPPRESS_DEPRECATED_SOON_WARNING" /* SUPPRESS_DEPRECATED_SOON_WARNING */] !== "true" && !await codeQlVersionAtLeast(codeql, CODEQL_NEXT_MINIMUM_VERSION)) { + } else if (checkVersion && process.env["CODEQL_ACTION_SUPPRESS_DEPRECATED_SOON_WARNING" /* SUPPRESS_DEPRECATED_SOON_WARNING */] !== "true" && !await codeql.isVersionAtLeast(CODEQL_NEXT_MINIMUM_VERSION)) { const result = await codeql.getVersion(); core12.warning( `CodeQL CLI version ${result.version} was discontinued on ${GHES_MOST_RECENT_DEPRECATION_DATE} alongside GitHub Enterprise Server ${GHES_VERSION_MOST_RECENTLY_DEPRECATED} and will not be supported by the next minor release of the CodeQL Action. Please update to CodeQL CLI version ${CODEQL_NEXT_MINIMUM_VERSION} or later. For instance, if you have specified a custom version of the CLI using the 'tools' input to the 'init' Action, you can remove this input to use the default version. @@ -186038,7 +186036,7 @@ var fs29 = __toESM(require("fs")); var path25 = __toESM(require("path")); var core19 = __toESM(require_core()); var io7 = __toESM(require_io()); -var semver10 = __toESM(require_semver2()); +var semver11 = __toESM(require_semver2()); // src/config/inputs.ts async function getToolsInput(action, repositoryProperties) { @@ -186548,7 +186546,7 @@ async function run3(actionState) { ) { const publicPreview = "2.22.1"; const actualVer = (await codeql.getVersion()).version; - if (semver10.lt(actualVer, publicPreview)) { + if (semver11.lt(actualVer, publicPreview)) { actionState.env.export("CODEQL_ENABLE_EXPERIMENTAL_FEATURES" /* EXPERIMENTAL_FEATURES */, "true"); logger2.info("Experimental Rust analysis enabled"); } @@ -186781,7 +186779,7 @@ exec ${goBinaryPath} "$@"` logger2.debug( `${"CODEQL_EXTRACTOR_JAVA_OPTION_MINIMIZE_DEPENDENCY_JARS" /* JAVA_EXTRACTOR_MINIMIZE_DEPENDENCY_JARS */} is already set to '${process.env["CODEQL_EXTRACTOR_JAVA_OPTION_MINIMIZE_DEPENDENCY_JARS" /* JAVA_EXTRACTOR_MINIMIZE_DEPENDENCY_JARS */]}', so the Action will not override it.` ); - } else if (await codeQlVersionAtLeast(codeql, CODEQL_VERSION_JAR_MINIMIZATION) && config.dependencyCachingEnabled && config.buildMode === "none" /* None */ && config.languages.includes("java" /* java */)) { + } else if (await codeql.isVersionAtLeast(CODEQL_VERSION_JAR_MINIMIZATION) && config.dependencyCachingEnabled && config.buildMode === "none" /* None */ && config.languages.includes("java" /* java */)) { actionState.env.export( "CODEQL_EXTRACTOR_JAVA_OPTION_MINIMIZE_DEPENDENCY_JARS" /* JAVA_EXTRACTOR_MINIMIZE_DEPENDENCY_JARS */, "true" diff --git a/src/codeql.ts b/src/codeql.ts index 706ca3210..07153a749 100644 --- a/src/codeql.ts +++ b/src/codeql.ts @@ -4,6 +4,7 @@ import * as path from "path"; import * as core from "@actions/core"; import * as toolrunner from "@actions/exec/lib/toolrunner"; import * as yaml from "js-yaml"; +import * as semver from "semver"; import { CommandInvocationError, @@ -73,6 +74,11 @@ export interface CodeQL { * Get a string containing the semver version of the CodeQL executable. */ getVersion(): Promise; + /** + * Determines whether the CLI installation represented by this {@link CodeQL} instance + * has at least the {@link requiredVersion}. + */ + isVersionAtLeast(requiredVersion: string): Promise; /** * Print version information about CodeQL. */ @@ -414,6 +420,19 @@ export function createStubCodeQL(partialCodeql: Partial): CodeQL { getVersion: resolveFunction(partialCodeql, "getVersion", async () => ({ version: "1.0.0", })), + isVersionAtLeast: resolveFunction( + partialCodeql, + "codeQlVersionAtLeast", + async (requiredVersion) => { + return ( + !!partialCodeql.getVersion && + semver.gte( + (await partialCodeql.getVersion()).version, + requiredVersion, + ) + ); + }, + ), printVersion: resolveFunction(partialCodeql, "printVersion"), supportsFeature: resolveFunction( partialCodeql, @@ -517,6 +536,9 @@ async function getCodeQLForCmd( } return result; }, + async isVersionAtLeast(requiredVersion: string) { + return semver.gte((await this.getVersion()).version, requiredVersion); + }, async printVersion() { // Reuse the cached version information rather than invoking the CLI again. core.info(JSON.stringify(await this.getVersion(), null, 2)); @@ -1011,7 +1033,7 @@ async function getCodeQLForCmd( // CodeQL object is created. if ( checkVersion && - !(await util.codeQlVersionAtLeast(codeql, CODEQL_MINIMUM_VERSION)) + !(await codeql.isVersionAtLeast(CODEQL_MINIMUM_VERSION)) ) { throw new util.ConfigurationError( `Expected a CodeQL CLI with version at least ${CODEQL_MINIMUM_VERSION} but got version ${ @@ -1021,7 +1043,7 @@ async function getCodeQLForCmd( } else if ( checkVersion && process.env[EnvVar.SUPPRESS_DEPRECATED_SOON_WARNING] !== "true" && - !(await util.codeQlVersionAtLeast(codeql, CODEQL_NEXT_MINIMUM_VERSION)) + !(await codeql.isVersionAtLeast(CODEQL_NEXT_MINIMUM_VERSION)) ) { const result = await codeql.getVersion(); core.warning( diff --git a/src/config-utils.ts b/src/config-utils.ts index de506aac0..5c2a89776 100644 --- a/src/config-utils.ts +++ b/src/config-utils.ts @@ -82,7 +82,6 @@ import { GitHubVersion, ConfigurationError, BuildMode, - codeQlVersionAtLeast, cloneObject, isDefined, checkDiskUsage, @@ -652,10 +651,7 @@ async function runnerHasSufficientMemory( logger: Logger, ): Promise { if ( - await codeQlVersionAtLeast( - codeql, - CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE, - ) + await codeql.isVersionAtLeast(CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE) ) { logger.debug( `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( ); return new Failure(OverlayDisabledReason.IncompatibleBuildMode); } - if (!(await codeQlVersionAtLeast(codeql, CODEQL_OVERLAY_MINIMUM_VERSION))) { + if (!(await codeql.isVersionAtLeast(CODEQL_OVERLAY_MINIMUM_VERSION))) { logger.warning( `Cannot build an ${overlayDatabaseMode} database because ` + `the CodeQL CLI is older than ${CODEQL_OVERLAY_MINIMUM_VERSION}. ` + diff --git a/src/feature-flags.ts b/src/feature-flags.ts index 5cf7c7414..e64b69eab 100644 --- a/src/feature-flags.ts +++ b/src/feature-flags.ts @@ -589,7 +589,7 @@ class OfflineFeatures implements FeatureEnablement { // Never use this feature if the CLI version explicitly can't support it. const minimumVersion = config.minimumVersion; if (codeql && minimumVersion) { - if (!(await util.codeQlVersionAtLeast(codeql, minimumVersion))) { + if (!(await codeql.isVersionAtLeast(minimumVersion))) { this.logger.debug( `Feature ${feature} is disabled because the CodeQL CLI version is older than the minimum ` + `version ${minimumVersion}.`, diff --git a/src/init-action.ts b/src/init-action.ts index f58d4ccca..7f9178304 100644 --- a/src/init-action.ts +++ b/src/init-action.ts @@ -88,7 +88,6 @@ import { checkDiskUsage, checkForTimeout, checkGitHubVersionInRange, - codeQlVersionAtLeast, DEFAULT_DEBUG_ARTIFACT_NAME, DEFAULT_DEBUG_DATABASE_NAME, getCodeQLMemoryLimit, @@ -686,7 +685,7 @@ async function run( `${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.`, ); } else if ( - (await codeQlVersionAtLeast(codeql, CODEQL_VERSION_JAR_MINIMIZATION)) && + (await codeql.isVersionAtLeast(CODEQL_VERSION_JAR_MINIMIZATION)) && config.dependencyCachingEnabled && config.buildMode === BuildMode.None && config.languages.includes(BuiltInLanguage.java) diff --git a/src/util.ts b/src/util.ts index 8761cacb2..19fbc4368 100644 --- a/src/util.ts +++ b/src/util.ts @@ -565,13 +565,6 @@ export function initializeEnvironment(version: string, env: Env = getEnv()) { env.export(EnvVar.VERSION, version); } -export async function codeQlVersionAtLeast( - codeql: CodeQL, - requiredVersion: string, -): Promise { - return semver.gte((await codeql.getVersion()).version, requiredVersion); -} - export function getBaseDatabaseOidsFilePath( config: ActionConfig<"dbLocation">, ): string {