setup-cpp/src/chocolatey/chocolatey.ts

23 lines
885 B
TypeScript
Raw Normal View History

2021-09-15 05:01:08 +08:00
import { exec } from "@actions/exec"
import which from "which"
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupChocolatey(_version: string, _setupCppDir: string, _arch: string) {
if (process.platform !== "win32") {
return
}
2021-09-15 05:01:08 +08:00
if (which.sync("choco", { nothrow: true }) !== null) {
return
}
// https://docs.chocolatey.org/en-us/choco/setup#install-with-cmd.exe
const exit = await exec(
`@"%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\\chocolatey\\bin"`
)
if (exit !== 0) {
throw new Error(`Failed to install chocolatey`)
}
}