feat: add tar as an installable tool

This commit is contained in:
Amin Yahyaabadi 2025-07-03 05:42:22 -07:00
parent 8e6c0edd38
commit 559fcdd572
12 changed files with 87 additions and 53 deletions

View File

@ -36,7 +36,7 @@ Setting up a **cross-platform** environment for building and testing C++/C proje
| cache | ccache, sccache |
| documentation | doxygen, graphviz |
| coverage | gcovr, opencppcoverage, kcov |
| other | python, powershell, sevenzip |
| other | python, powershell, sevenzip, tar |
`setup-cpp` automatically handles the dependencies of the selected tool (e.g., `python` is required for `conan`).

View File

@ -166,6 +166,9 @@ inputs:
git:
description: "Wether to install git (true/false) or the specific version to install."
required: false
tar:
description: "Wether to install tar (true/false) or the specific version to install."
required: false
runs:
using: "node20"

View File

@ -60,6 +60,7 @@ words:
- gcovr
- ghes
- Graphviz
- gtar
- hadolint
- iarna
- inja

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -134,7 +134,7 @@ All the available tools:
cache: { tools: "--ccache, --sccache" },
documentation: { tools: "--doxygen, --graphviz" },
coverage: { tools: "--gcovr, --opencppcoverage, --kcov" },
other: { tools: "--python, --powershell, --sevenzip" },
other: { tools: "--python, --powershell, --sevenzip, --tar" },
},
["tools"],
)

View File

@ -0,0 +1,12 @@
import type { InstallationInfo } from "../../utils/setup/setupBin.js"
import { testBin } from "../../utils/tests/test-helpers.js"
import { setupTar } from "../tar.js"
jest.setTimeout(300000)
describe("setup-tar", () => {
it("should setup tar", async () => {
const installInfo = await setupTar("", "", process.arch)
await testBin("tar", ["--version"], (installInfo as InstallationInfo | undefined)?.binDir)
})
})

61
src/tar/tar.ts Normal file
View File

@ -0,0 +1,61 @@
import { info } from "ci-log"
import { hasApk, installApkPack } from "setup-alpine"
import { hasAptGet, installAptPack } from "setup-apt"
import { installBrewPack } from "setup-brew"
import which from "which"
import { hasDnf } from "../utils/env/hasDnf.js"
import { isArch } from "../utils/env/isArch.js"
import { setupBin } from "../utils/setup/setupBin.js"
import { setupDnfPack } from "../utils/setup/setupDnfPack.js"
import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js"
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupTar(version: string, setupDir: string, arch: string) {
const tar = await which("tar", { nothrow: true })
if (tar !== null) {
info(`tar already installed at ${tar}`)
return
}
switch (process.platform) {
case "win32": {
// install tar from GnuWin
// https://phoenixnap.dl.sourceforge.net/project/gnuwin32/tar/1.13-1/tar-1.13-1-bin.zip?viasf=1
return setupBin(
"tar",
"1.13-1",
() => {
return {
url: "https://phoenixnap.dl.sourceforge.net/project/gnuwin32/tar/1.13-1/tar-1.13-1-bin.zip?viasf=1",
extractedFolderName: "",
binRelativeDir: "bin",
binFileName: "tar.exe",
}
},
setupDir,
arch,
)
}
case "darwin": {
// installs as gtar
return installBrewPack("gnu-tar", version)
}
case "linux": {
if (isArch()) {
await setupPacmanPack("gzip")
await setupPacmanPack("xz")
return setupPacmanPack("tar")
} else if (hasDnf()) {
return setupDnfPack([{ name: "tar" }, { name: "gzip" }, { name: "xz" }])
} else if (hasAptGet()) {
return installAptPack([{ name: "tar" }, { name: "gzip" }, { name: "xz-utils" }])
} else if (await hasApk()) {
return installApkPack([{ name: "tar" }, { name: "gzip" }, { name: "xz" }])
}
throw new Error("Unsupported linux distribution")
}
default: {
throw new Error("Unsupported platform")
}
}
}

View File

@ -29,6 +29,7 @@ import { setupPowershell } from "./powershell/powershell.js"
import { setupPython } from "./python/python.js"
import { setupSccache } from "./sccache/sccache.js"
import { setupSevenZip } from "./sevenzip/sevenzip.js"
import { setupTar } from "./tar/tar.js"
import { setupTask } from "./task/task.js"
import { setupVcpkg } from "./vcpkg/vcpkg.js"
import { setupVCVarsall } from "./vcvarsall/vcvarsall.js"
@ -105,6 +106,7 @@ export const setups = {
sevenzip: setupSevenZip,
"7zip": setupSevenZip,
"7z": setupSevenZip,
tar: setupTar,
} as const
export type ToolName = keyof typeof setups

View File

@ -4,14 +4,9 @@ import { info, warning } from "ci-log"
import { execa } from "execa"
import { mkdirp, move } from "fs-extra"
import { rm } from "fs/promises"
import { hasApk, installApkPack } from "setup-alpine"
import { hasAptGet, installAptPack } from "setup-apt"
import which from "which"
import { setupSevenZip } from "../../sevenzip/sevenzip.js"
import { hasDnf } from "../env/hasDnf.js"
import { isArch } from "../env/isArch.js"
import { setupDnfPack } from "./setupDnfPack.js"
import { setupPacmanPack } from "./setupPacmanPack.js"
import { setupTar } from "../../tar/tar.js"
export { extractTar, extractXar } from "@actions/tool-cache"
export enum ArchiveType {
@ -133,7 +128,7 @@ export async function extractZip(file: string, dest: string) {
}
export async function extractTarByExe(file: string, dest: string, stripComponents: number = 0, flags: string[] = []) {
await installTarDependencies(getArchiveType(file))
await setupTar("", "", process.arch)
try {
await mkdirp(dest)
@ -157,43 +152,3 @@ export async function extractTarByExe(file: string, dest: string, stripComponent
await grantUserWriteAccess(dest)
return dest
}
async function installTarDependencies(archiveType: ArchiveType) {
if (process.platform !== "linux") {
return
}
info("Installing tar extraction dependencies")
switch (archiveType) {
case ArchiveType.TarGz: {
if (isArch()) {
await setupPacmanPack("gzip")
await setupPacmanPack("tar")
} else if (hasDnf()) {
await setupDnfPack([{ name: "gzip" }, { name: "tar" }])
} else if (hasAptGet()) {
await installAptPack([{ name: "gzip" }, { name: "tar" }])
} else if (await hasApk()) {
await installApkPack([{ name: "gzip" }, { name: "tar" }])
}
return
}
case ArchiveType.TarXz: {
if (isArch()) {
await setupPacmanPack("xz")
await setupPacmanPack("tar")
} else if (hasDnf()) {
await setupDnfPack([{ name: "xz" }, { name: "tar" }])
} else if (hasAptGet()) {
await installAptPack([{ name: "xz-utils" }, { name: "tar" }])
} else if (await hasApk()) {
await installApkPack([{ name: "xz" }, { name: "tar" }])
}
return
}
default:
throw new Error(`Unsupported archive type: ${archiveType} for tar extraction`)
}
}