Skip to content

Commit 040d331

Browse files
committed
fix: fix check for apt package installs
1 parent 1818c42 commit 040d331

File tree

9 files changed

+113
-95
lines changed

9 files changed

+113
-95
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ exe/
1717
*.log
1818
*.exe
1919
.cache/
20+
21+
coverage

biome.jsonc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"**/dist/**",
88
"dev/cpp_vcpkg_project/**/*",
99
"**/.venv/",
10-
"**/.*cache/"
10+
"**/.*cache/",
11+
"**/coverage/"
1112
],
1213
"ignoreUnknown": true
1314
},

dist/actions/setup-cpp.js

Lines changed: 27 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/actions/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/legacy/setup-cpp.js

Lines changed: 27 additions & 27 deletions
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.js

Lines changed: 27 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/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/utils/setup/setupAptPack.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,9 @@ export async function setupAptPack(packages: AptPackage[], update = false): Prom
4444
// Add the repos if needed
4545
await addRepositories(apt, packages)
4646

47-
// Qualify the packages into full package name/version
48-
let qualifiedPacks = await Promise.all(packages.map((pack) => getAptArg(pack.name, pack.version)))
49-
50-
// find the packages that are not installed
51-
qualifiedPacks = await Promise.all(qualifiedPacks.filter(async (pack) => !(await isPackageInstalled(pack))))
47+
const needToInstall = await filterAndQualifyAptPackages(packages)
5248

53-
if (qualifiedPacks.length === 0) {
49+
if (needToInstall.length === 0) {
5450
info("All packages are already installed")
5551
return { binDir: "/usr/bin/" }
5652
}
@@ -63,13 +59,13 @@ export async function setupAptPack(packages: AptPackage[], update = false): Prom
6359

6460
// Install
6561
try {
66-
execRootSync(apt, ["install", "--fix-broken", "-y", ...qualifiedPacks])
62+
execRootSync(apt, ["install", "--fix-broken", "-y", ...needToInstall])
6763
} catch (err) {
6864
if ("stderr" in (err as ExecaError)) {
6965
const stderr = (err as ExecaError).stderr
7066
if (retryErrors.some((error) => stderr.includes(error))) {
71-
warning(`Failed to install packages ${qualifiedPacks}. Retrying...`)
72-
execRootSync(apt, ["install", "--fix-broken", "-y", ...qualifiedPacks])
67+
warning(`Failed to install packages ${needToInstall}. Retrying...`)
68+
execRootSync(apt, ["install", "--fix-broken", "-y", ...needToInstall])
7369
}
7470
} else {
7571
throw err
@@ -86,6 +82,21 @@ export enum AptPackageType {
8682
None = 3,
8783
}
8884

85+
/**
86+
* Filter out the packages that are already installed and qualify the packages into a full package name/version
87+
*/
88+
async function filterAndQualifyAptPackages(packages: AptPackage[]) {
89+
return (await Promise.all(packages.map(qualifiedNeededAptPackage)))
90+
.filter((pack) => pack !== undefined)
91+
}
92+
93+
async function qualifiedNeededAptPackage(pack: AptPackage) {
94+
// Qualify the packages into full package name/version
95+
const qualified = await getAptArg(pack.name, pack.version)
96+
// filter out the packages that are already installed
97+
return (await isPackageInstalled(qualified)) ? undefined : qualified
98+
}
99+
89100
async function addRepositories(apt: string, packages: AptPackage[]) {
90101
const allRepositories = [...new Set(packages.flatMap((pack) => pack.repositories ?? []))]
91102
if (allRepositories.length !== 0) {
@@ -192,7 +203,11 @@ async function initApt(apt: string) {
192203
didUpdate = true
193204
}
194205

195-
const toInstall = ["ca-certificates", "gnupg", "apt-utils"].filter(async (pack) => !(await isPackageInstalled(pack)))
206+
const toInstall = await filterAndQualifyAptPackages([
207+
{ name: "ca-certificates" },
208+
{ name: "gnupg" },
209+
{ name: "apt-utils" },
210+
])
196211

197212
if (toInstall.length !== 0) {
198213
execRootSync(apt, ["install", "-y", "--fix-broken", ...toInstall])

0 commit comments

Comments
 (0)