Skip to content

Commit

Permalink
Use the CLI version when caching the bundle in telemetry too
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Mercer committed Jan 12, 2023
1 parent 33206d2 commit 0be20e5
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/codeql.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codeql.test.js.map

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions lib/setup-codeql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/setup-codeql.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/codeql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ test("tries to cache an explicitly requested bundle with its CLI version number"
);
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");
});
});

Expand Down
26 changes: 19 additions & 7 deletions src/setup-codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ export async function downloadCodeQL(
variant: util.GitHubVariant,
tempDir: string,
logger: Logger
): Promise<string> {
): Promise<{ toolsVersion: string; codeqlFolder: string }> {
const parsedCodeQLURL = new URL(codeqlURL);
const searchParams = new URLSearchParams(parsedCodeQLURL.search);
const headers: OutgoingHttpHeaders = {
Expand Down Expand Up @@ -565,19 +565,27 @@ export async function downloadCodeQL(

const bundleVersion = getBundleVersionFromUrl(codeqlURL);
// Try to compute the CLI version for this bundle
const cliVersion =
const cliVersion: string | undefined =
maybeCliVersion ||
(variant === util.GitHubVariant.DOTCOM &&
(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
),
};
}

export function getCodeQLURLVersion(url: string): string {
Expand Down Expand Up @@ -623,6 +631,7 @@ export async function setupCodeQLBundle(
);

let codeqlFolder: string;
let toolsVersion = source.toolsVersion;
switch (source.sourceType) {
case "local":
codeqlFolder = await toolcache.extractTar(source.codeqlTarPath);
Expand All @@ -631,18 +640,21 @@ export async function setupCodeQLBundle(
codeqlFolder = source.codeqlFolder;
logger.debug(`CodeQL found in cache ${codeqlFolder}`);
break;
case "download":
codeqlFolder = await downloadCodeQL(
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 };
}

0 comments on commit 0be20e5

Please sign in to comment.