From cd0ee64e3e944966b65fce9b81dc6cc6f032da78 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 15 Sep 2021 03:14:39 -0500 Subject: [PATCH] feat: add setup apt --- src/utils/setup/setupApt.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/utils/setup/setupApt.ts diff --git a/src/utils/setup/setupApt.ts b/src/utils/setup/setupApt.ts new file mode 100644 index 00000000..613224dc --- /dev/null +++ b/src/utils/setup/setupApt.ts @@ -0,0 +1,14 @@ +import { exec } from "@actions/exec" + +/** A function that installs a package using apt */ +export async function setupApt(name: string, version?: string, updateRepositories: boolean = true) { + if (updateRepositories) { + await exec("apt-get", ["update"]) + } + + const exit = await exec("apt-get", ["install", version !== undefined ? `${name}=${version}` : name]) + + if (exit !== 0) { + throw new Error(`Failed to install ${name} ${version}`) + } +}