mirror of
https://github.com/github/codeql-action.git
synced 2026-05-07 22:30:44 +00:00
Only try zstd for specified version ranges of tar
This commit is contained in:
Generated
+36
-22
@@ -48,6 +48,8 @@ const api = __importStar(require("./api-client"));
|
||||
// creation scripts. Ensure that any changes to the format of this file are compatible with both of
|
||||
// these dependents.
|
||||
const defaults = __importStar(require("./defaults.json"));
|
||||
const feature_flags_1 = require("./feature-flags");
|
||||
const tar = __importStar(require("./tar"));
|
||||
const util = __importStar(require("./util"));
|
||||
const util_1 = require("./util");
|
||||
var ToolsSource;
|
||||
@@ -401,7 +403,7 @@ const downloadCodeQL = async function (codeqlURL, maybeBundleVersion, maybeCliVe
|
||||
logger.debug(`Finished downloading CodeQL bundle to ${archivedBundlePath} (${downloadDurationMs} ms).`);
|
||||
logger.debug("Extracting CodeQL bundle.");
|
||||
const extractionStart = perf_hooks_1.performance.now();
|
||||
const { compressionMethod, extractedBundlePath } = await extractBundle(archivedBundlePath);
|
||||
const { compressionMethod, outputPath: extractedBundlePath } = await tar.extract(archivedBundlePath);
|
||||
const extractionDurationMs = Math.round(perf_hooks_1.performance.now() - extractionStart);
|
||||
logger.debug(`Finished extracting CodeQL bundle to ${extractedBundlePath} (${extractionDurationMs} ms).`);
|
||||
await cleanUpGlob(archivedBundlePath, "CodeQL bundle archive", logger);
|
||||
@@ -467,13 +469,12 @@ function getCanonicalToolcacheVersion(cliVersion, bundleVersion, logger) {
|
||||
return cliVersion;
|
||||
}
|
||||
/**
|
||||
* Obtains the CodeQL bundle, installs it in the toolcache if appropriate, and extracts it.
|
||||
* Sets up a CodeQL bundle.
|
||||
*
|
||||
* @param checkVersion Whether to check that CodeQL CLI meets the minimum
|
||||
* version requirement. Must be set to true outside tests.
|
||||
* @returns the path to the extracted bundle, and the version of the tools
|
||||
* If `useZstdBundle` is true, and the requested CodeQL bundle needs to be downloaded,
|
||||
* this function will attempt to download a zstd-compressed bundle.
|
||||
*/
|
||||
async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, useZstdBundle, logger) {
|
||||
async function setupCodeQLBundleWithZstdOption(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, useZstdBundle, logger) {
|
||||
const source = await getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, useZstdBundle, logger);
|
||||
let codeqlFolder;
|
||||
let toolsVersion = source.toolsVersion;
|
||||
@@ -502,6 +503,35 @@ async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defau
|
||||
}
|
||||
return { codeqlFolder, toolsDownloadStatusReport, toolsSource, toolsVersion };
|
||||
}
|
||||
/**
|
||||
* Obtains the CodeQL bundle, installs it in the toolcache if appropriate, and extracts it.
|
||||
*
|
||||
* @returns the path to the extracted bundle, and the version of the tools
|
||||
*/
|
||||
async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, features, logger) {
|
||||
let zstdError = undefined;
|
||||
if (!toolsInput && (await features.getValue(feature_flags_1.Feature.ZstdBundle))) {
|
||||
try {
|
||||
if (await tar.isZstdAvailable(logger)) {
|
||||
return await setupCodeQLBundleWithZstdOption(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, true, logger);
|
||||
}
|
||||
else {
|
||||
logger.debug("Falling back to bundle compressed using gzip because the available version of tar was not " +
|
||||
"recognized or is too old.");
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
logger.info("Failed to set up bundle compressed using zstd, falling back to bundle compressed using gzip.");
|
||||
logger.debug(`Underlying error: ${e}`);
|
||||
zstdError = e;
|
||||
}
|
||||
}
|
||||
const result = await setupCodeQLBundleWithZstdOption(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, false, logger);
|
||||
if (zstdError) {
|
||||
result.toolsDownloadStatusReport = Object.assign({}, result.toolsDownloadStatusReport, { zstdError: (0, util_1.wrapError)(zstdError).message });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async function cleanUpGlob(glob, name, logger) {
|
||||
logger.debug(`Cleaning up ${name}.`);
|
||||
try {
|
||||
@@ -520,20 +550,4 @@ async function cleanUpGlob(glob, name, logger) {
|
||||
logger.warning(`Failed to clean up ${name}: ${e}.`);
|
||||
}
|
||||
}
|
||||
async function extractBundle(archivedBundlePath) {
|
||||
if (archivedBundlePath.endsWith(".tar.gz")) {
|
||||
return {
|
||||
compressionMethod: "gzip",
|
||||
// While we could also ask tar to autodetect the compression method,
|
||||
// we defensively keep the gzip call identical as requesting a gzipped
|
||||
// bundle will soon be a fallback option.
|
||||
extractedBundlePath: await toolcache.extractTar(archivedBundlePath),
|
||||
};
|
||||
}
|
||||
return {
|
||||
compressionMethod: "zstd",
|
||||
// tar will autodetect the compression method
|
||||
extractedBundlePath: await toolcache.extractTar(archivedBundlePath, undefined, "x"),
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=setup-codeql.js.map
|
||||
Reference in New Issue
Block a user