feat: fallback to version-less package on arch if not found

This commit is contained in:
Amin Yahyaabadi 2023-05-24 14:12:42 -07:00
parent a0488f7712
commit 36a5b861ce
8 changed files with 48 additions and 16 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -70,7 +70,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
let installationInfo: InstallationInfo let installationInfo: InstallationInfo
if (version === "" || isArch() || hasDnf()) { if (version === "" || isArch() || hasDnf()) {
if (isArch()) { if (isArch()) {
installationInfo = setupPacmanPack("doxygen", version) installationInfo = await setupPacmanPack("doxygen", version)
} else if (hasDnf()) { } else if (hasDnf()) {
return setupDnfPack("doxygen", version) return setupDnfPack("doxygen", version)
} else if (isUbuntu()) { } else if (isUbuntu()) {

View File

@ -95,7 +95,7 @@ export async function setupGcc(version: string, setupDir: string, arch: string)
case "linux": { case "linux": {
if (arch === "x64") { if (arch === "x64") {
if (isArch()) { if (isArch()) {
installationInfo = setupPacmanPack("gcc", version) installationInfo = await setupPacmanPack("gcc", version)
} else if (hasDnf()) { } else if (hasDnf()) {
installationInfo = setupDnfPack("gcc", version) installationInfo = setupDnfPack("gcc", version)
setupDnfPack("gcc-c++", version) setupDnfPack("gcc-c++", version)

View File

@ -63,7 +63,7 @@ export async function setupPythonViaSystem(
case "linux": { case "linux": {
let installInfo: InstallationInfo let installInfo: InstallationInfo
if (isArch()) { if (isArch()) {
installInfo = setupPacmanPack("python", version) installInfo = await setupPacmanPack("python", version)
setupPacmanPack("python-pip") setupPacmanPack("python-pip")
} else if (hasDnf()) { } else if (hasDnf()) {
installInfo = setupDnfPack("python3", version) installInfo = setupDnfPack("python3", version)

View File

@ -1,13 +1,14 @@
/* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin" import { InstallationInfo } from "./setupBin"
import { execRootSync } from "admina" import { execRootSync } from "admina"
import { info } from "ci-log" import { info, warning } from "ci-log"
import { execa } from "execa"
/* eslint-disable require-atomic-updates */
let didUpdate: boolean = false let didUpdate: boolean = false
let didInit: boolean = false let didInit: boolean = false
/** A function that installs a package using pacman */ /** A function that installs a package using pacman */
export function setupPacmanPack(name: string, version?: string, aur?: string): InstallationInfo { export async function setupPacmanPack(name: string, version?: string, aur?: string): Promise<InstallationInfo> {
info(`Installing ${name} ${version ?? ""} via pacman`) info(`Installing ${name} ${version ?? ""} via pacman`)
const pacman = "pacman" const pacman = "pacman"
@ -18,21 +19,52 @@ export function setupPacmanPack(name: string, version?: string, aur?: string): I
didUpdate = true didUpdate = true
} }
if (!didInit) {
// install base-devel // install base-devel
if (!didInit) {
execRootSync(pacman, ["-S", "--noconfirm", "base-devel"]) execRootSync(pacman, ["-S", "--noconfirm", "base-devel"])
didInit = true didInit = true
} }
const runInstall = (arg: string) => {
return execRootSync(aur ?? pacman, ["-S", "--noconfirm", arg])
}
if (version !== undefined && version !== "") { if (version !== undefined && version !== "") {
// check if version is available
const availableVersions = await availablePacmanVersions(pacman, name)
if (availableVersions.includes(version)) {
// try different version formats
try { try {
execRootSync(aur ?? pacman, ["-S", "--noconfirm", `${name}=${version}`]) runInstall(`${name}=${version}`)
} catch { } catch {
execRootSync(aur ?? pacman, ["-S", "--noconfirm", `${name}${version}`]) runInstall(`${name}${version}`)
} }
} else { } else {
execRootSync(aur ?? pacman, ["-S", "--noconfirm", name]) // try without version
info(`Failed to install ${name} ${version} via pacman, trying without version`)
runInstall(name)
}
} else {
// version not specified, install latest
runInstall(name)
} }
return { binDir: "/usr/bin/" } return { binDir: "/usr/bin/" }
} }
const pacmanSiVersionRegex = /Version\s*:\s*(.*)/g
/** Query pacman for available versions */
async function availablePacmanVersions(pacman: string, name: string) {
const availableVersions = []
try {
const { stdout } = await execa(pacman, ["-Si", name])
for (const match of stdout.matchAll(pacmanSiVersionRegex)) {
availableVersions.push(match[1])
}
} catch (err) {
warning(`Failed to get available versions for ${name}: ${err}`)
}
return availableVersions
}