fix: fix choco path

This commit is contained in:
Amin Yahyaabadi 2021-09-16 13:47:12 -05:00
parent e6a4d529fc
commit 1c9ab5ba6f
3 changed files with 29 additions and 8 deletions

View File

@ -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)
})
})

View File

@ -1,14 +1,29 @@
import { exec } from "@actions/exec"
import which from "which"
import { InstallationInfo } from "../utils/setup/setupBin"
let binDir: string | undefined
export async function setupChocolatey(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupChocolatey(_version: string, _setupCppDir: string, _arch: string) {
_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<InstallationInfo | undefined> {
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\\" }
}

View File

@ -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<InstallationInfo> {
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\\" }
}