Skip to content

Commit ff86c1b

Browse files
committed
fix: extract tar.xz files correctly with 7zip
1 parent b7e481e commit ff86c1b

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

dist/legacy/setup-cpp.js

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

dist/legacy/setup-cpp.js.map

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

dist/modern/setup-cpp.mjs

+1-1
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.map

+1-1
Large diffs are not rendered by default.

src/utils/setup/extract.ts

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { mkdirP } from "@actions/io"
1+
import { basename, dirname, join } from "path"
2+
import { mkdirP, mv } from "@actions/io"
23
import { grantUserWriteAccess } from "admina"
34
import { info, warning } from "ci-log"
45
import { execa } from "execa"
6+
import { rm } from "fs/promises"
57
import { installAptPack } from "setup-apt"
68
import which from "which"
79
import { setupSevenZip } from "../../sevenzip/sevenzip.js"
@@ -66,9 +68,33 @@ let sevenZip: string | undefined
6668

6769
/// Extract 7z using 7z
6870
export async function extract7Zip(file: string, dest: string) {
71+
const name = basename(file)
72+
73+
if (/.*\.tar\..+$/.test(name)) {
74+
// if the file is tar.*, extract the compression first
75+
const tarDir = dirname(file)
76+
await run7zip(file, tarDir)
77+
// extract the tar
78+
const tarName = name.slice(0, -3)
79+
const tarFile = `${tarDir}/${tarName}`
80+
await run7zip(tarFile, tarDir)
81+
await rm(tarFile)
82+
// Move the extracted files to the destination
83+
const folderName = tarName.slice(0, -4)
84+
const folderPath = join(tarDir, folderName)
85+
await mkdirP(dirname(dest))
86+
await mv(folderPath, dest)
87+
} else {
88+
// extract the 7z file directly
89+
await run7zip(file, dest)
90+
}
91+
92+
return dest
93+
}
94+
95+
async function run7zip(file: string, dest: string) {
6996
await execa(await getSevenZip(), ["x", file, `-o${dest}`, "-y"], { stdio: "inherit" })
7097
await grantUserWriteAccess(dest)
71-
return dest
7298
}
7399

74100
/// install 7z if needed

0 commit comments

Comments
 (0)