mirror of https://github.com/aminya/setup-cpp
fix: install extraction dependencies
This commit is contained in:
parent
f1968293bc
commit
41c74d00e3
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
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,11 +1,60 @@
|
||||||
import { mkdirP } from "@actions/io"
|
import { mkdirP } from "@actions/io"
|
||||||
import { grantUserWriteAccess } from "admina"
|
import { grantUserWriteAccess } from "admina"
|
||||||
import { warning } from "ci-log"
|
import { info, warning } from "ci-log"
|
||||||
import { execa } from "execa"
|
import { execa } from "execa"
|
||||||
|
import { installAptPack } from "setup-apt"
|
||||||
import which from "which"
|
import which from "which"
|
||||||
import { setupSevenZip } from "../../sevenzip/sevenzip.js"
|
import { setupSevenZip } from "../../sevenzip/sevenzip.js"
|
||||||
|
import { hasDnf } from "../env/hasDnf.js"
|
||||||
|
import { isArch } from "../env/isArch.js"
|
||||||
|
import { isUbuntu } from "../env/isUbuntu.js"
|
||||||
|
import { setupDnfPack } from "./setupDnfPack.js"
|
||||||
|
import { setupPacmanPack } from "./setupPacmanPack.js"
|
||||||
export { extractTar, extractXar } from "@actions/tool-cache"
|
export { extractTar, extractXar } from "@actions/tool-cache"
|
||||||
|
|
||||||
|
export enum ArchiveType {
|
||||||
|
TarGz = "tar.gz",
|
||||||
|
TarXz = "tar.xz",
|
||||||
|
Zip = "zip",
|
||||||
|
SevenZip = "7z",
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getArchiveType(file: string): ArchiveType {
|
||||||
|
const ext = file.split(".").pop()
|
||||||
|
|
||||||
|
if (ext === "gz" || ext === "tgz") {
|
||||||
|
return ArchiveType.TarGz
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ext === "xz" || ext === "txz") {
|
||||||
|
return ArchiveType.TarXz
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ext === "zip") {
|
||||||
|
return ArchiveType.Zip
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ext === "7z") {
|
||||||
|
return ArchiveType.SevenZip
|
||||||
|
}
|
||||||
|
|
||||||
|
// default to 7z
|
||||||
|
return ArchiveType.SevenZip
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getExtractFunction(archiveType: ArchiveType) {
|
||||||
|
switch (archiveType) {
|
||||||
|
case ArchiveType.TarGz:
|
||||||
|
return extractTarByExe
|
||||||
|
case ArchiveType.TarXz:
|
||||||
|
return extractTarByExe
|
||||||
|
case ArchiveType.Zip:
|
||||||
|
return extractZip
|
||||||
|
default:
|
||||||
|
return extract7Zip
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let sevenZip: string | undefined
|
let sevenZip: string | undefined
|
||||||
|
|
||||||
/// Extract 7z using 7z
|
/// Extract 7z using 7z
|
||||||
|
@ -38,6 +87,8 @@ export function extractZip(file: string, dest: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function extractTarByExe(file: string, dest: string, stripComponents: number = 0, flags: string[] = []) {
|
export async function extractTarByExe(file: string, dest: string, stripComponents: number = 0, flags: string[] = []) {
|
||||||
|
await installTarDependencies(getArchiveType(file))
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await mkdirP(dest)
|
await mkdirP(dest)
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -60,3 +111,38 @@ export async function extractTarByExe(file: string, dest: string, stripComponent
|
||||||
await grantUserWriteAccess(dest)
|
await grantUserWriteAccess(dest)
|
||||||
return dest
|
return dest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function installTarDependencies(archiveType: ArchiveType) {
|
||||||
|
info("Installing tar extraction dependencies")
|
||||||
|
|
||||||
|
switch (archiveType) {
|
||||||
|
case ArchiveType.TarGz: {
|
||||||
|
if (process.platform === "linux") {
|
||||||
|
if (isArch()) {
|
||||||
|
await setupPacmanPack("gzip")
|
||||||
|
await setupPacmanPack("tar")
|
||||||
|
} else if (hasDnf()) {
|
||||||
|
await setupDnfPack([{ name: "gzip" }, { name: "tar" }])
|
||||||
|
} else if (isUbuntu()) {
|
||||||
|
await installAptPack([{ name: "gzip" }, { name: "tar" }])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case ArchiveType.TarXz: {
|
||||||
|
if (process.platform === "linux") {
|
||||||
|
if (isArch()) {
|
||||||
|
await setupPacmanPack("xz")
|
||||||
|
await setupPacmanPack("tar")
|
||||||
|
} else if (hasDnf()) {
|
||||||
|
await setupDnfPack([{ name: "xz" }, { name: "tar" }])
|
||||||
|
} else if (isUbuntu()) {
|
||||||
|
await installAptPack([{ name: "xz-utils" }, { name: "tar" }])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new Error(`Unsupported archive type: ${archiveType} for tar extraction`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -7,13 +7,7 @@ import { chmod } from "fs/promises"
|
||||||
import { pathExists } from "path-exists"
|
import { pathExists } from "path-exists"
|
||||||
import { join } from "patha"
|
import { join } from "patha"
|
||||||
import retry from "retry-as-promised"
|
import retry from "retry-as-promised"
|
||||||
import { installAptPack } from "setup-apt"
|
|
||||||
import { maybeGetInput, rcOptions } from "../../cli-options.js"
|
import { maybeGetInput, rcOptions } from "../../cli-options.js"
|
||||||
import { hasDnf } from "../env/hasDnf.js"
|
|
||||||
import { isArch } from "../env/isArch.js"
|
|
||||||
import { isUbuntu } from "../env/isUbuntu.js"
|
|
||||||
import { setupDnfPack } from "./setupDnfPack.js"
|
|
||||||
import { setupPacmanPack } from "./setupPacmanPack.js"
|
|
||||||
|
|
||||||
/** A type that describes a package */
|
/** A type that describes a package */
|
||||||
export type PackageInfo = {
|
export type PackageInfo = {
|
||||||
|
@ -36,8 +30,6 @@ export type InstallationInfo = {
|
||||||
bin?: string
|
bin?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
let didInit: boolean = false
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function that:
|
* A function that:
|
||||||
*
|
*
|
||||||
|
@ -102,7 +94,7 @@ async function downloadExtractInstall(
|
||||||
version: string,
|
version: string,
|
||||||
url: string,
|
url: string,
|
||||||
setupDir: string,
|
setupDir: string,
|
||||||
extractFunction: ((file: string, dest: string) => Promise<unknown>) | undefined,
|
extractFunction: PackageInfo["extractFunction"],
|
||||||
arch: string,
|
arch: string,
|
||||||
) {
|
) {
|
||||||
// download ane extract the package into the installation directory.
|
// download ane extract the package into the installation directory.
|
||||||
|
@ -154,28 +146,10 @@ async function extractPackage(
|
||||||
extractFunction: ((file: string, dest: string) => Promise<unknown>) | undefined,
|
extractFunction: ((file: string, dest: string) => Promise<unknown>) | undefined,
|
||||||
) {
|
) {
|
||||||
info(`Extracting ${downloaded} to ${setupDir}`)
|
info(`Extracting ${downloaded} to ${setupDir}`)
|
||||||
await installExtractionDependencies()
|
|
||||||
|
|
||||||
await extractFunction?.(downloaded, setupDir)
|
await extractFunction?.(downloaded, setupDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function installExtractionDependencies() {
|
|
||||||
if (!didInit) {
|
|
||||||
info("Installing extraction dependencies")
|
|
||||||
if (process.platform === "linux") {
|
|
||||||
if (isArch()) {
|
|
||||||
await Promise.all([setupPacmanPack("unzip"), setupPacmanPack("tar"), setupPacmanPack("xz")])
|
|
||||||
} else if (hasDnf()) {
|
|
||||||
await setupDnfPack([{ name: "unzip" }, { name: "tar" }, { name: "xz" }])
|
|
||||||
} else if (isUbuntu()) {
|
|
||||||
await installAptPack([{ name: "unzip" }, { name: "tar" }, { name: "xz-utils" }])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// eslint-disable-next-line require-atomic-updates
|
|
||||||
didInit = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function cacheInstallation(setupDir: string, name: string, version: string) {
|
async function cacheInstallation(setupDir: string, name: string, version: string) {
|
||||||
// check if inside Github Actions. If so, cache the installation
|
// check if inside Github Actions. If so, cache the installation
|
||||||
if (GITHUB_ACTIONS && typeof process.env.RUNNER_TOOL_CACHE === "string") {
|
if (GITHUB_ACTIONS && typeof process.env.RUNNER_TOOL_CACHE === "string") {
|
||||||
|
|
Loading…
Reference in New Issue