Include the bundle version in the toolcache version number

This gives us an easy cache hit when requesting the same tools URL.
This commit is contained in:
Henry Mercer 2023-01-12 20:56:31 +00:00
parent c2e39e078f
commit 33206d299e
6 changed files with 23 additions and 15 deletions

14
lib/setup-codeql.js generated
View file

@ -397,7 +397,7 @@ async function getCodeQLSource(toolsInput, bypassToolcache, defaultCliVersion, a
};
}
exports.getCodeQLSource = getCodeQLSource;
async function downloadCodeQL(codeqlURL, cliVersion, apiDetails, variant, tempDir, logger) {
async function downloadCodeQL(codeqlURL, maybeCliVersion, apiDetails, variant, tempDir, logger) {
const parsedCodeQLURL = new URL(codeqlURL);
const searchParams = new URLSearchParams(parsedCodeQLURL.search);
const headers = {
@ -424,11 +424,15 @@ async function downloadCodeQL(codeqlURL, cliVersion, apiDetails, variant, tempDi
logger.debug(`CodeQL bundle download to ${codeqlPath} complete.`);
const codeqlExtracted = await toolcache.extractTar(codeqlPath);
const bundleVersion = getBundleVersionFromUrl(codeqlURL);
// If we have a CLI version, use that. Otherwise, try to find the CLI version from the GitHub Releases
const toolcacheVersion = cliVersion ||
// Try to compute the CLI version for this bundle
const cliVersion = maybeCliVersion ||
(variant === util.GitHubVariant.DOTCOM &&
(await tryFindCliVersionDotcomOnly(`codeql-bundle-${bundleVersion}`, logger))) ||
convertToSemVer(bundleVersion, logger);
(await tryFindCliVersionDotcomOnly(`codeql-bundle-${bundleVersion}`, logger)));
// Include the bundle version in the toolcache version number so that if the user requests the
// same URL again, we can get it from the cache without having to call any of the Releases API.
const toolcacheVersion = cliVersion
? `${cliVersion}-${bundleVersion}`
: convertToSemVer(bundleVersion, logger);
return await toolcache.cacheDir(codeqlExtracted, "CodeQL", toolcacheVersion);
}
exports.downloadCodeQL = downloadCodeQL;