Skip to content

Commit d99c7e8

Browse files
authored
Merge pull request #2771 from github/revert-2767-cklin/prefer-gtar
Revert "Prefer gtar if available"
2 parents 1bb15d0 + 906452d commit d99c7e8

File tree

4 files changed

+24
-55
lines changed

4 files changed

+24
-55
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ See the [releases page](https://github.com/github/codeql-action/releases) for th
44

55
## [UNRELEASED]
66

7-
- Update the action to prefer `gtar` over `tar` to make zstd archive extraction more robust. [2767](https://github.com/github/codeql-action/pull/2767)
7+
- Address an issue where the CodeQL Bundle would occasionally fail to decompress on macOS. [#2768](https://github.com/github/codeql-action/pull/2768)
88

99
## 3.28.9 - 07 Feb 2025
1010

lib/tar.js

Lines changed: 11 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tar.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tar.ts

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ const MIN_REQUIRED_BSD_TAR_VERSION = "3.4.3";
1515
const MIN_REQUIRED_GNU_TAR_VERSION = "1.31";
1616

1717
export type TarVersion = {
18-
name: string;
1918
type: "gnu" | "bsd";
2019
version: string;
2120
};
2221

23-
async function getTarVersion(programName: string): Promise<TarVersion> {
24-
const tar = await io.which(programName, true);
22+
async function getTarVersion(): Promise<TarVersion> {
23+
const tar = await io.which("tar", true);
2524
let stdout = "";
2625
const exitCode = await new ToolRunner(tar, ["--version"], {
2726
listeners: {
@@ -31,43 +30,28 @@ async function getTarVersion(programName: string): Promise<TarVersion> {
3130
},
3231
}).exec();
3332
if (exitCode !== 0) {
34-
throw new Error(`Failed to call ${programName} --version`);
33+
throw new Error("Failed to call tar --version");
3534
}
3635
// Return whether this is GNU tar or BSD tar, and the version number
3736
if (stdout.includes("GNU tar")) {
3837
const match = stdout.match(/tar \(GNU tar\) ([0-9.]+)/);
3938
if (!match || !match[1]) {
40-
throw new Error(`Failed to parse output of ${programName} --version.`);
39+
throw new Error("Failed to parse output of tar --version.");
4140
}
4241

43-
return { name: programName, type: "gnu", version: match[1] };
42+
return { type: "gnu", version: match[1] };
4443
} else if (stdout.includes("bsdtar")) {
4544
const match = stdout.match(/bsdtar ([0-9.]+)/);
4645
if (!match || !match[1]) {
47-
throw new Error(`Failed to parse output of ${programName} --version.`);
46+
throw new Error("Failed to parse output of tar --version.");
4847
}
4948

50-
return { name: programName, type: "bsd", version: match[1] };
49+
return { type: "bsd", version: match[1] };
5150
} else {
5251
throw new Error("Unknown tar version");
5352
}
5453
}
5554

56-
async function pickTarCommand(): Promise<TarVersion> {
57-
// bsdtar 3.5.3 on the macos-14 (arm) action runner image is prone to crash with the following
58-
// error messages when extracting zstd archives:
59-
//
60-
// tar: Child process exited with status 1
61-
// tar: Error exit delayed from previous errors.
62-
//
63-
// To avoid this problem, prefer GNU tar under the name "gtar" if it is available.
64-
try {
65-
return await getTarVersion("gtar");
66-
} catch {
67-
return await getTarVersion("tar");
68-
}
69-
}
70-
7155
export interface ZstdAvailability {
7256
available: boolean;
7357
foundZstdBinary: boolean;
@@ -79,7 +63,7 @@ export async function isZstdAvailable(
7963
): Promise<ZstdAvailability> {
8064
const foundZstdBinary = await isBinaryAccessible("zstd", logger);
8165
try {
82-
const tarVersion = await pickTarCommand();
66+
const tarVersion = await getTarVersion();
8367
const { type, version } = tarVersion;
8468
logger.info(`Found ${type} tar version ${version}.`);
8569
switch (type) {
@@ -187,10 +171,10 @@ export async function extractTarZst(
187171

188172
args.push("-f", tar instanceof stream.Readable ? "-" : tar, "-C", dest);
189173

190-
process.stdout.write(`[command]${tarVersion.name} ${args.join(" ")}\n`);
174+
process.stdout.write(`[command]tar ${args.join(" ")}\n`);
191175

192176
await new Promise<void>((resolve, reject) => {
193-
const tarProcess = spawn(tarVersion.name, args, { stdio: "pipe" });
177+
const tarProcess = spawn("tar", args, { stdio: "pipe" });
194178

195179
let stdout = "";
196180
tarProcess.stdout?.on("data", (data: Buffer) => {
@@ -221,7 +205,7 @@ export async function extractTarZst(
221205
if (code !== 0) {
222206
reject(
223207
new CommandInvocationError(
224-
tarVersion.name,
208+
"tar",
225209
args,
226210
code ?? undefined,
227211
stdout,

0 commit comments

Comments
 (0)