From 85ce4ea45056d1312d5c274432ada75cbab4b539 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 16 Sep 2021 13:16:22 -0500 Subject: [PATCH] fix: fix choco path --- src/chocolatey/__tests__/chocolatey.test.ts | 5 ++-- src/chocolatey/chocolatey.ts | 27 +++++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) 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\\" } }