From 96f1e1cf8c89a6939334aa7feac9b731bbe42e69 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 25 Jul 2022 00:40:05 -0700 Subject: [PATCH] feat: support installing nala --- action.yml | 3 +++ src/default_versions.ts | 8 ++++++ src/main.ts | 3 +++ src/nala/__tests__/nala.test.ts | 13 ++++++++++ src/nala/nala.ts | 43 +++++++++++++++++++++++++++++++++ src/utils/setup/setupAptPack.ts | 5 ++-- 6 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 src/nala/__tests__/nala.test.ts create mode 100644 src/nala/nala.ts diff --git a/action.yml b/action.yml index e1778f86..988c016c 100644 --- a/action.yml +++ b/action.yml @@ -75,6 +75,9 @@ inputs: sevenzip: description: "The 7z version to install." required: false + nala: + description: 'The nala version to install ("legacy" or "").' + required: false runs: using: "node12" diff --git a/src/default_versions.ts b/src/default_versions.ts index da6a0a1c..ee6c1502 100644 --- a/src/default_versions.ts +++ b/src/default_versions.ts @@ -55,6 +55,14 @@ const DefaultUbuntuVersion: Record> = { doxygen: { 20: "1.9.4", }, + nala: { + 22: "", + 21: "legacy", + 20: "legacy", + 18: "legacy", + 16: "legacy", + 14: "legacy", + }, } /** Get the default version if passed true or undefined, otherwise return the version itself */ diff --git a/src/main.ts b/src/main.ts index c5a818e9..0273f03e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -42,6 +42,7 @@ import { setupKcov } from "./kcov/kcov" import { addEnv } from "./utils/env/addEnv" import { setupSevenZip } from "./sevenzip/sevenzip" import { setupGraphviz } from "./graphviz/graphviz" +import { setupNala } from "./nala/nala" /** The setup functions */ const setups = { @@ -69,6 +70,7 @@ const setups = { make: setupMake, task: setupTask, sevenzip: setupSevenZip, + nala: setupNala, } /** The tools that can be installed */ @@ -97,6 +99,7 @@ const tools: Array = [ "make", "task", "sevenzip", + "nala", ] /** The possible inputs to the program */ diff --git a/src/nala/__tests__/nala.test.ts b/src/nala/__tests__/nala.test.ts new file mode 100644 index 00000000..76fbe3ba --- /dev/null +++ b/src/nala/__tests__/nala.test.ts @@ -0,0 +1,13 @@ +import { setupNala } from "../nala" +import { testBin } from "../../utils/tests/test-helpers" + +jest.setTimeout(300000) +describe("setup-nala", () => { + it("should setup nala", async () => { + if (process.platform !== "linux") { + return + } + const installInfo = setupNala("", "", process.arch) + await testBin("nala", ["--version"], installInfo?.binDir) + }) +}) diff --git a/src/nala/nala.ts b/src/nala/nala.ts new file mode 100644 index 00000000..b95b19d1 --- /dev/null +++ b/src/nala/nala.ts @@ -0,0 +1,43 @@ +import { dirname } from "path" +import which from "which" +import { execSudo } from "../utils/exec/sudo" +import { setupAptPack } from "../utils/setup/setupAptPack" + +let binDir: string | undefined + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export function setupNala(version: string, _setupDir: string, _arch: string) { + if (process.platform !== "linux") { + return undefined + } + if (typeof binDir === "string") { + return { binDir } + } + + const maybeBinDir = which.sync("nala", { nothrow: true }) + if (maybeBinDir !== null) { + binDir = dirname(maybeBinDir) + return { binDir } + } + + // https://github.com/volitank/nala#-installation + execSudo("/bin/bash", [ + "-c", + `echo "deb http://deb.volian.org/volian/ scar main" | sudo tee /etc/apt/sources.list.d/volian-archive-scar-unstable.list`, + ]) + setupAptPack("wget") + execSudo("/bin/bash", [ + "-c", + `wget -qO - https://deb.volian.org/volian/scar.key | sudo tee /etc/apt/trusted.gpg.d/volian-archive-scar-unstable.gpg > /dev/null`, + ]) + + if (version !== "legacy") { + setupAptPack("nala", undefined, [], true) + } else { + setupAptPack("nala-legacy", undefined, [], true) + } + + binDir = "/usr/bin" + + return { binDir } +} diff --git a/src/utils/setup/setupAptPack.ts b/src/utils/setup/setupAptPack.ts index 517c0cfc..6635b87e 100644 --- a/src/utils/setup/setupAptPack.ts +++ b/src/utils/setup/setupAptPack.ts @@ -14,7 +14,8 @@ let didInit: boolean = false export function setupAptPack( name: string, version?: string, - repositories: boolean | string[] = true + repositories: string[] = [], + update = false ): InstallationInfo { info(`Installing ${name} ${version ?? ""} via apt`) @@ -22,7 +23,7 @@ export function setupAptPack( process.env.DEBIAN_FRONTEND = "noninteractive" - if (!didUpdate) { + if (!didUpdate || update) { execSudo(apt, ["update", "-y"]) didUpdate = true }