Skip to content

Commit 36a5b86

Browse files
committed
feat: fallback to version-less package on arch if not found
1 parent a0488f7 commit 36a5b86

File tree

8 files changed

+48
-16
lines changed

8 files changed

+48
-16
lines changed

dist/node12/setup-cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node12/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node16/setup-cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node16/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/doxygen/doxygen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
7070
let installationInfo: InstallationInfo
7171
if (version === "" || isArch() || hasDnf()) {
7272
if (isArch()) {
73-
installationInfo = setupPacmanPack("doxygen", version)
73+
installationInfo = await setupPacmanPack("doxygen", version)
7474
} else if (hasDnf()) {
7575
return setupDnfPack("doxygen", version)
7676
} else if (isUbuntu()) {

src/gcc/gcc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export async function setupGcc(version: string, setupDir: string, arch: string)
9595
case "linux": {
9696
if (arch === "x64") {
9797
if (isArch()) {
98-
installationInfo = setupPacmanPack("gcc", version)
98+
installationInfo = await setupPacmanPack("gcc", version)
9999
} else if (hasDnf()) {
100100
installationInfo = setupDnfPack("gcc", version)
101101
setupDnfPack("gcc-c++", version)

src/python/python.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export async function setupPythonViaSystem(
6363
case "linux": {
6464
let installInfo: InstallationInfo
6565
if (isArch()) {
66-
installInfo = setupPacmanPack("python", version)
66+
installInfo = await setupPacmanPack("python", version)
6767
setupPacmanPack("python-pip")
6868
} else if (hasDnf()) {
6969
installInfo = setupDnfPack("python3", version)

src/utils/setup/setupPacmanPack.ts

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
/* eslint-disable require-atomic-updates */
21
import { InstallationInfo } from "./setupBin"
32
import { execRootSync } from "admina"
4-
import { info } from "ci-log"
3+
import { info, warning } from "ci-log"
4+
import { execa } from "execa"
55

6+
/* eslint-disable require-atomic-updates */
67
let didUpdate: boolean = false
78
let didInit: boolean = false
89

910
/** A function that installs a package using pacman */
10-
export function setupPacmanPack(name: string, version?: string, aur?: string): InstallationInfo {
11+
export async function setupPacmanPack(name: string, version?: string, aur?: string): Promise<InstallationInfo> {
1112
info(`Installing ${name} ${version ?? ""} via pacman`)
1213

1314
const pacman = "pacman"
@@ -18,21 +19,52 @@ export function setupPacmanPack(name: string, version?: string, aur?: string): I
1819
didUpdate = true
1920
}
2021

22+
// install base-devel
2123
if (!didInit) {
22-
// install base-devel
2324
execRootSync(pacman, ["-S", "--noconfirm", "base-devel"])
2425
didInit = true
2526
}
2627

28+
const runInstall = (arg: string) => {
29+
return execRootSync(aur ?? pacman, ["-S", "--noconfirm", arg])
30+
}
31+
2732
if (version !== undefined && version !== "") {
28-
try {
29-
execRootSync(aur ?? pacman, ["-S", "--noconfirm", `${name}=${version}`])
30-
} catch {
31-
execRootSync(aur ?? pacman, ["-S", "--noconfirm", `${name}${version}`])
33+
// check if version is available
34+
const availableVersions = await availablePacmanVersions(pacman, name)
35+
if (availableVersions.includes(version)) {
36+
// try different version formats
37+
try {
38+
runInstall(`${name}=${version}`)
39+
} catch {
40+
runInstall(`${name}${version}`)
41+
}
42+
} else {
43+
// try without version
44+
info(`Failed to install ${name} ${version} via pacman, trying without version`)
45+
runInstall(name)
3246
}
3347
} else {
34-
execRootSync(aur ?? pacman, ["-S", "--noconfirm", name])
48+
// version not specified, install latest
49+
runInstall(name)
3550
}
3651

3752
return { binDir: "/usr/bin/" }
3853
}
54+
55+
const pacmanSiVersionRegex = /Version\s*:\s*(.*)/g
56+
57+
/** Query pacman for available versions */
58+
async function availablePacmanVersions(pacman: string, name: string) {
59+
const availableVersions = []
60+
try {
61+
const { stdout } = await execa(pacman, ["-Si", name])
62+
63+
for (const match of stdout.matchAll(pacmanSiVersionRegex)) {
64+
availableVersions.push(match[1])
65+
}
66+
} catch (err) {
67+
warning(`Failed to get available versions for ${name}: ${err}`)
68+
}
69+
return availableVersions
70+
}

0 commit comments

Comments
 (0)