Use the CLI version when caching the bundle in telemetry too

This commit is contained in:
Henry Mercer 2023-01-12 21:09:09 +00:00
parent 33206d299e
commit 0be20e5ce1
6 changed files with 36 additions and 16 deletions

2
lib/codeql.test.js generated
View file

@ -187,7 +187,7 @@ function mockApiDetails(apiDetails) {
const result = await codeql.setupCodeQL(url, sampleApiDetails, tmpDir, util.GitHubVariant.DOTCOM, false, SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), false);
t.assert(releaseApiMock.isDone(), "Releases API should have been called");
t.assert(toolcache.find("CodeQL", "2.10.0-20200610"));
t.deepEqual(result.toolsVersion, "0.0.0-20200610");
t.deepEqual(result.toolsVersion, "2.10.0");
});
});
for (const { isCached, tagName, toolcacheCliVersion } of [

File diff suppressed because one or more lines are too long

18
lib/setup-codeql.js generated
View file

@ -427,13 +427,17 @@ async function downloadCodeQL(codeqlURL, maybeCliVersion, apiDetails, variant, t
// Try to compute the CLI version for this bundle
const cliVersion = maybeCliVersion ||
(variant === util.GitHubVariant.DOTCOM &&
(await tryFindCliVersionDotcomOnly(`codeql-bundle-${bundleVersion}`, logger)));
(await tryFindCliVersionDotcomOnly(`codeql-bundle-${bundleVersion}`, logger))) ||
undefined;
// 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);
return {
toolsVersion: cliVersion || toolcacheVersion,
codeqlFolder: await toolcache.cacheDir(codeqlExtracted, "CodeQL", toolcacheVersion),
};
}
exports.downloadCodeQL = downloadCodeQL;
function getCodeQLURLVersion(url) {
@ -461,6 +465,7 @@ exports.getCodeQLURLVersion = getCodeQLURLVersion;
async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, bypassToolcache, defaultCliVersion, logger) {
const source = await getCodeQLSource(toolsInput, bypassToolcache, defaultCliVersion, apiDetails, variant, logger);
let codeqlFolder;
let toolsVersion = source.toolsVersion;
switch (source.sourceType) {
case "local":
codeqlFolder = await toolcache.extractTar(source.codeqlTarPath);
@ -469,13 +474,16 @@ async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, bypas
codeqlFolder = source.codeqlFolder;
logger.debug(`CodeQL found in cache ${codeqlFolder}`);
break;
case "download":
codeqlFolder = await downloadCodeQL(source.codeqlURL, source.cliVersion, apiDetails, variant, tempDir, logger);
case "download": {
const result = await downloadCodeQL(source.codeqlURL, source.cliVersion, apiDetails, variant, tempDir, logger);
toolsVersion = result.toolsVersion;
codeqlFolder = result.codeqlFolder;
break;
}
default:
util.assertNever(source);
}
return { codeqlFolder, toolsVersion: source.toolsVersion };
return { codeqlFolder, toolsVersion };
}
exports.setupCodeQLBundle = setupCodeQLBundle;
//# sourceMappingURL=setup-codeql.js.map

File diff suppressed because one or more lines are too long