Skip to content

Commit 559fcdd

Browse files
committed
feat: add tar as an installable tool
1 parent 8e6c0ed commit 559fcdd

File tree

12 files changed

+87
-53
lines changed

12 files changed

+87
-53
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Setting up a **cross-platform** environment for building and testing C++/C proje
3636
| cache | ccache, sccache |
3737
| documentation | doxygen, graphviz |
3838
| coverage | gcovr, opencppcoverage, kcov |
39-
| other | python, powershell, sevenzip |
39+
| other | python, powershell, sevenzip, tar |
4040

4141
`setup-cpp` automatically handles the dependencies of the selected tool (e.g., `python` is required for `conan`).
4242

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ inputs:
166166
git:
167167
description: "Wether to install git (true/false) or the specific version to install."
168168
required: false
169+
tar:
170+
description: "Wether to install tar (true/false) or the specific version to install."
171+
required: false
169172

170173
runs:
171174
using: "node20"

cspell.config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ words:
6060
- gcovr
6161
- ghes
6262
- Graphviz
63+
- gtar
6364
- hadolint
6465
- iarna
6566
- inja

dist/legacy/setup-cpp.js

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.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.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ All the available tools:
134134
cache: { tools: "--ccache, --sccache" },
135135
documentation: { tools: "--doxygen, --graphviz" },
136136
coverage: { tools: "--gcovr, --opencppcoverage, --kcov" },
137-
other: { tools: "--python, --powershell, --sevenzip" },
137+
other: { tools: "--python, --powershell, --sevenzip, --tar" },
138138
},
139139
["tools"],
140140
)

src/tar/__tests__/tar.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { InstallationInfo } from "../../utils/setup/setupBin.js"
2+
import { testBin } from "../../utils/tests/test-helpers.js"
3+
import { setupTar } from "../tar.js"
4+
5+
jest.setTimeout(300000)
6+
describe("setup-tar", () => {
7+
it("should setup tar", async () => {
8+
const installInfo = await setupTar("", "", process.arch)
9+
10+
await testBin("tar", ["--version"], (installInfo as InstallationInfo | undefined)?.binDir)
11+
})
12+
})

src/tar/tar.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { info } from "ci-log"
2+
import { hasApk, installApkPack } from "setup-alpine"
3+
import { hasAptGet, installAptPack } from "setup-apt"
4+
import { installBrewPack } from "setup-brew"
5+
import which from "which"
6+
import { hasDnf } from "../utils/env/hasDnf.js"
7+
import { isArch } from "../utils/env/isArch.js"
8+
import { setupBin } from "../utils/setup/setupBin.js"
9+
import { setupDnfPack } from "../utils/setup/setupDnfPack.js"
10+
import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js"
11+
12+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
13+
export async function setupTar(version: string, setupDir: string, arch: string) {
14+
const tar = await which("tar", { nothrow: true })
15+
if (tar !== null) {
16+
info(`tar already installed at ${tar}`)
17+
return
18+
}
19+
20+
switch (process.platform) {
21+
case "win32": {
22+
// install tar from GnuWin
23+
// https://phoenixnap.dl.sourceforge.net/project/gnuwin32/tar/1.13-1/tar-1.13-1-bin.zip?viasf=1
24+
return setupBin(
25+
"tar",
26+
"1.13-1",
27+
() => {
28+
return {
29+
url: "https://phoenixnap.dl.sourceforge.net/project/gnuwin32/tar/1.13-1/tar-1.13-1-bin.zip?viasf=1",
30+
extractedFolderName: "",
31+
binRelativeDir: "bin",
32+
binFileName: "tar.exe",
33+
}
34+
},
35+
setupDir,
36+
arch,
37+
)
38+
}
39+
case "darwin": {
40+
// installs as gtar
41+
return installBrewPack("gnu-tar", version)
42+
}
43+
case "linux": {
44+
if (isArch()) {
45+
await setupPacmanPack("gzip")
46+
await setupPacmanPack("xz")
47+
return setupPacmanPack("tar")
48+
} else if (hasDnf()) {
49+
return setupDnfPack([{ name: "tar" }, { name: "gzip" }, { name: "xz" }])
50+
} else if (hasAptGet()) {
51+
return installAptPack([{ name: "tar" }, { name: "gzip" }, { name: "xz-utils" }])
52+
} else if (await hasApk()) {
53+
return installApkPack([{ name: "tar" }, { name: "gzip" }, { name: "xz" }])
54+
}
55+
throw new Error("Unsupported linux distribution")
56+
}
57+
default: {
58+
throw new Error("Unsupported platform")
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)