Throw configuration error when `tar` is not available

This commit is contained in:
Angela P Wen 2024-11-18 11:21:11 -08:00
Родитель a1695c562b
Коммит b500b62cea
9 изменённых файлов: 41 добавлений и 30 удалений

3
lib/setup-codeql.js сгенерированный
Просмотреть файл

@ -463,6 +463,9 @@ 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, features, defaultCliVersion, 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(toolsInput, defaultCliVersion, apiDetails, variant, zstdAvailability.available, logger);
let codeqlFolder;

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

13
lib/tar.js сгенерированный
Просмотреть файл

@ -42,17 +42,6 @@ const actions_util_1 = require("./actions-util");
const util_1 = require("./util");
const MIN_REQUIRED_BSD_TAR_VERSION = "3.4.3";
const MIN_REQUIRED_GNU_TAR_VERSION = "1.31";
async function isBinaryAccessible(binary, logger) {
try {
await (0, safe_which_1.safeWhich)(binary);
logger.debug(`Found ${binary}.`);
return true;
}
catch (e) {
logger.debug(`Could not find ${binary}: ${e}`);
return false;
}
}
async function getTarVersion() {
const tar = await (0, safe_which_1.safeWhich)("tar");
let stdout = "";
@ -86,7 +75,7 @@ async function getTarVersion() {
}
}
async function isZstdAvailable(logger) {
const foundZstdBinary = await isBinaryAccessible("zstd", logger);
const foundZstdBinary = await (0, util_1.isBinaryAccessible)("zstd", logger);
try {
const tarVersion = await getTarVersion();
const { type, version } = tarVersion;

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

13
lib/util.js сгенерированный
Просмотреть файл

@ -69,12 +69,14 @@ exports.checkActionVersion = checkActionVersion;
exports.cloneObject = cloneObject;
exports.checkSipEnablement = checkSipEnablement;
exports.cleanUpGlob = cleanUpGlob;
exports.isBinaryAccessible = isBinaryAccessible;
const fs = __importStar(require("fs"));
const os = __importStar(require("os"));
const path = __importStar(require("path"));
const util_1 = require("util");
const core = __importStar(require("@actions/core"));
const exec = __importStar(require("@actions/exec/lib/exec"));
const safe_which_1 = require("@chrisgavin/safe-which");
const check_disk_space_1 = __importDefault(require("check-disk-space"));
const del_1 = __importDefault(require("del"));
const get_folder_size_1 = __importDefault(require("get-folder-size"));
@ -926,4 +928,15 @@ async function cleanUpGlob(glob, name, logger) {
logger.warning(`Failed to clean up ${name}: ${e}.`);
}
}
async function isBinaryAccessible(binary, logger) {
try {
await (0, safe_which_1.safeWhich)(binary);
logger.debug(`Found ${binary}.`);
return true;
}
catch (e) {
logger.debug(`Could not find ${binary}: ${e}`);
return false;
}
}
//# sourceMappingURL=util.js.map

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -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(

Просмотреть файл

@ -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 = "";

Просмотреть файл

@ -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;
}
}