mirror of
https://github.com/github/codeql-action.git
synced 2026-10-03 09:14:58 +00:00
Extract the toolcache lookup from getCodeQLSource
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
121
lib/entry-points.js
generated
121
lib/entry-points.js
generated
@@ -152459,62 +152459,12 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, rawLanguages, useO
|
||||
logger.debug(
|
||||
`Attempting to obtain CodeQL tools. CLI version: ${cliVersion2 ?? "unknown"}, bundle tag name: ${tagName ?? "unknown"}, URL: ${url2 ?? "unspecified"}.`
|
||||
);
|
||||
let codeqlFolder;
|
||||
if (cliVersion2) {
|
||||
codeqlFolder = toolcache3.find("CodeQL", cliVersion2);
|
||||
if (!codeqlFolder) {
|
||||
logger.debug(
|
||||
`Didn't find a version of the CodeQL tools in the toolcache with a version number exactly matching ${cliVersion2}.`
|
||||
);
|
||||
const allVersions = toolcache3.findAllVersions("CodeQL");
|
||||
logger.debug(
|
||||
`Found the following versions of the CodeQL tools in the toolcache: ${JSON.stringify(
|
||||
allVersions
|
||||
)}.`
|
||||
);
|
||||
const candidateVersions = allVersions.filter(
|
||||
(version) => version.startsWith(`${cliVersion2}-`)
|
||||
);
|
||||
if (candidateVersions.length === 1) {
|
||||
logger.debug(
|
||||
`Exactly one version of the CodeQL tools starting with ${cliVersion2} found in the toolcache, using that.`
|
||||
);
|
||||
codeqlFolder = toolcache3.find("CodeQL", candidateVersions[0]);
|
||||
} else if (candidateVersions.length === 0) {
|
||||
logger.debug(
|
||||
`Didn't find any versions of the CodeQL tools starting with ${cliVersion2} in the toolcache. Trying next fallback method.`
|
||||
);
|
||||
} else {
|
||||
logger.warning(
|
||||
`Found ${candidateVersions.length} versions of the CodeQL tools starting with ${cliVersion2} in the toolcache, but at most one was expected.`
|
||||
);
|
||||
logger.debug("Trying next fallback method.");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!codeqlFolder && tagName) {
|
||||
const fallbackVersion = await tryGetFallbackToolcacheVersion(
|
||||
cliVersion2,
|
||||
tagName,
|
||||
logger
|
||||
);
|
||||
if (fallbackVersion) {
|
||||
codeqlFolder = toolcache3.find("CodeQL", fallbackVersion);
|
||||
} else {
|
||||
logger.debug(
|
||||
`Could not determine a fallback toolcache version number for CodeQL tools version ${humanReadableVersion}.`
|
||||
);
|
||||
}
|
||||
}
|
||||
if (codeqlFolder) {
|
||||
logger.info(
|
||||
`Found CodeQL tools version ${humanReadableVersion} in the toolcache.`
|
||||
);
|
||||
} else {
|
||||
logger.info(
|
||||
`Did not find CodeQL tools version ${humanReadableVersion} in the toolcache.`
|
||||
);
|
||||
}
|
||||
const codeqlFolder = await findCodeQLInToolcache(
|
||||
cliVersion2,
|
||||
tagName,
|
||||
humanReadableVersion,
|
||||
logger
|
||||
);
|
||||
if (codeqlFolder) {
|
||||
if (cliVersion2) {
|
||||
logger.info(
|
||||
@@ -152589,6 +152539,65 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, rawLanguages, useO
|
||||
toolsVersion: resolvedVersion ?? "unknown"
|
||||
};
|
||||
}
|
||||
async function findCodeQLInToolcache(cliVersion2, tagName, humanReadableVersion, logger) {
|
||||
let codeqlFolder;
|
||||
if (cliVersion2) {
|
||||
codeqlFolder = toolcache3.find("CodeQL", cliVersion2);
|
||||
if (!codeqlFolder) {
|
||||
logger.debug(
|
||||
`Didn't find a version of the CodeQL tools in the toolcache with a version number exactly matching ${cliVersion2}.`
|
||||
);
|
||||
const allVersions = toolcache3.findAllVersions("CodeQL");
|
||||
logger.debug(
|
||||
`Found the following versions of the CodeQL tools in the toolcache: ${JSON.stringify(
|
||||
allVersions
|
||||
)}.`
|
||||
);
|
||||
const candidateVersions = allVersions.filter(
|
||||
(version) => version.startsWith(`${cliVersion2}-`)
|
||||
);
|
||||
if (candidateVersions.length === 1) {
|
||||
logger.debug(
|
||||
`Exactly one version of the CodeQL tools starting with ${cliVersion2} found in the toolcache, using that.`
|
||||
);
|
||||
codeqlFolder = toolcache3.find("CodeQL", candidateVersions[0]);
|
||||
} else if (candidateVersions.length === 0) {
|
||||
logger.debug(
|
||||
`Didn't find any versions of the CodeQL tools starting with ${cliVersion2} in the toolcache. Trying next fallback method.`
|
||||
);
|
||||
} else {
|
||||
logger.warning(
|
||||
`Found ${candidateVersions.length} versions of the CodeQL tools starting with ${cliVersion2} in the toolcache, but at most one was expected.`
|
||||
);
|
||||
logger.debug("Trying next fallback method.");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!codeqlFolder && tagName) {
|
||||
const fallbackVersion = await tryGetFallbackToolcacheVersion(
|
||||
cliVersion2,
|
||||
tagName,
|
||||
logger
|
||||
);
|
||||
if (fallbackVersion) {
|
||||
codeqlFolder = toolcache3.find("CodeQL", fallbackVersion);
|
||||
} else {
|
||||
logger.debug(
|
||||
`Could not determine a fallback toolcache version number for CodeQL tools version ${humanReadableVersion}.`
|
||||
);
|
||||
}
|
||||
}
|
||||
if (codeqlFolder) {
|
||||
logger.info(
|
||||
`Found CodeQL tools version ${humanReadableVersion} in the toolcache.`
|
||||
);
|
||||
} else {
|
||||
logger.info(
|
||||
`Did not find CodeQL tools version ${humanReadableVersion} in the toolcache.`
|
||||
);
|
||||
}
|
||||
return codeqlFolder;
|
||||
}
|
||||
async function tryGetFallbackToolcacheVersion(cliVersion2, tagName, logger) {
|
||||
const bundleVersion2 = tryGetBundleVersionFromTagName(tagName, logger);
|
||||
if (bundleVersion2 === void 0) {
|
||||
|
||||
@@ -629,76 +629,12 @@ export async function getCodeQLSource(
|
||||
`URL: ${url ?? "unspecified"}.`,
|
||||
);
|
||||
|
||||
let codeqlFolder: string | undefined;
|
||||
|
||||
if (cliVersion) {
|
||||
// If we find the specified CLI version, we always use that.
|
||||
codeqlFolder = toolcache.find("CodeQL", cliVersion);
|
||||
|
||||
// Fall back to a single `x.y.z-*` entry, since older toolcaches store bundles as
|
||||
// `x.y.z-<bundle version>`.
|
||||
if (!codeqlFolder) {
|
||||
logger.debug(
|
||||
"Didn't find a version of the CodeQL tools in the toolcache with a version number " +
|
||||
`exactly matching ${cliVersion}.`,
|
||||
);
|
||||
const allVersions = toolcache.findAllVersions("CodeQL");
|
||||
logger.debug(
|
||||
`Found the following versions of the CodeQL tools in the toolcache: ${JSON.stringify(
|
||||
allVersions,
|
||||
)}.`,
|
||||
);
|
||||
const candidateVersions = allVersions.filter((version) =>
|
||||
version.startsWith(`${cliVersion}-`),
|
||||
);
|
||||
if (candidateVersions.length === 1) {
|
||||
logger.debug(
|
||||
`Exactly one version of the CodeQL tools starting with ${cliVersion} found in the ` +
|
||||
"toolcache, using that.",
|
||||
);
|
||||
codeqlFolder = toolcache.find("CodeQL", candidateVersions[0]);
|
||||
} else if (candidateVersions.length === 0) {
|
||||
logger.debug(
|
||||
`Didn't find any versions of the CodeQL tools starting with ${cliVersion} ` +
|
||||
`in the toolcache. Trying next fallback method.`,
|
||||
);
|
||||
} else {
|
||||
logger.warning(
|
||||
`Found ${candidateVersions.length} versions of the CodeQL tools starting with ` +
|
||||
`${cliVersion} in the toolcache, but at most one was expected.`,
|
||||
);
|
||||
logger.debug("Trying next fallback method.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to matching `0.0.0-<bundleVersion>`.
|
||||
if (!codeqlFolder && tagName) {
|
||||
const fallbackVersion = await tryGetFallbackToolcacheVersion(
|
||||
cliVersion,
|
||||
tagName,
|
||||
logger,
|
||||
);
|
||||
if (fallbackVersion) {
|
||||
codeqlFolder = toolcache.find("CodeQL", fallbackVersion);
|
||||
} else {
|
||||
logger.debug(
|
||||
"Could not determine a fallback toolcache version number for CodeQL tools version " +
|
||||
`${humanReadableVersion}.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (codeqlFolder) {
|
||||
logger.info(
|
||||
`Found CodeQL tools version ${humanReadableVersion} in the toolcache.`,
|
||||
);
|
||||
} else {
|
||||
logger.info(
|
||||
`Did not find CodeQL tools version ${humanReadableVersion} in the toolcache.`,
|
||||
);
|
||||
}
|
||||
|
||||
const codeqlFolder = await findCodeQLInToolcache(
|
||||
cliVersion,
|
||||
tagName,
|
||||
humanReadableVersion,
|
||||
logger,
|
||||
);
|
||||
if (codeqlFolder) {
|
||||
if (cliVersion) {
|
||||
logger.info(
|
||||
@@ -790,6 +726,90 @@ export async function getCodeQLSource(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for the requested version of the CodeQL tools in the toolcache, allowing for the different
|
||||
* version numbers that toolcaches may use for the same bundle. We try the exact CLI version, then a
|
||||
* single `x.y.z-*` entry for that version, then `0.0.0-<bundle version>`. The `x.y.z-*` entry can
|
||||
* be any prerelease of the CLI version.
|
||||
*/
|
||||
async function findCodeQLInToolcache(
|
||||
cliVersion: string | undefined,
|
||||
tagName: string | undefined,
|
||||
humanReadableVersion: string,
|
||||
logger: Logger,
|
||||
): Promise<string | undefined> {
|
||||
let codeqlFolder: string | undefined;
|
||||
|
||||
if (cliVersion) {
|
||||
// If we find the specified CLI version, we always use that.
|
||||
codeqlFolder = toolcache.find("CodeQL", cliVersion);
|
||||
|
||||
// Fall back to a single `x.y.z-*` entry, since older toolcaches store bundles as
|
||||
// `x.y.z-<bundle version>`.
|
||||
if (!codeqlFolder) {
|
||||
logger.debug(
|
||||
"Didn't find a version of the CodeQL tools in the toolcache with a version number " +
|
||||
`exactly matching ${cliVersion}.`,
|
||||
);
|
||||
const allVersions = toolcache.findAllVersions("CodeQL");
|
||||
logger.debug(
|
||||
`Found the following versions of the CodeQL tools in the toolcache: ${JSON.stringify(
|
||||
allVersions,
|
||||
)}.`,
|
||||
);
|
||||
const candidateVersions = allVersions.filter((version) =>
|
||||
version.startsWith(`${cliVersion}-`),
|
||||
);
|
||||
if (candidateVersions.length === 1) {
|
||||
logger.debug(
|
||||
`Exactly one version of the CodeQL tools starting with ${cliVersion} found in the ` +
|
||||
"toolcache, using that.",
|
||||
);
|
||||
codeqlFolder = toolcache.find("CodeQL", candidateVersions[0]);
|
||||
} else if (candidateVersions.length === 0) {
|
||||
logger.debug(
|
||||
`Didn't find any versions of the CodeQL tools starting with ${cliVersion} ` +
|
||||
`in the toolcache. Trying next fallback method.`,
|
||||
);
|
||||
} else {
|
||||
logger.warning(
|
||||
`Found ${candidateVersions.length} versions of the CodeQL tools starting with ` +
|
||||
`${cliVersion} in the toolcache, but at most one was expected.`,
|
||||
);
|
||||
logger.debug("Trying next fallback method.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to matching `0.0.0-<bundleVersion>`.
|
||||
if (!codeqlFolder && tagName) {
|
||||
const fallbackVersion = await tryGetFallbackToolcacheVersion(
|
||||
cliVersion,
|
||||
tagName,
|
||||
logger,
|
||||
);
|
||||
if (fallbackVersion) {
|
||||
codeqlFolder = toolcache.find("CodeQL", fallbackVersion);
|
||||
} else {
|
||||
logger.debug(
|
||||
"Could not determine a fallback toolcache version number for CodeQL tools version " +
|
||||
`${humanReadableVersion}.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (codeqlFolder) {
|
||||
logger.info(
|
||||
`Found CodeQL tools version ${humanReadableVersion} in the toolcache.`,
|
||||
);
|
||||
} else {
|
||||
logger.info(
|
||||
`Did not find CodeQL tools version ${humanReadableVersion} in the toolcache.`,
|
||||
);
|
||||
}
|
||||
return codeqlFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a fallback version number to use when looking for CodeQL in the toolcache if we didn't find
|
||||
* the `x.y.z` version. This is to support old versions of the toolcache.
|
||||
|
||||
Reference in New Issue
Block a user