Throw configuration error when tar is not available

This commit is contained in:
Angela P Wen 2024-11-18 11:21:11 -08:00
parent a1695c562b
commit b500b62cea
9 changed files with 41 additions and 30 deletions

View file

@ -653,6 +653,11 @@ export async function setupCodeQLBundle(
defaultCliVersion: CodeQLDefaultVersionInfo,
logger: Logger,
) {
if (!(await util.isBinaryAccessible("tar", logger))) {
throw new util.ConfigurationError(
"Could not find tar in PATH, so unable to extract CodeQL bundle.",
);
}
const zstdAvailability = await tar.isZstdAvailable(logger);
const source = await getCodeQLSource(

View file

@ -10,7 +10,7 @@ import { v4 as uuidV4 } from "uuid";
import { CommandInvocationError, getTemporaryDirectory } from "./actions-util";
import { Logger } from "./logging";
import { assertNever, cleanUpGlob } from "./util";
import { assertNever, cleanUpGlob, isBinaryAccessible } from "./util";
const MIN_REQUIRED_BSD_TAR_VERSION = "3.4.3";
const MIN_REQUIRED_GNU_TAR_VERSION = "1.31";
@ -20,20 +20,6 @@ export type TarVersion = {
version: string;
};
async function isBinaryAccessible(
binary: string,
logger: Logger,
): Promise<boolean> {
try {
await safeWhich(binary);
logger.debug(`Found ${binary}.`);
return true;
} catch (e) {
logger.debug(`Could not find ${binary}: ${e}`);
return false;
}
}
async function getTarVersion(): Promise<TarVersion> {
const tar = await safeWhich("tar");
let stdout = "";

View file

@ -5,6 +5,7 @@ import { promisify } from "util";
import * as core from "@actions/core";
import * as exec from "@actions/exec/lib/exec";
import { safeWhich } from "@chrisgavin/safe-which";
import checkDiskSpace from "check-disk-space";
import del from "del";
import getFolderSize from "get-folder-size";
@ -1187,3 +1188,17 @@ export async function cleanUpGlob(glob: string, name: string, logger: Logger) {
logger.warning(`Failed to clean up ${name}: ${e}.`);
}
}
export async function isBinaryAccessible(
binary: string,
logger: Logger,
): Promise<boolean> {
try {
await safeWhich(binary);
logger.debug(`Found ${binary}.`);
return true;
} catch (e) {
logger.debug(`Could not find ${binary}: ${e}`);
return false;
}
}