From e522160611955d33691f365d6adc65ebc049652f Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 15 Sep 2021 03:20:11 -0500 Subject: [PATCH] feat: add setup choco --- src/utils/setup/setupChoco.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/utils/setup/setupChoco.ts diff --git a/src/utils/setup/setupChoco.ts b/src/utils/setup/setupChoco.ts new file mode 100644 index 00000000..07fdcd0b --- /dev/null +++ b/src/utils/setup/setupChoco.ts @@ -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}`) + } +}