Merge pull request #2611 from github/angelapwen/catch-tar-error
Throw configuration error when `tar` is not available
This commit is contained in:
commit
9222a972b5
9 changed files with 41 additions and 30 deletions
3
lib/setup-codeql.js
generated
3
lib/setup-codeql.js
generated
|
|
@ -463,6 +463,9 @@ function getCanonicalToolcacheVersion(cliVersion, bundleVersion, logger) {
|
||||||
* @returns the path to the extracted bundle, and the version of the tools
|
* @returns the path to the extracted bundle, and the version of the tools
|
||||||
*/
|
*/
|
||||||
async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, features, defaultCliVersion, logger) {
|
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 zstdAvailability = await tar.isZstdAvailable(logger);
|
||||||
const source = await getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, zstdAvailability.available, logger);
|
const source = await getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, zstdAvailability.available, logger);
|
||||||
let codeqlFolder;
|
let codeqlFolder;
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
13
lib/tar.js
generated
13
lib/tar.js
generated
|
|
@ -42,17 +42,6 @@ const actions_util_1 = require("./actions-util");
|
||||||
const util_1 = require("./util");
|
const util_1 = require("./util");
|
||||||
const MIN_REQUIRED_BSD_TAR_VERSION = "3.4.3";
|
const MIN_REQUIRED_BSD_TAR_VERSION = "3.4.3";
|
||||||
const MIN_REQUIRED_GNU_TAR_VERSION = "1.31";
|
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() {
|
async function getTarVersion() {
|
||||||
const tar = await (0, safe_which_1.safeWhich)("tar");
|
const tar = await (0, safe_which_1.safeWhich)("tar");
|
||||||
let stdout = "";
|
let stdout = "";
|
||||||
|
|
@ -86,7 +75,7 @@ async function getTarVersion() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function isZstdAvailable(logger) {
|
async function isZstdAvailable(logger) {
|
||||||
const foundZstdBinary = await isBinaryAccessible("zstd", logger);
|
const foundZstdBinary = await (0, util_1.isBinaryAccessible)("zstd", logger);
|
||||||
try {
|
try {
|
||||||
const tarVersion = await getTarVersion();
|
const tarVersion = await getTarVersion();
|
||||||
const { type, version } = tarVersion;
|
const { type, version } = tarVersion;
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
13
lib/util.js
generated
13
lib/util.js
generated
|
|
@ -69,12 +69,14 @@ exports.checkActionVersion = checkActionVersion;
|
||||||
exports.cloneObject = cloneObject;
|
exports.cloneObject = cloneObject;
|
||||||
exports.checkSipEnablement = checkSipEnablement;
|
exports.checkSipEnablement = checkSipEnablement;
|
||||||
exports.cleanUpGlob = cleanUpGlob;
|
exports.cleanUpGlob = cleanUpGlob;
|
||||||
|
exports.isBinaryAccessible = isBinaryAccessible;
|
||||||
const fs = __importStar(require("fs"));
|
const fs = __importStar(require("fs"));
|
||||||
const os = __importStar(require("os"));
|
const os = __importStar(require("os"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
const util_1 = require("util");
|
const util_1 = require("util");
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const exec = __importStar(require("@actions/exec/lib/exec"));
|
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 check_disk_space_1 = __importDefault(require("check-disk-space"));
|
||||||
const del_1 = __importDefault(require("del"));
|
const del_1 = __importDefault(require("del"));
|
||||||
const get_folder_size_1 = __importDefault(require("get-folder-size"));
|
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}.`);
|
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
|
//# sourceMappingURL=util.js.map
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -653,6 +653,11 @@ export async function setupCodeQLBundle(
|
||||||
defaultCliVersion: CodeQLDefaultVersionInfo,
|
defaultCliVersion: CodeQLDefaultVersionInfo,
|
||||||
logger: Logger,
|
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 zstdAvailability = await tar.isZstdAvailable(logger);
|
||||||
|
|
||||||
const source = await getCodeQLSource(
|
const source = await getCodeQLSource(
|
||||||
|
|
|
||||||
16
src/tar.ts
16
src/tar.ts
|
|
@ -10,7 +10,7 @@ import { v4 as uuidV4 } from "uuid";
|
||||||
|
|
||||||
import { CommandInvocationError, getTemporaryDirectory } from "./actions-util";
|
import { CommandInvocationError, getTemporaryDirectory } from "./actions-util";
|
||||||
import { Logger } from "./logging";
|
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_BSD_TAR_VERSION = "3.4.3";
|
||||||
const MIN_REQUIRED_GNU_TAR_VERSION = "1.31";
|
const MIN_REQUIRED_GNU_TAR_VERSION = "1.31";
|
||||||
|
|
@ -20,20 +20,6 @@ export type TarVersion = {
|
||||||
version: string;
|
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> {
|
async function getTarVersion(): Promise<TarVersion> {
|
||||||
const tar = await safeWhich("tar");
|
const tar = await safeWhich("tar");
|
||||||
let stdout = "";
|
let stdout = "";
|
||||||
|
|
|
||||||
15
src/util.ts
15
src/util.ts
|
|
@ -5,6 +5,7 @@ import { promisify } from "util";
|
||||||
|
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as exec from "@actions/exec/lib/exec";
|
import * as exec from "@actions/exec/lib/exec";
|
||||||
|
import { safeWhich } from "@chrisgavin/safe-which";
|
||||||
import checkDiskSpace from "check-disk-space";
|
import checkDiskSpace from "check-disk-space";
|
||||||
import del from "del";
|
import del from "del";
|
||||||
import getFolderSize from "get-folder-size";
|
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}.`);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue