Enable zstd bundles on GHES and remove feature flag

This commit is contained in:
Henry Mercer 2024-11-01 15:24:47 +00:00
parent 48c3e26756
commit 33f2dc57a4
32 changed files with 82 additions and 154 deletions

25
lib/setup-codeql.js generated
View file

@ -205,7 +205,7 @@ async function findOverridingToolsInCache(humanReadableVersion, logger) {
}
return undefined;
}
async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, tarSupportsZstd, features, logger) {
async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, tarSupportsZstd, logger) {
if (toolsInput &&
!CODEQL_BUNDLE_VERSION_ALIAS.includes(toolsInput) &&
!toolsInput.startsWith("http")) {
@ -347,7 +347,7 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian
}
if (!url) {
url = await getCodeQLBundleDownloadURL(tagName, apiDetails, cliVersion !== undefined &&
(await useZstdBundle(cliVersion, features, tarSupportsZstd)), logger);
(await useZstdBundle(cliVersion, tarSupportsZstd)), logger);
}
if (cliVersion) {
logger.info(`Using CodeQL CLI version ${cliVersion} sourced from ${url} .`);
@ -379,7 +379,7 @@ async function tryGetFallbackToolcacheVersion(cliVersion, tagName, logger) {
}
// Exported using `export const` for testing purposes. Specifically, we want to
// be able to stub this function and have other functions in this file use that stub.
const downloadCodeQL = async function (codeqlURL, maybeBundleVersion, maybeCliVersion, apiDetails, tarVersion, tempDir, features, logger) {
const downloadCodeQL = async function (codeqlURL, maybeBundleVersion, maybeCliVersion, apiDetails, tarVersion, tempDir, logger) {
const parsedCodeQLURL = new URL(codeqlURL);
const searchParams = new URLSearchParams(parsedCodeQLURL.search);
const headers = {
@ -401,7 +401,7 @@ const downloadCodeQL = async function (codeqlURL, maybeBundleVersion, maybeCliVe
else {
logger.debug("Downloading CodeQL tools without an authorization token.");
}
const { extractedBundlePath, statusReport } = await (0, tools_download_1.downloadAndExtract)(codeqlURL, authorization, { "User-Agent": "CodeQL Action", ...headers }, tarVersion, tempDir, features, logger);
const { extractedBundlePath, statusReport } = await (0, tools_download_1.downloadAndExtract)(codeqlURL, authorization, { "User-Agent": "CodeQL Action", ...headers }, tarVersion, tempDir, logger);
const bundleVersion = maybeBundleVersion ?? tryGetBundleVersionFromUrl(codeqlURL, logger);
if (bundleVersion === undefined) {
logger.debug("Could not cache CodeQL tools because we could not determine the bundle version from the " +
@ -462,7 +462,7 @@ function getCanonicalToolcacheVersion(cliVersion, bundleVersion, logger) {
*
* @returns the path to the extracted bundle, and the version of the tools
*/
async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, features, logger) {
async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, logger) {
const zstdAvailability = await tar.isZstdAvailable(logger);
let zstdFailureReason;
// If we think the installed version of tar supports zstd, try to use zstd,
@ -473,7 +473,7 @@ async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defau
if (process.env.CODEQL_ACTION_FORCE_ZSTD_FAILURE === "true") {
throw new Error("Failing since CODEQL_ACTION_FORCE_ZSTD_FAILURE is true.");
}
return await setupCodeQLBundleWithCompressionMethod(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, features, logger, zstdAvailability, true);
return await setupCodeQLBundleWithCompressionMethod(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, logger, zstdAvailability, true);
}
catch (e) {
zstdFailureReason = util.getErrorMessage(e) || "unknown error";
@ -484,14 +484,14 @@ async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defau
logger.warning(`Failed to set up CodeQL tools with zstd. Falling back to gzipped version. Error: ${util.getErrorMessage(e)}`);
}
}
const result = await setupCodeQLBundleWithCompressionMethod(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, features, logger, zstdAvailability, false);
const result = await setupCodeQLBundleWithCompressionMethod(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, logger, zstdAvailability, false);
if (result.toolsDownloadStatusReport && zstdFailureReason) {
result.toolsDownloadStatusReport.zstdFailureReason = zstdFailureReason;
}
return result;
}
async function setupCodeQLBundleWithCompressionMethod(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, features, logger, zstdAvailability, useTarIfAvailable) {
const source = await getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, useTarIfAvailable, features, logger);
async function setupCodeQLBundleWithCompressionMethod(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, logger, zstdAvailability, useTarIfAvailable) {
const source = await getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, useTarIfAvailable, logger);
let codeqlFolder;
let toolsVersion = source.toolsVersion;
let toolsDownloadStatusReport;
@ -509,7 +509,7 @@ async function setupCodeQLBundleWithCompressionMethod(toolsInput, apiDetails, te
toolsSource = ToolsSource.Toolcache;
break;
case "download": {
const result = await (0, exports.downloadCodeQL)(source.codeqlURL, source.bundleVersion, source.cliVersion, apiDetails, zstdAvailability.version, tempDir, features, logger);
const result = await (0, exports.downloadCodeQL)(source.codeqlURL, source.bundleVersion, source.cliVersion, apiDetails, zstdAvailability.version, tempDir, logger);
toolsVersion = result.toolsVersion;
codeqlFolder = result.codeqlFolder;
toolsDownloadStatusReport = result.statusReport;
@ -527,12 +527,11 @@ async function setupCodeQLBundleWithCompressionMethod(toolsInput, apiDetails, te
zstdAvailability,
};
}
async function useZstdBundle(cliVersion, features, tarSupportsZstd) {
async function useZstdBundle(cliVersion, tarSupportsZstd) {
return (
// In testing, gzip performs better than zstd on Windows.
process.platform !== "win32" &&
tarSupportsZstd &&
semver.gte(cliVersion, feature_flags_1.CODEQL_VERSION_ZSTD_BUNDLE) &&
!!(await features.getValue(feature_flags_1.Feature.ZstdBundle)));
semver.gte(cliVersion, feature_flags_1.CODEQL_VERSION_ZSTD_BUNDLE));
}
//# sourceMappingURL=setup-codeql.js.map