fix: fix apt cache check and version fallback

This commit is contained in:
Amin Yahyaabadi 2025-03-16 02:44:14 -07:00
parent 660206b3e3
commit 8115710285
6 changed files with 60 additions and 27 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

@ -1,3 +1,4 @@
import { info } from "ci-log"
import escapeRegex from "escape-string-regexp"
import { execa } from "execa"
import { getAptEnv } from "./apt-env.js"
@ -42,35 +43,31 @@ async function aptPackageType(
version: string | undefined,
fallBackToLatest: boolean,
): Promise<AptPackageType> {
if (version !== undefined && version !== "") {
const { stdout } = await execa("apt-cache", [
"search",
"--names-only",
`^${escapeRegex(name)}-${escapeRegex(version)}$`,
], { env: getAptEnv(apt), stdio: "pipe" })
if (stdout.trim() !== "") {
const hasVersion = version !== undefined && version !== ""
const canFallBackToLatest = !hasVersion || fallBackToLatest
if (hasVersion) {
// check if apt-get search can find the version
if (await aptCacheSearchHasPackage(apt, name, version)) {
return AptPackageType.NameDashVersion
}
try {
// check if apt-get show can find the version
// eslint-disable-next-line @typescript-eslint/no-shadow
const { stdout } = await execa("apt-cache", ["show", `${name}=${version}`], { env: getAptEnv(apt) })
if (stdout.trim() === "") {
return AptPackageType.NameEqualsVersion
}
} catch {
// ignore
// check if apt-get show can find the version
if (await aptCacheShowHasPackage(apt, `${name}=${version}`)) {
return AptPackageType.NameEqualsVersion
}
}
try {
const { stdout: showStdout } = await execa("apt-cache", ["show", name], { env: getAptEnv(apt), stdio: "pipe" })
if (showStdout.trim() !== "") {
return AptPackageType.Name
const logFallback = () => {
if (hasVersion && fallBackToLatest) {
info(`Could not find package ${name} ${version}. Falling back to latest version.`)
}
} catch {
// ignore
}
if (canFallBackToLatest && await aptCacheShowHasPackage(apt, name)) {
// if the version is undefined or empty, return the name as a package name
logFallback()
return AptPackageType.Name
}
// If apt-cache fails, update the repos and try again
@ -79,14 +76,47 @@ async function aptPackageType(
return aptPackageType(apt, name, version, fallBackToLatest)
}
if (version === undefined || version === "" || fallBackToLatest) {
if (canFallBackToLatest) {
// if the version is undefined or empty, return the name as a package name
logFallback()
return AptPackageType.Name
}
return AptPackageType.None
}
async function aptCacheSearchHasPackage(apt: string, name: string, version: string) {
try {
const { stdout } = await execa("apt-cache", [
"search",
"--names-only",
`^${escapeRegex(name)}-${escapeRegex(version)}$`,
], { env: getAptEnv(apt), stdio: "pipe" })
if (stdout.trim() !== "") {
return true
}
} catch {
// ignore
}
return false
}
async function aptCacheShowHasPackage(apt: string, arg: string) {
try {
const { stdout } = await execa("apt-cache", ["show", arg], {
env: getAptEnv(apt),
stdio: "pipe",
verbose: true,
})
if (stdout.trim() !== "") {
return true
}
} catch {
// ignore
}
return false
}
async function getAptArg(apt: string, pack: AptPackage) {
const { name, version, fallBackToLatest = false } = pack

View File

@ -27,6 +27,9 @@ import { setupDnfPack } from "../utils/setup/setupDnfPack.js"
function getDoxygenPackageInfo(version: string, platform: NodeJS.Platform, _arch: string): PackageInfo {
switch (platform) {
case "linux": {
if (process.arch === "arm64") {
throw new Error("Doxygen binaries are not available for Linux arm64")
}
const folderName = `doxygen-${version}`
return {
binRelativeDir: "bin/",