mirror of https://github.com/aminya/setup-cpp
fix: fix choco path
This commit is contained in:
parent
e6a4d529fc
commit
1c9ab5ba6f
|
@ -1,3 +1,4 @@
|
||||||
|
import { InstallationInfo } from "../../utils/setup/setupBin"
|
||||||
import { testBin } from "../../utils/tests/test-helpers"
|
import { testBin } from "../../utils/tests/test-helpers"
|
||||||
import { setupChocolatey } from "../chocolatey"
|
import { setupChocolatey } from "../chocolatey"
|
||||||
|
|
||||||
|
@ -7,7 +8,7 @@ describe("setup-chocolatey", () => {
|
||||||
if (process.platform !== "win32") {
|
if (process.platform !== "win32") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await setupChocolatey("", "", "")
|
const { binDir } = (await setupChocolatey("", "", "")) as InstallationInfo
|
||||||
await testBin("choco")
|
await testBin("choco", ["--version"], binDir)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,14 +1,29 @@
|
||||||
import { exec } from "@actions/exec"
|
import { exec } from "@actions/exec"
|
||||||
import which from "which"
|
import which from "which"
|
||||||
|
import { InstallationInfo } from "../utils/setup/setupBin"
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
let binDir: string | undefined
|
||||||
export async function setupChocolatey(_version: string, _setupCppDir: string, _arch: string) {
|
|
||||||
|
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") {
|
if (process.platform !== "win32") {
|
||||||
return
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
if (which.sync("choco", { nothrow: true }) !== null) {
|
if (typeof binDir === "string") {
|
||||||
return
|
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
|
// 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) {
|
if (exit !== 0) {
|
||||||
throw new Error(`Failed to install chocolatey`)
|
throw new Error(`Failed to install chocolatey`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return { binDir: which.sync("choco", { nothrow: true }) ?? "C:\\ProgramData\\Chocolatey\\bin\\" }
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
import { exec } from "@actions/exec"
|
import { exec } from "@actions/exec"
|
||||||
import which from "which"
|
import which from "which"
|
||||||
import { setupChocolatey } from "../../chocolatey/chocolatey"
|
import { setupChocolatey } from "../../chocolatey/chocolatey"
|
||||||
|
import { InstallationInfo } from "./setupBin"
|
||||||
|
|
||||||
let hasChoco = false
|
let hasChoco = false
|
||||||
|
|
||||||
/** A function that installs a package using choco */
|
/** 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) {
|
if (!hasChoco || which.sync("choco", { nothrow: true }) === null) {
|
||||||
await setupChocolatey("", "", "")
|
await setupChocolatey("", "", "")
|
||||||
hasChoco = true
|
hasChoco = true
|
||||||
|
@ -22,4 +23,6 @@ export async function setupChocoPack(name: string, version?: string, args: strin
|
||||||
if (exit !== 0) {
|
if (exit !== 0) {
|
||||||
throw new Error(`Failed to install ${name} ${version}`)
|
throw new Error(`Failed to install ${name} ${version}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return { binDir: "C:\\ProgramData\\Chocolatey\\bin\\" }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue