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

View file

@ -5,6 +5,7 @@ import * as stream from "stream";
import { ToolRunner } from "@actions/exec/lib/toolrunner";
import * as io from "@actions/io";
import * as toolcache from "@actions/tool-cache";
import * as semver from "semver";
import { CommandInvocationError } from "./actions-util";
import { Logger } from "./logging";
@ -68,13 +69,23 @@ export async function isZstdAvailable(
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,
};
@ -202,9 +213,18 @@ export async function extractTarZst(
}
}
export function inferCompressionMethod(tarPath: string): CompressionMethod {
if (tarPath.endsWith(".tar.gz")) {
return "gzip";
const KNOWN_EXTENSIONS: Record<string, CompressionMethod> = {
"tar.gz": "gzip",
"tar.zst": "zstd",
};
export function inferCompressionMethod(
tarPath: string,
): CompressionMethod | undefined {
for (const [ext, method] of Object.entries(KNOWN_EXTENSIONS)) {
if (tarPath.endsWith(`.${ext}`)) {
return method;
}
}
return "zstd";
return undefined;
}