Fix assumption that download URLs contain file extension

This is not the case when downloading the bundle from a GitHub Release synced to GHES with the CodeQL Action sync tool.
This commit is contained in:
Henry Mercer 2025-01-22 12:25:58 +00:00
parent f89b8a7d52
commit d23f49f56f
9 changed files with 139 additions and 47 deletions

22
lib/tar.js generated
View file

@ -43,6 +43,7 @@ const stream = __importStar(require("stream"));
const toolrunner_1 = require("@actions/exec/lib/toolrunner");
const io = __importStar(require("@actions/io"));
const toolcache = __importStar(require("@actions/tool-cache"));
const semver = __importStar(require("semver"));
const actions_util_1 = require("./actions-util");
const util_1 = require("./util");
const MIN_REQUIRED_BSD_TAR_VERSION = "3.4.3";
@ -88,13 +89,18 @@ async function isZstdAvailable(logger) {
switch (type) {
case "gnu":
return {
available: foundZstdBinary && version >= MIN_REQUIRED_GNU_TAR_VERSION,
available: foundZstdBinary &&
// GNU tar only uses major and minor version numbers
semver.gte(semver.coerce(version), semver.coerce(MIN_REQUIRED_GNU_TAR_VERSION)),
foundZstdBinary,
version: tarVersion,
};
case "bsd":
return {
available: foundZstdBinary && version >= MIN_REQUIRED_BSD_TAR_VERSION,
available: foundZstdBinary &&
// Do a loose comparison since these version numbers don't contain
// a patch version number.
semver.gte(version, MIN_REQUIRED_BSD_TAR_VERSION),
foundZstdBinary,
version: tarVersion,
};
@ -179,10 +185,16 @@ async function extractTarZst(tar, dest, tarVersion, logger) {
throw e;
}
}
const KNOWN_EXTENSIONS = {
"tar.gz": "gzip",
"tar.zst": "zstd",
};
function inferCompressionMethod(tarPath) {
if (tarPath.endsWith(".tar.gz")) {
return "gzip";
for (const [ext, method] of Object.entries(KNOWN_EXTENSIONS)) {
if (tarPath.endsWith(`.${ext}`)) {
return method;
}
}
return "zstd";
return undefined;
}
//# sourceMappingURL=tar.js.map