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

2
lib/codeql.test.js generated
View file

@ -186,7 +186,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"));
t.assert(toolcache.find("CodeQL", "2.10.0-20200610"));
t.deepEqual(result.toolsVersion, "0.0.0-20200610");
});
});

File diff suppressed because one or more lines are too long

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;

File diff suppressed because one or more lines are too long

View file

@ -265,7 +265,7 @@ test("tries to cache an explicitly requested bundle with its CLI version number"
false
);
t.assert(releaseApiMock.isDone(), "Releases API should have been called");
t.assert(toolcache.find("CodeQL", "2.10.0"));
t.assert(toolcache.find("CodeQL", "2.10.0-20200610"));
t.deepEqual(result.toolsVersion, "0.0.0-20200610");
});
});

View file

@ -521,7 +521,7 @@ export async function getCodeQLSource(
export async function downloadCodeQL(
codeqlURL: string,
cliVersion: string | undefined,
maybeCliVersion: string | undefined,
apiDetails: api.GitHubApiDetails,
variant: util.GitHubVariant,
tempDir: string,
@ -564,15 +564,19 @@ export async function downloadCodeQL(
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);
)));
// 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);
}