@@ -4,6 +4,7 @@ import * as path from "path";
44import * as core from "@actions/core" ;
55import * as toolrunner from "@actions/exec/lib/toolrunner" ;
66import * as yaml from "js-yaml" ;
7+ import * as semver from "semver" ;
78
89import {
910 CommandInvocationError ,
@@ -19,6 +20,7 @@ import type { ActionConfig } from "./config/action-config";
1920import { appendExtraQueryExclusions , type Config } from "./config-utils" ;
2021import { DocUrl } from "./doc-url" ;
2122import { EnvVar , getEnv , Env , ReadOnlyEnv } from "./environment" ;
23+ import { getErrorMessage , isDiskConfigurationError } from "./errors" ;
2224import {
2325 CodeQLDefaultVersionInfo ,
2426 Feature ,
@@ -34,7 +36,9 @@ import { ToolsDownloadStatusReport } from "./tools-download";
3436import { ToolsFeature , isSupportedToolsFeature } from "./tools-features" ;
3537import { shouldEnableIndirectTracing } from "./tracer-config" ;
3638import * as util from "./util" ;
37- import { BuildMode , CleanupLevel , getErrorMessage } from "./util" ;
39+ import { BuildMode , CleanupLevel } from "./util" ;
40+
41+ export { isDiskConfigurationError } from "./errors" ;
3842
3943type Options = Array < string | number | boolean > ;
4044
@@ -70,6 +74,11 @@ export interface CodeQL {
7074 * Get a string containing the semver version of the CodeQL executable.
7175 */
7276 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 > ;
7382 /**
7483 * Print version information about CodeQL.
7584 */
@@ -275,26 +284,6 @@ const GHES_MOST_RECENT_DEPRECATION_DATE = "2026-10-16";
275284/** The CLI verbosity level to use for extraction in debug mode. */
276285const EXTRACTION_DEBUG_MODE_VERBOSITY = "progress++" ;
277286
278- /**
279- * Decides whether `e` is a disk-related error outside of our control
280- * that should be classified as a `ConfigurationError`.
281- *
282- * @param e The error to check.
283- * @returns True if the error should be treated as a `ConfigurationError` or false if not.
284- */
285- export function isDiskConfigurationError ( e : unknown ) : boolean {
286- if ( ! ( e instanceof Error ) ) {
287- return false ;
288- }
289-
290- return (
291- // out of disk space
292- e . message . includes ( "ENOSPC" ) ||
293- // access denied
294- e . message . includes ( "EACCES" )
295- ) ;
296- }
297-
298287/**
299288 * Set up CodeQL CLI access.
300289 *
@@ -403,9 +392,9 @@ export function setCodeQL(codeql: Partial<CodeQL>): void {
403392 cachedCodeQL = createStubCodeQL ( codeql ) ;
404393}
405394
406- function resolveFunction < T > (
395+ function resolveFunction < K extends keyof CodeQL , T extends CodeQL [ K ] > (
407396 partialCodeql : Partial < CodeQL > ,
408- methodName : string ,
397+ methodName : K ,
409398 defaultImplementation ?: T ,
410399) : T {
411400 if ( typeof partialCodeql [ methodName ] !== "function" ) {
@@ -415,7 +404,7 @@ function resolveFunction<T>(
415404 const dummyMethod = ( ) => {
416405 throw new Error ( `CodeQL ${ methodName } method not correctly defined` ) ;
417406 } ;
418- return dummyMethod as T ;
407+ return dummyMethod as unknown as T ;
419408 }
420409 return partialCodeql [ methodName ] as T ;
421410}
@@ -432,6 +421,19 @@ export function createStubCodeQL(partialCodeql: Partial<CodeQL>): CodeQL {
432421 getVersion : resolveFunction ( partialCodeql , "getVersion" , async ( ) => ( {
433422 version : "1.0.0" ,
434423 } ) ) ,
424+ isVersionAtLeast : resolveFunction (
425+ partialCodeql ,
426+ "isVersionAtLeast" ,
427+ async ( requiredVersion ) => {
428+ return (
429+ ! ! partialCodeql . getVersion &&
430+ semver . gte (
431+ ( await partialCodeql . getVersion ( ) ) . version ,
432+ requiredVersion ,
433+ )
434+ ) ;
435+ } ,
436+ ) ,
435437 printVersion : resolveFunction ( partialCodeql , "printVersion" ) ,
436438 supportsFeature : resolveFunction (
437439 partialCodeql ,
@@ -525,6 +527,9 @@ export async function getCodeQLForCmd(
525527 }
526528 return result ;
527529 } ,
530+ async isVersionAtLeast ( requiredVersion : string ) {
531+ return semver . gte ( ( await this . getVersion ( ) ) . version , requiredVersion ) ;
532+ } ,
528533 async printVersion ( ) {
529534 // Reuse the cached version information rather than invoking the CLI again.
530535 core . info ( JSON . stringify ( await this . getVersion ( ) , null , 2 ) ) ;
@@ -1062,7 +1067,7 @@ export async function getCodeQLForCmd(
10621067 // CodeQL object is created.
10631068 if (
10641069 checkVersion &&
1065- ! ( await util . codeQlVersionAtLeast ( codeql , CODEQL_MINIMUM_VERSION ) )
1070+ ! ( await codeql . isVersionAtLeast ( CODEQL_MINIMUM_VERSION ) )
10661071 ) {
10671072 throw new util . ConfigurationError (
10681073 `Expected a CodeQL CLI with version at least ${ CODEQL_MINIMUM_VERSION } but got version ${
@@ -1072,7 +1077,7 @@ export async function getCodeQLForCmd(
10721077 } else if (
10731078 checkVersion &&
10741079 env . getOptional ( EnvVar . SUPPRESS_DEPRECATED_SOON_WARNING ) !== "true" &&
1075- ! ( await util . codeQlVersionAtLeast ( codeql , CODEQL_NEXT_MINIMUM_VERSION ) )
1080+ ! ( await codeql . isVersionAtLeast ( CODEQL_NEXT_MINIMUM_VERSION ) )
10761081 ) {
10771082 const result = await codeql . getVersion ( ) ;
10781083 core . warning (
0 commit comments