-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathsetup-cpp-installer.ts
28 lines (27 loc) · 1.04 KB
/
setup-cpp-installer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { info } from "ci-log"
import { execa } from "execa"
import which from "which"
/**
* Install the setup-cpp CLI globally
* @param version - The version of setup-cpp to install
* @param packageManager - The package manager to use
*/
export async function installSetupCpp(version: string, packageManager: string = "npm") {
try {
// check if `setup-cpp` is available in the shell, if so, skip the installation to avoid overwriting the existing version
const setupCppPath = await which("setup-cpp", { nothrow: true })
if (setupCppPath !== null) {
return `setup-cpp@${version} already installed`
}
// Install setup-cpp globally
info(`Installing setup-cpp@${version} via ${packageManager}...`)
await execa(packageManager, ["install", "-g", `setup-cpp@${version}`], {
stdio: "inherit",
// 1 minutes timeout
timeout: 1000 * 60 * 1,
})
return `setup-cpp@${version} installed successfully`
} catch (err) {
return new Error(`Failed to install the setup-cpp@${version} CLI: ${err}. Ignoring...`)
}
}