Skip to content

Commit

Permalink
Include the bundle version in the toolcache version number
Browse files Browse the repository at this point in the history
This gives us an easy cache hit when requesting the same tools URL.
  • Loading branch information
Henry Mercer committed Jan 12, 2023
1 parent c2e39e0 commit 33206d2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 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.

14 changes: 9 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 @@ -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");
});
});
Expand Down
16 changes: 10 additions & 6 deletions src/setup-codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 33206d2

Please sign in to comment.