Skip to content

Commit 974628d

Browse files
authored
Merge pull request #29 from aminya/7zip [skip ci]
2 parents 6aef987 + c65b6f6 commit 974628d

File tree

8 files changed

+59
-2
lines changed

8 files changed

+59
-2
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ The package can be used locally or from CI services like GitHub Actions.
3333
- gcovr
3434
- opencppcoverage
3535
- kcov
36+
37+
`setup-cpp` can also install the following. These are automatically installed if needed for the above Cpp tools (e.g., python is required for conan).
38+
3639
- python
3740
- choco
3841
- brew
42+
- sevenzip
3943

4044
# Usage
4145

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ inputs:
6969
kcov:
7070
description: "The kcov version to install."
7171
required: false
72+
sevenzip:
73+
description: "The 7z version to install."
74+
required: false
7275

7376
runs:
7477
using: "node12"

dist/setup_cpp.js

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

dist/setup_cpp.js.map

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

src/main.ts

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { join } from "path"
2929
import { setupVCVarsall } from "./vcvarsall/vcvarsall"
3030
import { setupKcov } from "./kcov/kcov"
3131
import { addEnv } from "./utils/env/addEnv"
32+
import { setupSevenZip } from "./sevenzip/sevenzip"
3233

3334
/** The setup functions */
3435
const setups = {
@@ -54,6 +55,7 @@ const setups = {
5455
kcov: setupKcov,
5556
make: setupMake,
5657
task: setupTask,
58+
sevenzip: setupSevenZip,
5759
}
5860

5961
/** The tools that can be installed */
@@ -80,6 +82,7 @@ const tools: Array<keyof typeof setups> = [
8082
"kcov",
8183
"make",
8284
"task",
85+
"sevenzip",
8386
]
8487

8588
/** The possible inputs to the program */
@@ -290,9 +293,11 @@ All the available tools:
290293
--gcovr
291294
--opencppcoverage
292295
--kcov
296+
293297
--python
294298
--choco
295299
--brew
300+
--sevenzip
296301
`)
297302
}
298303

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

src/sevenzip/sevenzip.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { setupAptPack } from "../utils/setup/setupAptPack"
2+
import { setupBrewPack } from "../utils/setup/setupBrewPack"
3+
import { setupChocoPack } from "../utils/setup/setupChocoPack"
4+
5+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
6+
export function setupSevenZip(version: string, _setupDir: string, _arch: string) {
7+
switch (process.platform) {
8+
case "win32": {
9+
return setupChocoPack("7zip", version)
10+
}
11+
case "darwin": {
12+
return setupBrewPack("p7zip", version)
13+
}
14+
case "linux": {
15+
return setupAptPack("p7zip-full", version)
16+
}
17+
default: {
18+
throw new Error(`Unsupported platform`)
19+
}
20+
}
21+
}

src/utils/setup/extract.ts

+12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
import execa from "execa"
22
import { mkdirP } from "@actions/io"
3+
import which from "which"
4+
import { setupSevenZip } from "../../sevenzip/sevenzip"
35
export { extractTar, extractXar, extract7z, extractZip } from "@actions/tool-cache"
46

7+
let sevenZip: string | undefined
8+
59
export async function extractExe(file: string, dest: string) {
10+
// install 7z if needed
11+
if (sevenZip === undefined) {
12+
if (which.sync("7z", { nothrow: true }) !== null) {
13+
sevenZip = "7z"
14+
}
15+
await setupSevenZip("", "", process.arch)
16+
}
17+
618
await execa("7z", ["x", file, `-o${dest}`])
719
return dest
820
}

0 commit comments

Comments
 (0)