Skip to content

Commit 41c74d0

Browse files
committed
fix: install extraction dependencies
1 parent f196829 commit 41c74d0

File tree

8 files changed

+175
-115
lines changed

8 files changed

+175
-115
lines changed

dist/actions/setup-cpp.js

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

dist/actions/setup-cpp.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.

dist/legacy/setup-cpp.js

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

dist/legacy/setup-cpp.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.

dist/modern/setup-cpp.js

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

dist/modern/setup-cpp.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/utils/setup/extract.ts

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,60 @@
11
import { mkdirP } from "@actions/io"
22
import { grantUserWriteAccess } from "admina"
3-
import { warning } from "ci-log"
3+
import { info, warning } from "ci-log"
44
import { execa } from "execa"
5+
import { installAptPack } from "setup-apt"
56
import which from "which"
67
import { setupSevenZip } from "../../sevenzip/sevenzip.js"
8+
import { hasDnf } from "../env/hasDnf.js"
9+
import { isArch } from "../env/isArch.js"
10+
import { isUbuntu } from "../env/isUbuntu.js"
11+
import { setupDnfPack } from "./setupDnfPack.js"
12+
import { setupPacmanPack } from "./setupPacmanPack.js"
713
export { extractTar, extractXar } from "@actions/tool-cache"
814

15+
export enum ArchiveType {
16+
TarGz = "tar.gz",
17+
TarXz = "tar.xz",
18+
Zip = "zip",
19+
SevenZip = "7z",
20+
}
21+
22+
export function getArchiveType(file: string): ArchiveType {
23+
const ext = file.split(".").pop()
24+
25+
if (ext === "gz" || ext === "tgz") {
26+
return ArchiveType.TarGz
27+
}
28+
29+
if (ext === "xz" || ext === "txz") {
30+
return ArchiveType.TarXz
31+
}
32+
33+
if (ext === "zip") {
34+
return ArchiveType.Zip
35+
}
36+
37+
if (ext === "7z") {
38+
return ArchiveType.SevenZip
39+
}
40+
41+
// default to 7z
42+
return ArchiveType.SevenZip
43+
}
44+
45+
export function getExtractFunction(archiveType: ArchiveType) {
46+
switch (archiveType) {
47+
case ArchiveType.TarGz:
48+
return extractTarByExe
49+
case ArchiveType.TarXz:
50+
return extractTarByExe
51+
case ArchiveType.Zip:
52+
return extractZip
53+
default:
54+
return extract7Zip
55+
}
56+
}
57+
958
let sevenZip: string | undefined
1059

1160
/// Extract 7z using 7z
@@ -38,6 +87,8 @@ export function extractZip(file: string, dest: string) {
3887
}
3988

4089
export async function extractTarByExe(file: string, dest: string, stripComponents: number = 0, flags: string[] = []) {
90+
await installTarDependencies(getArchiveType(file))
91+
4192
try {
4293
await mkdirP(dest)
4394
} catch {
@@ -60,3 +111,38 @@ export async function extractTarByExe(file: string, dest: string, stripComponent
60111
await grantUserWriteAccess(dest)
61112
return dest
62113
}
114+
115+
async function installTarDependencies(archiveType: ArchiveType) {
116+
info("Installing tar extraction dependencies")
117+
118+
switch (archiveType) {
119+
case ArchiveType.TarGz: {
120+
if (process.platform === "linux") {
121+
if (isArch()) {
122+
await setupPacmanPack("gzip")
123+
await setupPacmanPack("tar")
124+
} else if (hasDnf()) {
125+
await setupDnfPack([{ name: "gzip" }, { name: "tar" }])
126+
} else if (isUbuntu()) {
127+
await installAptPack([{ name: "gzip" }, { name: "tar" }])
128+
}
129+
}
130+
break
131+
}
132+
case ArchiveType.TarXz: {
133+
if (process.platform === "linux") {
134+
if (isArch()) {
135+
await setupPacmanPack("xz")
136+
await setupPacmanPack("tar")
137+
} else if (hasDnf()) {
138+
await setupDnfPack([{ name: "xz" }, { name: "tar" }])
139+
} else if (isUbuntu()) {
140+
await installAptPack([{ name: "xz-utils" }, { name: "tar" }])
141+
}
142+
}
143+
break
144+
}
145+
default:
146+
throw new Error(`Unsupported archive type: ${archiveType} for tar extraction`)
147+
}
148+
}

src/utils/setup/setupBin.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ import { chmod } from "fs/promises"
77
import { pathExists } from "path-exists"
88
import { join } from "patha"
99
import retry from "retry-as-promised"
10-
import { installAptPack } from "setup-apt"
1110
import { maybeGetInput, rcOptions } from "../../cli-options.js"
12-
import { hasDnf } from "../env/hasDnf.js"
13-
import { isArch } from "../env/isArch.js"
14-
import { isUbuntu } from "../env/isUbuntu.js"
15-
import { setupDnfPack } from "./setupDnfPack.js"
16-
import { setupPacmanPack } from "./setupPacmanPack.js"
1711

1812
/** A type that describes a package */
1913
export type PackageInfo = {
@@ -36,8 +30,6 @@ export type InstallationInfo = {
3630
bin?: string
3731
}
3832

39-
let didInit: boolean = false
40-
4133
/**
4234
* A function that:
4335
*
@@ -102,7 +94,7 @@ async function downloadExtractInstall(
10294
version: string,
10395
url: string,
10496
setupDir: string,
105-
extractFunction: ((file: string, dest: string) => Promise<unknown>) | undefined,
97+
extractFunction: PackageInfo["extractFunction"],
10698
arch: string,
10799
) {
108100
// download ane extract the package into the installation directory.
@@ -154,28 +146,10 @@ async function extractPackage(
154146
extractFunction: ((file: string, dest: string) => Promise<unknown>) | undefined,
155147
) {
156148
info(`Extracting ${downloaded} to ${setupDir}`)
157-
await installExtractionDependencies()
158149

159150
await extractFunction?.(downloaded, setupDir)
160151
}
161152

162-
async function installExtractionDependencies() {
163-
if (!didInit) {
164-
info("Installing extraction dependencies")
165-
if (process.platform === "linux") {
166-
if (isArch()) {
167-
await Promise.all([setupPacmanPack("unzip"), setupPacmanPack("tar"), setupPacmanPack("xz")])
168-
} else if (hasDnf()) {
169-
await setupDnfPack([{ name: "unzip" }, { name: "tar" }, { name: "xz" }])
170-
} else if (isUbuntu()) {
171-
await installAptPack([{ name: "unzip" }, { name: "tar" }, { name: "xz-utils" }])
172-
}
173-
}
174-
// eslint-disable-next-line require-atomic-updates
175-
didInit = true
176-
}
177-
}
178-
179153
async function cacheInstallation(setupDir: string, name: string, version: string) {
180154
// check if inside Github Actions. If so, cache the installation
181155
if (GITHUB_ACTIONS && typeof process.env.RUNNER_TOOL_CACHE === "string") {

0 commit comments

Comments
 (0)