From 1c9ab5ba6fe51c50908ac2bbc33026eb8bd61437 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 16 Sep 2021 13:47:12 -0500 Subject: [PATCH] fix: fix choco path --- src/chocolatey/__tests__/chocolatey.test.ts | 5 ++-- src/chocolatey/chocolatey.ts | 27 +++++++++++++++++---- src/utils/setup/setupChocoPack.ts | 5 +++- 3 files changed, 29 insertions(+), 8 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..a980c594 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 (which.sync("choco", { nothrow: true }) !== null) { - return + if (typeof binDir === "string") { + return { binDir } + } + + const maybeBinDir = which.sync("choco", { nothrow: true }) + if (maybeBinDir !== null) { + binDir = maybeBinDir + return { binDir } } // 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\\" } } diff --git a/src/utils/setup/setupChocoPack.ts b/src/utils/setup/setupChocoPack.ts index 20b2a4eb..d9d3448b 100644 --- a/src/utils/setup/setupChocoPack.ts +++ b/src/utils/setup/setupChocoPack.ts @@ -2,11 +2,12 @@ import { exec } from "@actions/exec" import which from "which" import { setupChocolatey } from "../../chocolatey/chocolatey" +import { InstallationInfo } from "./setupBin" let hasChoco = false /** A function that installs a package using choco */ -export async function setupChocoPack(name: string, version?: string, args: string[] = []) { +export async function setupChocoPack(name: string, version?: string, args: string[] = []): Promise { if (!hasChoco || which.sync("choco", { nothrow: true }) === null) { await setupChocolatey("", "", "") hasChoco = true @@ -22,4 +23,6 @@ export async function setupChocoPack(name: string, version?: string, args: strin if (exit !== 0) { throw new Error(`Failed to install ${name} ${version}`) } + + return { binDir: "C:\\ProgramData\\Chocolatey\\bin\\" } }