Remove fallback logic for mapping default CLI version to GitHub Release
The default version feature flags will now always point to a CLI version with a semantically versioned bundle, so we can find the GitHub Release directly from the CLI version.
This commit is contained in:
parent
395fdba990
commit
bec18d1625
18 changed files with 106 additions and 401 deletions
67
lib/setup-codeql.js
generated
67
lib/setup-codeql.js
generated
|
|
@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.setupCodeQLBundle = exports.getCodeQLURLVersion = exports.downloadCodeQL = exports.tryGetFallbackToolcacheVersion = exports.getCodeQLSource = exports.convertToSemVer = exports.tryGetBundleVersionFromUrl = exports.tryFindCliVersionDotcomOnly = exports.findCodeQLBundleTagDotcomOnly = exports.getCodeQLActionRepository = exports.CODEQL_DEFAULT_ACTION_REPOSITORY = void 0;
|
||||
exports.setupCodeQLBundle = exports.getCodeQLURLVersion = exports.downloadCodeQL = exports.tryGetFallbackToolcacheVersion = exports.getCodeQLSource = exports.convertToSemVer = exports.tryGetBundleVersionFromUrl = exports.tryFindCliVersionDotcomOnly = exports.getCodeQLActionRepository = exports.CODEQL_DEFAULT_ACTION_REPOSITORY = void 0;
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const perf_hooks_1 = require("perf_hooks");
|
||||
|
|
@ -71,34 +71,6 @@ function getCodeQLActionRepository(logger) {
|
|||
return util.getRequiredEnvParam("GITHUB_ACTION_REPOSITORY");
|
||||
}
|
||||
exports.getCodeQLActionRepository = getCodeQLActionRepository;
|
||||
/**
|
||||
* Gets the tag name and, if known, the CodeQL CLI version for each CodeQL bundle release.
|
||||
*
|
||||
* CodeQL bundles are currently tagged in the form `codeql-bundle-yyyymmdd`, so it is not possible
|
||||
* to directly find the CodeQL bundle release for a particular CLI version or find the CodeQL CLI
|
||||
* version for a particular CodeQL bundle.
|
||||
*
|
||||
* To get around this, we add a `cli-version-x.y.z.txt` asset to each bundle release that specifies
|
||||
* the CLI version for that bundle release. We can then use the GitHub Releases for the CodeQL
|
||||
* Action as a source of truth.
|
||||
*
|
||||
* In the medium term, we should migrate to a tagging scheme that allows us to directly find the
|
||||
* CodeQL bundle release for a particular CLI version, for example `codeql-bundle-vx.y.z`.
|
||||
*/
|
||||
async function getCodeQLBundleReleasesDotcomOnly(logger) {
|
||||
logger.debug(`Fetching CodeQL CLI version and CodeQL bundle tag name information for releases of the CodeQL tools.`);
|
||||
const apiClient = api.getApiClient();
|
||||
const codeQLActionRepository = getCodeQLActionRepository(logger);
|
||||
const releases = await apiClient.paginate(apiClient.repos.listReleases, {
|
||||
owner: codeQLActionRepository.split("/")[0],
|
||||
repo: codeQLActionRepository.split("/")[1],
|
||||
});
|
||||
logger.debug(`Found ${releases.length} releases.`);
|
||||
return releases.map((release) => ({
|
||||
cliVersion: tryGetCodeQLCliVersionForRelease(release, logger),
|
||||
tagName: release.tag_name,
|
||||
}));
|
||||
}
|
||||
function tryGetCodeQLCliVersionForRelease(release, logger) {
|
||||
const cliVersionsFromMarkerFiles = release.assets
|
||||
.map((asset) => asset.name.match(/cli-version-(.*)\.txt/)?.[1])
|
||||
|
|
@ -114,18 +86,6 @@ function tryGetCodeQLCliVersionForRelease(release, logger) {
|
|||
}
|
||||
return cliVersionsFromMarkerFiles[0];
|
||||
}
|
||||
async function findCodeQLBundleTagDotcomOnly(cliVersion, logger) {
|
||||
const filtered = (await getCodeQLBundleReleasesDotcomOnly(logger)).filter((release) => release.cliVersion === cliVersion);
|
||||
if (filtered.length === 0) {
|
||||
throw new Error(`Failed to find a release of the CodeQL tools that contains CodeQL CLI ${cliVersion}.`);
|
||||
}
|
||||
else if (filtered.length > 1) {
|
||||
throw new Error(`Found multiple releases of the CodeQL tools that contain CodeQL CLI ${cliVersion}. ` +
|
||||
`Only one such release should exist.`);
|
||||
}
|
||||
return filtered[0].tagName;
|
||||
}
|
||||
exports.findCodeQLBundleTagDotcomOnly = findCodeQLBundleTagDotcomOnly;
|
||||
async function tryFindCliVersionDotcomOnly(tagName, logger) {
|
||||
try {
|
||||
logger.debug(`Fetching the GitHub Release for the CodeQL bundle tagged ${tagName}.`);
|
||||
|
|
@ -368,9 +328,9 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian
|
|||
}
|
||||
}
|
||||
// Fall back to matching `0.0.0-<bundleVersion>`.
|
||||
if (!codeqlFolder && (cliVersion || tagName)) {
|
||||
if (cliVersion || tagName) {
|
||||
const fallbackVersion = await tryGetFallbackToolcacheVersion(cliVersion, tagName, variant, logger);
|
||||
if (!codeqlFolder && tagName) {
|
||||
if (tagName) {
|
||||
const fallbackVersion = await tryGetFallbackToolcacheVersion(cliVersion, tagName, logger);
|
||||
if (fallbackVersion) {
|
||||
codeqlFolder = toolcache.find("CodeQL", fallbackVersion);
|
||||
}
|
||||
|
|
@ -380,8 +340,8 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian
|
|||
}
|
||||
}
|
||||
else {
|
||||
logger.debug("Both the CLI version and the bundle version are unknown, so we will not be able to find " +
|
||||
"the requested version of the CodeQL tools in the toolcache.");
|
||||
logger.debug("Could not determine a fallback toolcache version number for CodeQL tools version " +
|
||||
`${humanReadableVersion} since the tag name is unknown.`);
|
||||
}
|
||||
}
|
||||
if (codeqlFolder) {
|
||||
|
|
@ -409,13 +369,6 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian
|
|||
}
|
||||
}
|
||||
if (!url) {
|
||||
if (!tagName && cliVersion && variant === util.GitHubVariant.DOTCOM) {
|
||||
tagName = await findCodeQLBundleTagDotcomOnly(cliVersion, logger);
|
||||
}
|
||||
else if (!tagName) {
|
||||
throw new Error(`Could not obtain the requested version (${humanReadableVersion}) of the CodeQL tools ` +
|
||||
"since we could not compute the tag name.");
|
||||
}
|
||||
url = await getCodeQLBundleDownloadURL(tagName, apiDetails, variant, logger);
|
||||
}
|
||||
return {
|
||||
|
|
@ -431,13 +384,7 @@ exports.getCodeQLSource = getCodeQLSource;
|
|||
* Gets a fallback version number to use when looking for CodeQL in the toolcache if we didn't find
|
||||
* the `x.y.z` version. This is to support old versions of the toolcache.
|
||||
*/
|
||||
async function tryGetFallbackToolcacheVersion(cliVersion, tagName, variant, logger) {
|
||||
//
|
||||
// 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.
|
||||
if (cliVersion && !tagName && variant === util.GitHubVariant.DOTCOM) {
|
||||
tagName = await findCodeQLBundleTagDotcomOnly(cliVersion, logger);
|
||||
}
|
||||
async function tryGetFallbackToolcacheVersion(cliVersion, tagName, logger) {
|
||||
if (!tagName) {
|
||||
return undefined;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue