feat: add setup choco

This commit is contained in:
Amin Yahyaabadi 2021-09-15 03:20:11 -05:00
parent cd0ee64e3e
commit e522160611
1 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,21 @@
import { exec } from "@actions/exec"
import which from "which"
import { setupChocolatey } from "../../chocolatey/chocolatey"
/** A function that installs a package using choco */
export async function setupChoco(name: string, version?: string) {
if (which.sync("choco", { nothrow: true }) === null) {
await setupChocolatey()
}
let exit
if (version === undefined) {
exit = await exec("choco", ["install", name])
} else {
exit = await exec("choco", ["install", name, `--version=${version}`])
}
if (exit !== 0) {
throw new Error(`Failed to install ${name} ${version}`)
}
}