Skip to content

Commit

Permalink
fix: fix choco path
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 16, 2021
1 parent 9cc2cc7 commit 85ce4ea
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/chocolatey/__tests__/chocolatey.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { InstallationInfo } from "../../utils/setup/setupBin"
import { testBin } from "../../utils/tests/test-helpers"
import { setupChocolatey } from "../chocolatey"

Expand All @@ -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)
})
})
27 changes: 22 additions & 5 deletions src/chocolatey/chocolatey.ts
Original file line number Diff line number Diff line change
@@ -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<InstallationInfo | undefined> {
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
Expand All @@ -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\\" }
}

0 comments on commit 85ce4ea

Please sign in to comment.