Skip to content

Commit b500b62

Browse files
committed
Throw configuration error when tar is not available
1 parent a1695c5 commit b500b62

9 files changed

+41
-30
lines changed

lib/setup-codeql.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/setup-codeql.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tar.js

+1-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tar.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/setup-codeql.ts

+5
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,11 @@ export async function setupCodeQLBundle(
653653
defaultCliVersion: CodeQLDefaultVersionInfo,
654654
logger: Logger,
655655
) {
656+
if (!(await util.isBinaryAccessible("tar", logger))) {
657+
throw new util.ConfigurationError(
658+
"Could not find tar in PATH, so unable to extract CodeQL bundle.",
659+
);
660+
}
656661
const zstdAvailability = await tar.isZstdAvailable(logger);
657662

658663
const source = await getCodeQLSource(

src/tar.ts

+1-15
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { v4 as uuidV4 } from "uuid";
1010

1111
import { CommandInvocationError, getTemporaryDirectory } from "./actions-util";
1212
import { Logger } from "./logging";
13-
import { assertNever, cleanUpGlob } from "./util";
13+
import { assertNever, cleanUpGlob, isBinaryAccessible } from "./util";
1414

1515
const MIN_REQUIRED_BSD_TAR_VERSION = "3.4.3";
1616
const MIN_REQUIRED_GNU_TAR_VERSION = "1.31";
@@ -20,20 +20,6 @@ export type TarVersion = {
2020
version: string;
2121
};
2222

23-
async function isBinaryAccessible(
24-
binary: string,
25-
logger: Logger,
26-
): Promise<boolean> {
27-
try {
28-
await safeWhich(binary);
29-
logger.debug(`Found ${binary}.`);
30-
return true;
31-
} catch (e) {
32-
logger.debug(`Could not find ${binary}: ${e}`);
33-
return false;
34-
}
35-
}
36-
3723
async function getTarVersion(): Promise<TarVersion> {
3824
const tar = await safeWhich("tar");
3925
let stdout = "";

src/util.ts

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { promisify } from "util";
55

66
import * as core from "@actions/core";
77
import * as exec from "@actions/exec/lib/exec";
8+
import { safeWhich } from "@chrisgavin/safe-which";
89
import checkDiskSpace from "check-disk-space";
910
import del from "del";
1011
import getFolderSize from "get-folder-size";
@@ -1187,3 +1188,17 @@ export async function cleanUpGlob(glob: string, name: string, logger: Logger) {
11871188
logger.warning(`Failed to clean up ${name}: ${e}.`);
11881189
}
11891190
}
1191+
1192+
export async function isBinaryAccessible(
1193+
binary: string,
1194+
logger: Logger,
1195+
): Promise<boolean> {
1196+
try {
1197+
await safeWhich(binary);
1198+
logger.debug(`Found ${binary}.`);
1199+
return true;
1200+
} catch (e) {
1201+
logger.debug(`Could not find ${binary}: ${e}`);
1202+
return false;
1203+
}
1204+
}

0 commit comments

Comments
 (0)