Skip to content

Commit 8115710

Browse files
committed
fix: fix apt cache check and version fallback
1 parent 660206b commit 8115710

File tree

6 files changed

+60
-27
lines changed

6 files changed

+60
-27
lines changed

dist/legacy/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/legacy/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/modern/setup-cpp.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.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.

packages/setup-apt/src/qualify-install.ts

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { info } from "ci-log"
12
import escapeRegex from "escape-string-regexp"
23
import { execa } from "execa"
34
import { getAptEnv } from "./apt-env.js"
@@ -42,35 +43,31 @@ async function aptPackageType(
4243
version: string | undefined,
4344
fallBackToLatest: boolean,
4445
): Promise<AptPackageType> {
45-
if (version !== undefined && version !== "") {
46-
const { stdout } = await execa("apt-cache", [
47-
"search",
48-
"--names-only",
49-
`^${escapeRegex(name)}-${escapeRegex(version)}$`,
50-
], { env: getAptEnv(apt), stdio: "pipe" })
51-
if (stdout.trim() !== "") {
46+
const hasVersion = version !== undefined && version !== ""
47+
const canFallBackToLatest = !hasVersion || fallBackToLatest
48+
49+
if (hasVersion) {
50+
// check if apt-get search can find the version
51+
if (await aptCacheSearchHasPackage(apt, name, version)) {
5252
return AptPackageType.NameDashVersion
5353
}
5454

55-
try {
56-
// check if apt-get show can find the version
57-
// eslint-disable-next-line @typescript-eslint/no-shadow
58-
const { stdout } = await execa("apt-cache", ["show", `${name}=${version}`], { env: getAptEnv(apt) })
59-
if (stdout.trim() === "") {
60-
return AptPackageType.NameEqualsVersion
61-
}
62-
} catch {
63-
// ignore
55+
// check if apt-get show can find the version
56+
if (await aptCacheShowHasPackage(apt, `${name}=${version}`)) {
57+
return AptPackageType.NameEqualsVersion
6458
}
6559
}
6660

67-
try {
68-
const { stdout: showStdout } = await execa("apt-cache", ["show", name], { env: getAptEnv(apt), stdio: "pipe" })
69-
if (showStdout.trim() !== "") {
70-
return AptPackageType.Name
61+
const logFallback = () => {
62+
if (hasVersion && fallBackToLatest) {
63+
info(`Could not find package ${name} ${version}. Falling back to latest version.`)
7164
}
72-
} catch {
73-
// ignore
65+
}
66+
67+
if (canFallBackToLatest && await aptCacheShowHasPackage(apt, name)) {
68+
// if the version is undefined or empty, return the name as a package name
69+
logFallback()
70+
return AptPackageType.Name
7471
}
7572

7673
// If apt-cache fails, update the repos and try again
@@ -79,14 +76,47 @@ async function aptPackageType(
7976
return aptPackageType(apt, name, version, fallBackToLatest)
8077
}
8178

82-
if (version === undefined || version === "" || fallBackToLatest) {
79+
if (canFallBackToLatest) {
8380
// if the version is undefined or empty, return the name as a package name
81+
logFallback()
8482
return AptPackageType.Name
8583
}
8684

8785
return AptPackageType.None
8886
}
8987

88+
async function aptCacheSearchHasPackage(apt: string, name: string, version: string) {
89+
try {
90+
const { stdout } = await execa("apt-cache", [
91+
"search",
92+
"--names-only",
93+
`^${escapeRegex(name)}-${escapeRegex(version)}$`,
94+
], { env: getAptEnv(apt), stdio: "pipe" })
95+
if (stdout.trim() !== "") {
96+
return true
97+
}
98+
} catch {
99+
// ignore
100+
}
101+
return false
102+
}
103+
104+
async function aptCacheShowHasPackage(apt: string, arg: string) {
105+
try {
106+
const { stdout } = await execa("apt-cache", ["show", arg], {
107+
env: getAptEnv(apt),
108+
stdio: "pipe",
109+
verbose: true,
110+
})
111+
if (stdout.trim() !== "") {
112+
return true
113+
}
114+
} catch {
115+
// ignore
116+
}
117+
return false
118+
}
119+
90120
async function getAptArg(apt: string, pack: AptPackage) {
91121
const { name, version, fallBackToLatest = false } = pack
92122

src/doxygen/doxygen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import { setupDnfPack } from "../utils/setup/setupDnfPack.js"
2727
function getDoxygenPackageInfo(version: string, platform: NodeJS.Platform, _arch: string): PackageInfo {
2828
switch (platform) {
2929
case "linux": {
30+
if (process.arch === "arm64") {
31+
throw new Error("Doxygen binaries are not available for Linux arm64")
32+
}
3033
const folderName = `doxygen-${version}`
3134
return {
3235
binRelativeDir: "bin/",

0 commit comments

Comments
 (0)