diff --git a/src/chocolatey/__tests__/chocolatey.test.ts b/src/chocolatey/__tests__/chocolatey.test.ts index 387dbd58..1bd5b310 100644 --- a/src/chocolatey/__tests__/chocolatey.test.ts +++ b/src/chocolatey/__tests__/chocolatey.test.ts @@ -1,3 +1,4 @@ +import { InstallationInfo } from "../../utils/setup/setupBin" import { testBin } from "../../utils/tests/test-helpers" import { setupChocolatey } from "../chocolatey" @@ -7,7 +8,7 @@ describe("setup-chocolatey", () => { if (process.platform !== "win32") { return } - await setupChocolatey("", "", "") - await testBin("choco") + const { binDir } = (await setupChocolatey("", "", "")) as InstallationInfo + await testBin("choco", ["--version"], binDir) }) }) diff --git a/src/chocolatey/chocolatey.ts b/src/chocolatey/chocolatey.ts index dfcd48d5..6078538f 100644 --- a/src/chocolatey/chocolatey.ts +++ b/src/chocolatey/chocolatey.ts @@ -1,14 +1,29 @@ import { exec } from "@actions/exec" import which from "which" +import { InstallationInfo } from "../utils/setup/setupBin" -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export async function setupChocolatey(_version: string, _setupCppDir: string, _arch: string) { +let binDir: string | undefined + +export async function setupChocolatey( + // eslint-disable-next-line @typescript-eslint/no-unused-vars + _version: string, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + _setupCppDir: string, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + _arch: string +): Promise { if (process.platform !== "win32") { - return + return undefined + } + + if (typeof binDir === "string") { + return { binDir } } - if (which.sync("choco", { nothrow: true }) !== null) { - return + const maybeBinDir = which.sync("choco", { nothrow: true }) + if (maybeBinDir !== null) { + binDir = maybeBinDir + return undefined } // https://docs.chocolatey.org/en-us/choco/setup#install-with-cmd.exe @@ -19,4 +34,6 @@ export async function setupChocolatey(_version: string, _setupCppDir: string, _a if (exit !== 0) { throw new Error(`Failed to install chocolatey`) } + + return { binDir: which.sync("choco", { nothrow: true }) ?? "C:\\ProgramData\\Chocolatey\\bin\\" } }