diff --git a/src/chocolatey/__tests__/conan.test.ts b/src/chocolatey/__tests__/conan.test.ts new file mode 100644 index 00000000..e52516be --- /dev/null +++ b/src/chocolatey/__tests__/conan.test.ts @@ -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) + }) +}) diff --git a/src/chocolatey/chocolatey.ts b/src/chocolatey/chocolatey.ts new file mode 100644 index 00000000..5da8ef88 --- /dev/null +++ b/src/chocolatey/chocolatey.ts @@ -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`) + } +} diff --git a/src/main.ts b/src/main.ts index ddca230b..94ec47cf 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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 { 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")