Merge pull request #21 from aminya/make-task

This commit is contained in:
Amin Yahyaabadi 2022-01-30 18:44:02 -08:00 committed by GitHub
commit 454f319514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 260 additions and 96 deletions

View File

@ -23,6 +23,8 @@ The package can be used locally or from CI services like GitHub Actions.
- vcpkg
- meson
- conan
- make
- task
- ccache
- cppcheck
- clangtidy

View File

@ -30,6 +30,12 @@ inputs:
conan:
description: "The conan version to install."
required: false
make:
description: "The make version to install."
required: false
task:
description: "The task version to install."
required: false
vcpkg:
description: "The vcpkg version to install."
required: false

2
dist/setup_cpp.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -56,7 +56,7 @@ export function setupChocolatey(
if (maybeChoco !== null) {
binDir = dirname(maybeChoco)
} else {
binDir = "C:/ProgramData/Chocolatey/bin/"
binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin`
}
if (existsSync(binDir)) {

View File

@ -1,5 +1,6 @@
import { setupCmake } from "../cmake"
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
import { isGitHubCI } from "../../utils/env/isci"
jest.setTimeout(300000)
@ -10,14 +11,16 @@ describe("setup-cmake", () => {
})
it("should setup CMake", async () => {
const { binDir } = await setupCmake("3.20.2", directory, "")
const { binDir } = await setupCmake("3.20.2", directory, process.arch)
await testBin("cmake", ["--version"], binDir)
})
it("should find CMake in the cache", async () => {
const { binDir } = await setupCmake("3.20.2", directory, "")
const { binDir } = await setupCmake("3.20.2", directory, process.arch)
await testBin("cmake", ["--version"], binDir)
expect(binDir.includes("ToolCache")).toBeTruthy()
if (isGitHubCI()) {
expect(binDir).toMatch(process.env.RUNNER_TOOL_CACHE ?? "hostedtoolcache")
}
})
afterAll(async () => {

View File

@ -1,16 +1,13 @@
import { extractZip, extractTar } from "@actions/tool-cache"
import { getInput } from "@actions/core"
import semverLte from "semver/functions/lte"
import semverCoerce from "semver/functions/coerce"
import { setupBin, PackageInfo, InstallationInfo } from "../utils/setup/setupBin"
import { addBinExtension } from "../utils/extension/extension"
/** Get the platform data for cmake */
function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): PackageInfo {
function getCmakePackageInfo(version: string, platform: NodeJS.Platform, arch: string): PackageInfo {
const semVersion = semverCoerce(version) ?? version
const platformStr = platform ?? process.platform
const arch = getInput("architecture") || process.arch
switch (platformStr) {
switch (platform) {
case "win32": {
const isOld = semverLte(semVersion, "v3.19.6")
let osArchStr: string
@ -58,12 +55,11 @@ function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): Packa
}
}
default:
throw new Error(`Unsupported platform '${platformStr}'`)
throw new Error(`Unsupported platform '${platform}'`)
}
}
/** Setup cmake */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupCmake(version: string, setupDir: string, _arch: string): Promise<InstallationInfo> {
return setupBin("cmake", version, getCmakePackageInfo, setupDir)
export function setupCmake(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
return setupBin("cmake", version, getCmakePackageInfo, setupDir, arch)
}

View File

@ -11,6 +11,7 @@ const DefaultVersions: Record<string, string> = {
meson: "0.61.1",
python: "3.8.10",
kcov: "v39",
task: "3.10.0",
gcc: process.platform === "win32" ? "11.2.0.07112021" : "11",
}

View File

@ -24,8 +24,8 @@ export async function setupGcc(version: string, _setupDir: string, arch: string)
} else if (arch === "ia32" && existsSync("C:/tools/mingw32/bin")) {
binDir = "C:/tools/mingw32/bin"
addPath(binDir)
} else if (existsSync("C:/ProgramData/Chocolatey/bin/g++.exe")) {
binDir = "C:/ProgramData/Chocolatey/bin/"
} else if (existsSync(`${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin/g++.exe`)) {
binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin`
}
break
}

View File

@ -31,7 +31,7 @@ describe("setup-Kcov", () => {
// it("should find Kcov in the cache", async () => {
// const directory = await setupTmpDir("kcov-v39")
// const binDir = await testKcov("v39", directory)
// expect(binDir.includes("ToolCache")).toBeTruthy()
// expect(binDir.includes("hostedtoolcache")).toBeTruthy()
// await cleanupTmpDir("kcov-v39")
// })
})

View File

@ -2,7 +2,7 @@ import execa from "execa"
// import { join } from "path"
// import { untildify_user as untildify } from "./utils/path/untildify"
// import { setupCmake } from "../cmake/cmake"
import { execaSudo } from "../utils/env/sudo"
import { execSudo } from "../utils/exec/sudo"
import { addBinExtension } from "../utils/extension/extension"
import { extractTarByExe } from "../utils/setup/extract"
import { setupAptPack } from "../utils/setup/setupAptPack"
@ -20,9 +20,7 @@ function getKcovPackageInfo(version: string): PackageInfo {
extractedFolderName: "",
binRelativeDir: "usr/local/bin",
binFileName: addBinExtension("kcov"),
extractFunction: (file: string, dest: string) => {
return extractTarByExe(file, dest, ["--strip-components=0"])
},
extractFunction: extractTarByExe,
}
} else {
return {
@ -38,7 +36,7 @@ function getKcovPackageInfo(version: string): PackageInfo {
await setupAptPack("libcurl4-openssl-dev")
await execa("cmake", ["-S", "./", "-B", "./build"], { cwd: out })
await execa("cmake", ["--build", "./build", "--config", "Release"], { cwd: out })
await execaSudo("cmake", ["--install", "./build"], out)
await execSudo("cmake", ["--install", "./build"], out)
return out
},
}
@ -48,7 +46,7 @@ function getKcovPackageInfo(version: string): PackageInfo {
export async function setupKcov(version: string, setupDir: string, arch: string) {
switch (process.platform) {
case "linux": {
const installationInfo = await setupBin("kcov", version, getKcovPackageInfo, setupDir)
const installationInfo = await setupBin("kcov", version, getKcovPackageInfo, setupDir, arch)
return installationInfo
}
default: {

View File

@ -2,6 +2,7 @@ import { setupLLVM, VERSIONS, getUrl, setupClangTools } from "../llvm"
import { getSpecificVersionAndUrl } from "../../utils/setup/version"
import { isValidUrl } from "../../utils/http/validate_url"
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
import { isGitHubCI } from "../../utils/env/isci"
jest.setTimeout(300000)
async function testUrl(version: string) {
@ -42,7 +43,7 @@ describe("setup-llvm", () => {
})
it("should setup LLVM", async () => {
const { binDir } = await setupLLVM("11.0.0", directory, "")
const { binDir } = await setupLLVM("11.0.0", directory, process.arch)
await testBin("clang++", ["--version"], binDir)
expect(process.env.CC?.includes("clang")).toBeTruthy()
@ -50,24 +51,29 @@ describe("setup-llvm", () => {
})
it("should find llvm in the cache", async () => {
const { binDir } = await setupLLVM("11.0.0", directory, "")
const { binDir } = await setupLLVM("11.0.0", directory, process.arch)
await testBin("clang++", ["--version"], binDir)
expect(binDir.includes("ToolCache")).toBeTruthy()
if (isGitHubCI()) {
expect(binDir).toMatch(process.env.RUNNER_TOOL_CACHE ?? "hostedtoolcache")
}
expect(process.env.CC?.includes("clang")).toBeTruthy()
expect(process.env.CXX?.includes("clang++")).toBeTruthy()
expect(process.env.CC?.includes("ToolCache")).toBeTruthy()
expect(process.env.CXX?.includes("ToolCache")).toBeTruthy()
if (isGitHubCI()) {
expect(process.env.CC).toMatch("hostedtoolcache")
expect(process.env.CXX).toMatch("hostedtoolcache")
}
})
it("should setup clang-tidy and clang-format", async () => {
const { binDir } = await setupClangTools("11.0.0", directory, "")
const { binDir } = await setupClangTools("11.0.0", directory, process.arch)
await testBin("clang-tidy", ["--version"], binDir)
await testBin("clang-format", ["--version"], binDir)
})
afterAll(async () => {
await cleanupTmpDir("setup-llvm")
await cleanupTmpDir("llvm")
}, 100000)
})

View File

@ -222,8 +222,8 @@ export function getUrl(platform: string, version: string): string | null | Promi
//================================================
// Exports
//================================================
async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform): Promise<PackageInfo> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform, _arch: string): Promise<PackageInfo> {
const [specificVersion, url] = await getSpecificVersionAndUrl(VERSIONS, platform, version, getUrl)
setOutput("version", specificVersion)
return {
@ -231,17 +231,17 @@ async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform): P
extractedFolderName: "",
binRelativeDir: "bin",
binFileName: addBinExtension("clang"),
extractFunction: platform === "win32" ? extractExe : extractTarByExe,
extractFunction:
platform === "win32"
? extractExe
: (file: string, dest: string) => {
return extractTarByExe(file, dest, ["--strip-components=1"])
},
}
}
export async function setupLLVM(
version: string,
setupDir: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_arch: string
): Promise<InstallationInfo> {
const installationInfo = await setupBin("llvm", version, getLLVMPackageInfo, setupDir)
export async function setupLLVM(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
const installationInfo = await setupBin("llvm", version, getLLVMPackageInfo, setupDir, arch)
await activateLLVM(installationInfo.installDir ?? setupDir, version)
return installationInfo
}
@ -284,11 +284,6 @@ export async function activateLLVM(directory: string, versionGiven: string) {
}
/** Setup llvm tools (clang tidy, clang format, etc) without activating llvm and using it as the compiler */
export function setupClangTools(
version: string,
setupDir: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_arch: string
): Promise<InstallationInfo> {
return setupBin("llvm", version, getLLVMPackageInfo, setupDir)
export function setupClangTools(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
return setupBin("llvm", version, getLLVMPackageInfo, setupDir, arch)
}

View File

@ -1,6 +1,8 @@
import * as core from "@actions/core"
import { setupBrew } from "./brew/brew"
import { setupCcache } from "./ccache/ccache"
import { setupMake } from "./make/make"
import { setupTask } from "./task/task"
import { setupChocolatey } from "./chocolatey/chocolatey"
import { setupCmake } from "./cmake/cmake"
import { setupConan } from "./conan/conan"
@ -50,6 +52,8 @@ const setups = {
msvc: setupMSVC,
vcvarsall: setupVCVarsall,
kcov: setupKcov,
make: setupMake,
task: setupTask,
}
/** The tools that can be installed */
@ -74,6 +78,8 @@ const tools: Array<keyof typeof setups> = [
"msvc",
"vcvarsall",
"kcov",
"make",
"task",
]
/** The possible inputs to the program */
@ -282,6 +288,8 @@ All the available tools:
--vcpkg
--meson
--conan
--make
--task
--ccache
--cppcheck
--clangformat

View File

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

24
src/make/make.ts Normal file
View File

@ -0,0 +1,24 @@
import { addPath } from "@actions/core"
import { setupAptPack } from "../utils/setup/setupAptPack"
import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack"
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupMake(version: string, _setupDir: string, _arch: string) {
switch (process.platform) {
case "win32": {
return setupChocoPack("make", version)
}
case "darwin": {
setupBrewPack("make", version)
addPath("/usr/local/opt/make/libexec/gnubin")
return { binDir: "/usr/local/opt/make/libexec/gnubin" }
}
case "linux": {
return setupAptPack("make", version)
}
default: {
throw new Error(`Unsupported platform`)
}
}
}

View File

@ -1,9 +1,10 @@
import { setupNinja } from "../ninja"
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
import { isGitHubCI } from "../../utils/env/isci"
jest.setTimeout(300000)
async function testNinja(directory: string) {
const { binDir } = await setupNinja("1.10.2", directory, "")
const { binDir } = await setupNinja("1.10.2", directory, process.arch)
await testBin("ninja", ["--version"], binDir)
return binDir
}
@ -20,10 +21,12 @@ describe("setup-ninja", () => {
it("should find Ninja in the cache", async () => {
const binDir = await testNinja(directory)
expect(binDir.includes("ToolCache")).toBeTruthy()
if (isGitHubCI()) {
expect(binDir).toMatch(process.env.RUNNER_TOOL_CACHE ?? "hostedtoolcache")
}
})
afterEach(async () => {
await cleanupTmpDir("setup-ninja")
await cleanupTmpDir("ninja")
}, 100000)
})

View File

@ -17,7 +17,8 @@ function getNinjaPlatform(platform: NodeJS.Platform) {
}
/** Get the platform data for ninja */
function getNinjaPackageInfo(version: string, platform: NodeJS.Platform): PackageInfo {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function getNinjaPackageInfo(version: string, platform: NodeJS.Platform, _arch: string): PackageInfo {
const ninjaPlatform = getNinjaPlatform(platform)
return {
binRelativeDir: "",
@ -28,7 +29,6 @@ function getNinjaPackageInfo(version: string, platform: NodeJS.Platform): Packag
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupNinja(version: string, setupDir: string, _arch: string): Promise<InstallationInfo> {
return setupBin("ninja", version, getNinjaPackageInfo, setupDir)
export function setupNinja(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
return setupBin("ninja", version, getNinjaPackageInfo, setupDir, arch)
}

View File

@ -0,0 +1,28 @@
import { setupTask } from "../task"
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
import { isGitHubCI } from "../../utils/env/isci"
jest.setTimeout(300000)
describe("setup-task", () => {
let directory: string
beforeAll(async () => {
directory = await setupTmpDir("task")
})
it("should setup task", async () => {
const { binDir } = await setupTask("3.10.0", directory, process.arch)
await testBin("task", ["--version"], binDir)
})
it("should find task in the cache", async () => {
const { binDir } = await setupTask("3.10.0", directory, process.arch)
if (isGitHubCI()) {
expect(binDir).toMatch(process.env.RUNNER_TOOL_CACHE ?? "hostedtoolcache")
}
})
afterEach(async () => {
await cleanupTmpDir("task")
}, 100000)
})

48
src/task/task.ts Normal file
View File

@ -0,0 +1,48 @@
import { extractZip } from "@actions/tool-cache"
import { addBinExtension } from "../utils/extension/extension"
import { extractTarByExe } from "../utils/setup/extract"
import { setupBin, PackageInfo, InstallationInfo } from "../utils/setup/setupBin"
/** Get the platform name task uses in their download links */
function getTaskPlatform(platform: NodeJS.Platform) {
switch (platform) {
case "win32":
return "windows"
default:
return platform
}
}
/** Get the arch name task uses in their download links */
function getTaskArch(arch: string) {
switch (arch) {
case "x64":
return "amd64"
case "ia32":
case "x86":
case "i386":
case "x32":
return "386"
default:
return arch
}
}
/** Get the platform data for task */
function getTaskPackageInfo(version: string, platform: NodeJS.Platform, arch: string): PackageInfo {
const taskPlatform = getTaskPlatform(platform)
const taskArch = getTaskArch(arch)
const isZip = platform === "win32"
const extension = isZip ? "zip" : "tar.gz"
return {
binRelativeDir: "",
binFileName: addBinExtension("task"),
extractedFolderName: "",
extractFunction: isZip ? extractZip : extractTarByExe,
url: `https://github.com/go-task/task/releases/download/v${version}/task_${taskPlatform}_${taskArch}.${extension}`,
}
}
export function setupTask(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
return setupBin("task", version, getTaskPackageInfo, setupDir, arch)
}

View File

@ -1,12 +1,12 @@
import { exportVariable } from "@actions/core"
import * as core from "@actions/core"
import execa from "execa"
import { isGitHubCI } from "./isci"
import { untildify_user as untildify } from "../path/untildify"
import { appendFileSync } from "fs"
import { join } from "path"
import { isRoot } from "./sudo"
import { error } from "../io/io"
import { execPowershell } from "../exec/powershell"
/** An add path function that works locally or inside GitHub Actions */
export function addEnv(name: string, val: string | undefined) {
@ -31,11 +31,8 @@ function addEnvSystem(name: string, valGiven: string | undefined) {
const val = valGiven ?? ""
switch (process.platform) {
case "win32": {
if (val.length <= 1024) {
execa.sync(`setx "${name}" "${val}"`)
} else {
execa.sync(`powershell -C "[Environment]::SetEnvironmentVariable('${name}', '${val}', 'User')"`)
}
// We do not use `execa.sync(`setx PATH "${path};%PATH%"`)` because of its character limit
execPowershell(`[Environment]::SetEnvironmentVariable('${name}', '${val}', 'User')`)
core.info(`${name}="${val} was set in the environment."`)
return
}

View File

@ -1,4 +1,3 @@
import execa from "execa"
import which from "which"
let _issudo: boolean | undefined = undefined
@ -18,11 +17,3 @@ export function mightSudo(command: string) {
}
return command
}
export function execaSudo(file: string, args: string[], cwd?: string) {
if (isRoot()) {
return execa.command(`sudo ${[file, ...args].map((arg) => `'${arg}'`).join(" ")}`, { shell: true, cwd })
} else {
return execa(file, args)
}
}

View File

@ -0,0 +1,22 @@
import execa from "execa"
import which from "which"
let powershell: string | undefined
export function execPowershell(command: string) {
if (powershell === undefined) {
const maybePwsh = which.sync("pwsh", { nothrow: true })
if (maybePwsh !== null) {
powershell = maybePwsh
}
const maybePowerShell = which.sync("powershell", { nothrow: true })
if (maybePowerShell !== null) {
powershell = maybePowerShell
}
}
if (powershell === undefined) {
throw new Error("Could not find powershell")
}
execa.sync(`${powershell} -C "${command}"`)
}

14
src/utils/exec/sudo.ts Normal file
View File

@ -0,0 +1,14 @@
import execa from "execa"
import { isRoot } from "../env/sudo"
export function execSudo(file: string, args: string[], cwd?: string) {
if (isRoot()) {
return execa.command(`sudo ${[file, ...args].map((arg) => `'${arg}'`).join(" ")}`, {
shell: true,
cwd,
stdio: "inherit",
})
} else {
return execa(file, args)
}
}

View File

@ -1,14 +1,15 @@
import { addPath as ghAddPath } from "@actions/core"
import { delimiter } from "path"
import * as core from "@actions/core"
import execa from "execa"
import { isGitHubCI } from "../env/isci"
import { untildify_user as untildify } from "./untildify"
import { appendFileSync } from "fs"
import { error } from "../io/io"
import { execPowershell } from "../exec/powershell"
/** An add path function that works locally or inside GitHub Actions */
export function addPath(path: string) {
process.env.PATH = `${path}${delimiter}${process.env.PATH}`
try {
if (isGitHubCI()) {
ghAddPath(path)
@ -29,11 +30,10 @@ export function addPath(path: string) {
function addPathSystem(path: string) {
switch (process.platform) {
case "win32": {
if (`${path};${process.env.PATH}`.length <= 1024) {
execa.sync(`setx PATH "${path};%PATH%"`)
} else {
execa.sync(`powershell -C "[Environment]::SetEnvironmentVariable('PATH', \\"${path};$env:PATH\\", 'User')"`)
}
// We do not use `execa.sync(`setx PATH "${path};%PATH%"`)` because of its character limit and also because %PATH% is different for user and system
execPowershell(
`$USER_PATH=[Environment]::GetEnvironmentVariable('PATH', 'User'); [Environment]::SetEnvironmentVariable('PATH', \\"${path};$USER_PATH\\", 'User')`
)
core.info(`${path} was added to the PATH.`)
return
}
@ -45,8 +45,7 @@ function addPathSystem(path: string) {
return
}
default: {
// fall through shell path modification
return
}
}
process.env.PATH = `${path}${delimiter}${process.env.PATH}`
}

View File

@ -7,7 +7,7 @@ export async function extractExe(file: string, dest: string) {
return dest
}
export async function extractTarByExe(file: string, dest: string, flags = ["--strip-components=1"]) {
export async function extractTarByExe(file: string, dest: string, flags = ["--strip-components=0"]) {
try {
await mkdirP(dest)
} catch {

View File

@ -1,6 +1,6 @@
/* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin"
import { execaSudo } from "../env/sudo"
import { execSudo } from "../exec/sudo"
let didUpdate: boolean = false
let didInit: boolean = false
@ -16,7 +16,7 @@ export async function setupAptPack(
process.env.DEBIAN_FRONTEND = "noninteractive"
if (!didUpdate) {
await execaSudo(apt, ["update", "-y"])
await execSudo(apt, ["update", "-y"])
didUpdate = true
}
@ -25,7 +25,7 @@ export async function setupAptPack(
// set time - zone
// TZ = Canada / Pacific
// ln - snf / usr / share / zoneinfo / $TZ / etc / localtime && echo $TZ > /etc/timezone
await execaSudo(apt, [
await execSudo(apt, [
"install",
"--fix-broken",
"-y",
@ -40,19 +40,19 @@ export async function setupAptPack(
if (Array.isArray(repositories)) {
for (const repo of repositories) {
// eslint-disable-next-line no-await-in-loop
await execaSudo("add-apt-repository", ["--update", "-y", repo])
await execSudo("add-apt-repository", ["--update", "-y", repo])
}
await execaSudo(apt, ["update", "-y"])
await execSudo(apt, ["update", "-y"])
}
if (version !== undefined && version !== "") {
try {
await execaSudo(apt, ["install", "--fix-broken", "-y", `${name}=${version}`])
await execSudo(apt, ["install", "--fix-broken", "-y", `${name}=${version}`])
} catch {
await execaSudo(apt, ["install", "--fix-broken", "-y", `${name}-${version}`])
await execSudo(apt, ["install", "--fix-broken", "-y", `${name}-${version}`])
}
} else {
await execaSudo(apt, ["install", "--fix-broken", "-y", name])
await execSudo(apt, ["install", "--fix-broken", "-y", name])
}
return { binDir: "/usr/bin/" }

View File

@ -41,15 +41,17 @@ export type InstallationInfo = {
export async function setupBin(
name: string,
version: string,
getPackageInfo: (version: string, platform: NodeJS.Platform) => PackageInfo | Promise<PackageInfo>,
setupDir: string
getPackageInfo: (version: string, platform: NodeJS.Platform, arch: string) => PackageInfo | Promise<PackageInfo>,
setupDir: string,
arch: string
): Promise<InstallationInfo> {
process.env.RUNNER_TEMP = process.env.RUNNER_TEMP ?? tmpdir()
process.env.RUNNER_TOOL_CACHE = process.env.RUNNER_TOOL_CACH ?? join(tmpdir(), "setup-cpp", "ToolCache")
process.env.RUNNER_TOOL_CACHE = process.env.RUNNER_TOOL_CACHE ?? join(tmpdir(), "setup-cpp", "hostedtoolcache")
const { url, binRelativeDir, binFileName, extractedFolderName, extractFunction } = await getPackageInfo(
version,
process.platform
process.platform,
arch
)
// Restore from cache (if found).
@ -60,7 +62,7 @@ export async function setupBin(
const installDir = join(dir, extractedFolderName)
const binDir = join(installDir, binRelativeDir)
if (existsSync(binDir) && existsSync(join(binDir, binFileName))) {
info(`${name} ${version} was found in the cache.`)
info(`${name} ${version} was found in the cache at ${binDir}.`)
addPath(binDir)
return { installDir, binDir }
}
@ -85,8 +87,12 @@ export async function setupBin(
await setupAptPack("xz-utils")
}
const downloaded = await downloadTool(url)
await extractFunction?.(downloaded, setupDir)
try {
const downloaded = await downloadTool(url)
await extractFunction?.(downloaded, setupDir)
} catch (err) {
throw new Error(`Failed to download ${name} ${version} ${arch}: ${err}`)
}
}
// Adding the bin dir to the path

View File

@ -14,7 +14,9 @@ export function setupBrewPack(name: string, version?: string): InstallationInfo
}
// brew is not thread-safe
execa.sync("brew", ["install", version !== undefined && version !== "" ? `${name}@${version}` : name])
execa.sync("brew", ["install", version !== undefined && version !== "" ? `${name}@${version}` : name], {
stdio: "inherit",
})
return { binDir: "/usr/local/bin/" }
}

View File

@ -28,7 +28,7 @@ export function setupChocoPack(name: string, version?: string, args: string[] =
execa.sync("choco", ["install", "-y", name, ...args], { env, extendEnv: false })
}
const binDir = "C:/ProgramData/Chocolatey/bin/"
const binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin`
addPath(binDir)
return { binDir }
}

View File

@ -4,6 +4,7 @@ import * as path from "path"
import { addBinExtension } from "../extension/extension"
import { join } from "path"
import spawn from "cross-spawn"
import { existsSync } from "fs"
export async function setupTmpDir(testName: string) {
const tempDirectory = path.join(tmpdir(), "setup-cpp", testName)
@ -38,10 +39,12 @@ export async function testBin(
if (typeof binDir === "string") {
expect(binDir).toBeDefined()
expect(binDir).not.toHaveLength(0)
expect(existsSync(binDir)).toBeTruthy()
bin = join(binDir, addBinExtension(name))
}
if (args !== null) {
console.log(`Running ${bin} ${args.join(" ")}`)
const { status } = spawn.sync(bin, args, { stdio: "inherit" })
expect(status).toBe(0)
}