Allow using a x.y.z-yyyymmdd toolcache version for CLI x.y.z.
This commit is contained in:
parent
e8c12e1f7d
commit
648838c4a0
6 changed files with 100 additions and 17 deletions
25
lib/codeql.test.js
generated
25
lib/codeql.test.js
generated
|
|
@ -147,14 +147,31 @@ async function installIntoToolcache({ apiDetails = sampleApiDetails, cliVersion,
|
||||||
t.deepEqual(result.toolsVersion, "0.0.0-20200610");
|
t.deepEqual(result.toolsVersion, "0.0.0-20200610");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
for (const isCached of [true, false]) {
|
for (const { isCached, tagName, toolcacheCliVersion } of [
|
||||||
(0, ava_1.default)(`uses default version on Dotcom when default version bundle is ${isCached ? "" : "not "}cached`, async (t) => {
|
{
|
||||||
|
isCached: true,
|
||||||
|
tagName: "codeql-bundle-20230101",
|
||||||
|
toolcacheCliVersion: SAMPLE_DEFAULT_CLI_VERSION.cliVersion,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
isCached: true,
|
||||||
|
// By leaving toolcacheCliVersion undefined, the bundle will be installed
|
||||||
|
// into the toolcache as `${SAMPLE_DEFAULT_CLI_VERSION.cliVersion}-20230101`.
|
||||||
|
// This lets us test that `x.y.z-yyyymmdd` toolcache versions are used if an
|
||||||
|
// `x.y.z` version isn't in the toolcache.
|
||||||
|
tagName: `codeql-bundle-${SAMPLE_DEFAULT_CLI_VERSION.cliVersion}-20230101`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
isCached: false,
|
||||||
|
tagName: "codeql-bundle-20230101",
|
||||||
|
},
|
||||||
|
]) {
|
||||||
|
(0, ava_1.default)(`uses default version on Dotcom when default version bundle ${tagName} is ${isCached ? "" : "not "}cached`, async (t) => {
|
||||||
await util.withTmpDir(async (tmpDir) => {
|
await util.withTmpDir(async (tmpDir) => {
|
||||||
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
|
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
|
||||||
const tagName = `codeql-bundle-20230101`;
|
|
||||||
if (isCached) {
|
if (isCached) {
|
||||||
await installIntoToolcache({
|
await installIntoToolcache({
|
||||||
cliVersion: SAMPLE_DEFAULT_CLI_VERSION.cliVersion,
|
cliVersion: toolcacheCliVersion,
|
||||||
tagName,
|
tagName,
|
||||||
isPinned: true,
|
isPinned: true,
|
||||||
tmpDir,
|
tmpDir,
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
26
lib/setup-codeql.js
generated
26
lib/setup-codeql.js
generated
|
|
@ -250,8 +250,8 @@ async function getCodeQLSource(toolsInput, bypassToolcache, defaultCliVersion, a
|
||||||
* We include a `variant` property to let us verify using the type system that
|
* We include a `variant` property to let us verify using the type system that
|
||||||
* `tagName` is only undefined when the variant is Dotcom. This lets us ensure
|
* `tagName` is only undefined when the variant is Dotcom. This lets us ensure
|
||||||
* that we can always compute `tagName`, either by using the existing tag name
|
* that we can always compute `tagName`, either by using the existing tag name
|
||||||
* on enterprise instances, or safely calling `findCodeQLBundleTagDotcomOnly`
|
* on enterprise instances, or calling `findCodeQLBundleTagDotcomOnly` on
|
||||||
* on Dotcom.
|
* Dotcom.
|
||||||
*/
|
*/
|
||||||
const requestedVersion = forceLatest
|
const requestedVersion = forceLatest
|
||||||
? // case 1
|
? // case 1
|
||||||
|
|
@ -273,13 +273,33 @@ async function getCodeQLSource(toolsInput, bypassToolcache, defaultCliVersion, a
|
||||||
// If we find the specified version, we always use that.
|
// If we find the specified version, we always use that.
|
||||||
let codeqlFolder = toolcache.find("CodeQL", requestedVersion.cliVersion);
|
let codeqlFolder = toolcache.find("CodeQL", requestedVersion.cliVersion);
|
||||||
let tagName = requestedVersion["tagName"];
|
let tagName = requestedVersion["tagName"];
|
||||||
|
if (!codeqlFolder) {
|
||||||
|
logger.debug("Didn't find a version of the CodeQL tools in the toolcache with a version number " +
|
||||||
|
`exactly matching ${requestedVersion.cliVersion}.`);
|
||||||
|
const allVersions = toolcache.findAllVersions("CodeQL");
|
||||||
|
logger.debug(`Found the following versions of the CodeQL tools in the toolcache: ${JSON.stringify(allVersions)}.`);
|
||||||
|
// If there is exactly one version of the CodeQL tools in the toolcache, and that version is
|
||||||
|
// the form `x.y.z-<tagName>`, then use it.
|
||||||
|
const candidateVersions = allVersions.filter((version) => version.startsWith(`${requestedVersion.cliVersion}-`));
|
||||||
|
if (candidateVersions.length === 1) {
|
||||||
|
logger.debug("Exactly one candidate version found, using that.");
|
||||||
|
codeqlFolder = toolcache.find("CodeQL", candidateVersions[0]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logger.debug("Did not find exactly one version of the CodeQL tools starting with the requested version.");
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!codeqlFolder && !requestedVersion.cliVersion.startsWith("0.0.0")) {
|
if (!codeqlFolder && !requestedVersion.cliVersion.startsWith("0.0.0")) {
|
||||||
// Fall back to accepting a `0.0.0-<tagName>` version if we didn't find the
|
// Fall back to accepting a `0.0.0-<tagName>` version if we didn't find the
|
||||||
// `x.y.z` version. This is to support old versions of the toolcache.
|
// `x.y.z` version. This is to support old versions of the toolcache.
|
||||||
|
//
|
||||||
|
// If we are on Dotcom, we will make an HTTP request to the Releases API here
|
||||||
|
// to find the tag name for the requested version.
|
||||||
tagName =
|
tagName =
|
||||||
tagName || (await getOrFindBundleTagName(requestedVersion, logger));
|
tagName || (await getOrFindBundleTagName(requestedVersion, logger));
|
||||||
const fallbackVersion = convertToSemVer(tagName, logger);
|
const fallbackVersion = convertToSemVer(tagName, logger);
|
||||||
logger.debug(`Computed a fallback toolcache version number of ${fallbackVersion} for CodeQL tools version ${requestedVersion.cliVersion}.`);
|
logger.debug(`Computed a fallback toolcache version number of ${fallbackVersion} for CodeQL tools version ` +
|
||||||
|
`${requestedVersion.cliVersion}.`);
|
||||||
codeqlFolder = toolcache.find("CodeQL", fallbackVersion);
|
codeqlFolder = toolcache.find("CodeQL", fallbackVersion);
|
||||||
}
|
}
|
||||||
if (codeqlFolder) {
|
if (codeqlFolder) {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -204,18 +204,34 @@ test("downloads an explicitly requested bundle even if a different version is ca
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const isCached of [true, false]) {
|
for (const { isCached, tagName, toolcacheCliVersion } of [
|
||||||
test(`uses default version on Dotcom when default version bundle is ${
|
{
|
||||||
|
isCached: true,
|
||||||
|
tagName: "codeql-bundle-20230101",
|
||||||
|
toolcacheCliVersion: SAMPLE_DEFAULT_CLI_VERSION.cliVersion,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
isCached: true,
|
||||||
|
// By leaving toolcacheCliVersion undefined, the bundle will be installed
|
||||||
|
// into the toolcache as `${SAMPLE_DEFAULT_CLI_VERSION.cliVersion}-20230101`.
|
||||||
|
// This lets us test that `x.y.z-yyyymmdd` toolcache versions are used if an
|
||||||
|
// `x.y.z` version isn't in the toolcache.
|
||||||
|
tagName: `codeql-bundle-${SAMPLE_DEFAULT_CLI_VERSION.cliVersion}-20230101`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
isCached: false,
|
||||||
|
tagName: "codeql-bundle-20230101",
|
||||||
|
},
|
||||||
|
]) {
|
||||||
|
test(`uses default version on Dotcom when default version bundle ${tagName} is ${
|
||||||
isCached ? "" : "not "
|
isCached ? "" : "not "
|
||||||
}cached`, async (t) => {
|
}cached`, async (t) => {
|
||||||
await util.withTmpDir(async (tmpDir) => {
|
await util.withTmpDir(async (tmpDir) => {
|
||||||
setupActionsVars(tmpDir, tmpDir);
|
setupActionsVars(tmpDir, tmpDir);
|
||||||
|
|
||||||
const tagName = `codeql-bundle-20230101`;
|
|
||||||
|
|
||||||
if (isCached) {
|
if (isCached) {
|
||||||
await installIntoToolcache({
|
await installIntoToolcache({
|
||||||
cliVersion: SAMPLE_DEFAULT_CLI_VERSION.cliVersion,
|
cliVersion: toolcacheCliVersion,
|
||||||
tagName,
|
tagName,
|
||||||
isPinned: true,
|
isPinned: true,
|
||||||
tmpDir,
|
tmpDir,
|
||||||
|
|
|
||||||
|
|
@ -311,8 +311,8 @@ export async function getCodeQLSource(
|
||||||
* We include a `variant` property to let us verify using the type system that
|
* We include a `variant` property to let us verify using the type system that
|
||||||
* `tagName` is only undefined when the variant is Dotcom. This lets us ensure
|
* `tagName` is only undefined when the variant is Dotcom. This lets us ensure
|
||||||
* that we can always compute `tagName`, either by using the existing tag name
|
* that we can always compute `tagName`, either by using the existing tag name
|
||||||
* on enterprise instances, or safely calling `findCodeQLBundleTagDotcomOnly`
|
* on enterprise instances, or calling `findCodeQLBundleTagDotcomOnly` on
|
||||||
* on Dotcom.
|
* Dotcom.
|
||||||
*/
|
*/
|
||||||
const requestedVersion = forceLatest
|
const requestedVersion = forceLatest
|
||||||
? // case 1
|
? // case 1
|
||||||
|
|
@ -339,14 +339,44 @@ export async function getCodeQLSource(
|
||||||
let codeqlFolder = toolcache.find("CodeQL", requestedVersion.cliVersion);
|
let codeqlFolder = toolcache.find("CodeQL", requestedVersion.cliVersion);
|
||||||
let tagName: string | undefined = requestedVersion["tagName"];
|
let tagName: string | undefined = requestedVersion["tagName"];
|
||||||
|
|
||||||
|
if (!codeqlFolder) {
|
||||||
|
logger.debug(
|
||||||
|
"Didn't find a version of the CodeQL tools in the toolcache with a version number " +
|
||||||
|
`exactly matching ${requestedVersion.cliVersion}.`
|
||||||
|
);
|
||||||
|
const allVersions = toolcache.findAllVersions("CodeQL");
|
||||||
|
logger.debug(
|
||||||
|
`Found the following versions of the CodeQL tools in the toolcache: ${JSON.stringify(
|
||||||
|
allVersions
|
||||||
|
)}.`
|
||||||
|
);
|
||||||
|
// If there is exactly one version of the CodeQL tools in the toolcache, and that version is
|
||||||
|
// the form `x.y.z-<tagName>`, then use it.
|
||||||
|
const candidateVersions = allVersions.filter((version) =>
|
||||||
|
version.startsWith(`${requestedVersion.cliVersion}-`)
|
||||||
|
);
|
||||||
|
if (candidateVersions.length === 1) {
|
||||||
|
logger.debug("Exactly one candidate version found, using that.");
|
||||||
|
codeqlFolder = toolcache.find("CodeQL", candidateVersions[0]);
|
||||||
|
} else {
|
||||||
|
logger.debug(
|
||||||
|
"Did not find exactly one version of the CodeQL tools starting with the requested version."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!codeqlFolder && !requestedVersion.cliVersion.startsWith("0.0.0")) {
|
if (!codeqlFolder && !requestedVersion.cliVersion.startsWith("0.0.0")) {
|
||||||
// Fall back to accepting a `0.0.0-<tagName>` version if we didn't find the
|
// Fall back to accepting a `0.0.0-<tagName>` version if we didn't find the
|
||||||
// `x.y.z` version. This is to support old versions of the toolcache.
|
// `x.y.z` version. This is to support old versions of the toolcache.
|
||||||
|
//
|
||||||
|
// If we are on Dotcom, we will make an HTTP request to the Releases API here
|
||||||
|
// to find the tag name for the requested version.
|
||||||
tagName =
|
tagName =
|
||||||
tagName || (await getOrFindBundleTagName(requestedVersion, logger));
|
tagName || (await getOrFindBundleTagName(requestedVersion, logger));
|
||||||
const fallbackVersion = convertToSemVer(tagName, logger);
|
const fallbackVersion = convertToSemVer(tagName, logger);
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`Computed a fallback toolcache version number of ${fallbackVersion} for CodeQL tools version ${requestedVersion.cliVersion}.`
|
`Computed a fallback toolcache version number of ${fallbackVersion} for CodeQL tools version ` +
|
||||||
|
`${requestedVersion.cliVersion}.`
|
||||||
);
|
);
|
||||||
codeqlFolder = toolcache.find("CodeQL", fallbackVersion);
|
codeqlFolder = toolcache.find("CodeQL", fallbackVersion);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue