Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw configuration error when tar is not available #2611

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/setup-codeql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/setup-codeql.js.map

Large diffs are not rendered by default.

13 changes: 1 addition & 12 deletions lib/tar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/tar.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions lib/util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/util.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/setup-codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 1 addition & 15 deletions src/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 = "";
Expand Down
15 changes: 15 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}
}
Loading