Enforce a minimum version of CodeQL CLI

This commit is contained in:
Edoardo Pirovano
2021-08-18 10:15:48 +01:00
parent fb77829455
commit 70d2efc353
21 changed files with 111 additions and 61 deletions

View File

@@ -178,9 +178,20 @@ let cachedCodeQL: CodeQL | undefined = undefined;
const CODEQL_BUNDLE_VERSION = defaults.bundleVersion;
const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
/**
* The oldest version of CodeQL that the Action will run with. This should be
* at least three minor versions behind the current version. The version flags
* below can be used to conditionally enable certain features on versions newer
* than this. Please record the reason we cannot support an older version.
*
* Reason: Changes to how the tracing environment is set up.
*/
const CODEQL_MINIMUM_VERSION = "2.3.1";
/**
* Versions of CodeQL that version-flag certain functionality in the Action.
* For convenience, please keep these in descending order.
* For convenience, please keep these in descending order. Once a version
* flag is older than the oldest supported version above, it may be removed.
*/
const CODEQL_VERSION_RAM_FINALIZE = "2.5.8";
const CODEQL_VERSION_DIAGNOSTICS = "2.5.6";
@@ -326,7 +337,8 @@ export async function setupCodeQL(
tempDir: string,
toolCacheDir: string,
variant: util.GitHubVariant,
logger: Logger
logger: Logger,
checkVersion: boolean
): Promise<{ codeql: CodeQL; toolsVersion: string }> {
try {
// We use the special value of 'latest' to prioritize the version in the
@@ -437,7 +449,7 @@ export async function setupCodeQL(
throw new Error(`Unsupported platform: ${process.platform}`);
}
cachedCodeQL = getCodeQLForCmd(codeqlCmd);
cachedCodeQL = await getCodeQLForCmd(codeqlCmd, checkVersion);
return { codeql: cachedCodeQL, toolsVersion: codeqlURLVersion };
} catch (e) {
logger.error(e);
@@ -474,9 +486,9 @@ export function convertToSemVer(version: string, logger: Logger): string {
/**
* Use the CodeQL executable located at the given path.
*/
export function getCodeQL(cmd: string): CodeQL {
export async function getCodeQL(cmd: string): Promise<CodeQL> {
if (cachedCodeQL === undefined) {
cachedCodeQL = getCodeQLForCmd(cmd);
cachedCodeQL = await getCodeQLForCmd(cmd, true);
}
return cachedCodeQL;
}
@@ -549,9 +561,12 @@ export function getCachedCodeQL(): CodeQL {
return cachedCodeQL;
}
function getCodeQLForCmd(cmd: string): CodeQL {
async function getCodeQLForCmd(
cmd: string,
checkVersion: boolean
): Promise<CodeQL> {
let cachedVersion: undefined | Promise<string> = undefined;
return {
const codeql = {
getPath() {
return cmd;
},
@@ -869,6 +884,15 @@ function getCodeQLForCmd(cmd: string): CodeQL {
await new toolrunner.ToolRunner(cmd, args).exec();
},
};
if (
checkVersion &&
!(await util.codeQlVersionAbove(codeql, CODEQL_MINIMUM_VERSION))
) {
throw new Error(
`Expected a CodeQL CLI with version at least ${CODEQL_MINIMUM_VERSION} but got version ${await codeql.getVersion()}`
);
}
return codeql;
}
function packWithVersionToString(pack: PackWithVersion): string {