feat: add chocolatey installation

This commit is contained in:
Amin Yahyaabadi 2021-09-14 16:01:08 -05:00
parent bf743570e7
commit b085463827
3 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,15 @@
import { setupChocolatey } from "../chocolatey"
import { spawnSync as spawn } from "child_process"
jest.setTimeout(100000)
describe("setup-chocolatey", () => {
it("should setup chocolatey", async () => {
await setupChocolatey()
const { status } = spawn("choco", ["--version"], {
encoding: "utf8",
})
expect(status).toBe(0)
})
})

View File

@ -0,0 +1,17 @@
import { exec } from "@actions/exec"
import which from "which"
export async function setupChocolatey() {
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`)
}
}

View File

@ -1,4 +1,5 @@
import * as core from "@actions/core"
import { setupChocolatey } from "./chocolatey/chocolatey"
import { setupCmake } from "./cmake/cmake"
import { setupConan } from "./conan/conan"
import { setupGcovr } from "./gcovr/gcovr"
@ -60,6 +61,12 @@ export async function main(): Promise<number> {
if (llvmVersion !== undefined) {
await setupLLVM(llvmVersion, setupCppDir)
}
// setup chocolatey (required for installing msvc)
const chocoVersion = maybeGetInput("choco")
if (chocoVersion !== undefined) {
await setupChocolatey()
}
} catch (err) {
core.error(err as string | Error)
core.setFailed("install-cpp failed")