mirror of https://github.com/aminya/setup-cpp
fix: fix check for apt package installs
This commit is contained in:
parent
1818c421dc
commit
040d33199e
|
@ -17,3 +17,5 @@ exe/
|
||||||
*.log
|
*.log
|
||||||
*.exe
|
*.exe
|
||||||
.cache/
|
.cache/
|
||||||
|
|
||||||
|
coverage
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
"**/dist/**",
|
"**/dist/**",
|
||||||
"dev/cpp_vcpkg_project/**/*",
|
"dev/cpp_vcpkg_project/**/*",
|
||||||
"**/.venv/",
|
"**/.venv/",
|
||||||
"**/.*cache/"
|
"**/.*cache/",
|
||||||
|
"**/coverage/"
|
||||||
],
|
],
|
||||||
"ignoreUnknown": true
|
"ignoreUnknown": true
|
||||||
},
|
},
|
||||||
|
|
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
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -44,13 +44,9 @@ export async function setupAptPack(packages: AptPackage[], update = false): Prom
|
||||||
// Add the repos if needed
|
// Add the repos if needed
|
||||||
await addRepositories(apt, packages)
|
await addRepositories(apt, packages)
|
||||||
|
|
||||||
// Qualify the packages into full package name/version
|
const needToInstall = await filterAndQualifyAptPackages(packages)
|
||||||
let qualifiedPacks = await Promise.all(packages.map((pack) => getAptArg(pack.name, pack.version)))
|
|
||||||
|
|
||||||
// find the packages that are not installed
|
if (needToInstall.length === 0) {
|
||||||
qualifiedPacks = await Promise.all(qualifiedPacks.filter(async (pack) => !(await isPackageInstalled(pack))))
|
|
||||||
|
|
||||||
if (qualifiedPacks.length === 0) {
|
|
||||||
info("All packages are already installed")
|
info("All packages are already installed")
|
||||||
return { binDir: "/usr/bin/" }
|
return { binDir: "/usr/bin/" }
|
||||||
}
|
}
|
||||||
|
@ -63,13 +59,13 @@ export async function setupAptPack(packages: AptPackage[], update = false): Prom
|
||||||
|
|
||||||
// Install
|
// Install
|
||||||
try {
|
try {
|
||||||
execRootSync(apt, ["install", "--fix-broken", "-y", ...qualifiedPacks])
|
execRootSync(apt, ["install", "--fix-broken", "-y", ...needToInstall])
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if ("stderr" in (err as ExecaError)) {
|
if ("stderr" in (err as ExecaError)) {
|
||||||
const stderr = (err as ExecaError).stderr
|
const stderr = (err as ExecaError).stderr
|
||||||
if (retryErrors.some((error) => stderr.includes(error))) {
|
if (retryErrors.some((error) => stderr.includes(error))) {
|
||||||
warning(`Failed to install packages ${qualifiedPacks}. Retrying...`)
|
warning(`Failed to install packages ${needToInstall}. Retrying...`)
|
||||||
execRootSync(apt, ["install", "--fix-broken", "-y", ...qualifiedPacks])
|
execRootSync(apt, ["install", "--fix-broken", "-y", ...needToInstall])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw err
|
throw err
|
||||||
|
@ -86,6 +82,21 @@ export enum AptPackageType {
|
||||||
None = 3,
|
None = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter out the packages that are already installed and qualify the packages into a full package name/version
|
||||||
|
*/
|
||||||
|
async function filterAndQualifyAptPackages(packages: AptPackage[]) {
|
||||||
|
return (await Promise.all(packages.map(qualifiedNeededAptPackage)))
|
||||||
|
.filter((pack) => pack !== undefined)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function qualifiedNeededAptPackage(pack: AptPackage) {
|
||||||
|
// Qualify the packages into full package name/version
|
||||||
|
const qualified = await getAptArg(pack.name, pack.version)
|
||||||
|
// filter out the packages that are already installed
|
||||||
|
return (await isPackageInstalled(qualified)) ? undefined : qualified
|
||||||
|
}
|
||||||
|
|
||||||
async function addRepositories(apt: string, packages: AptPackage[]) {
|
async function addRepositories(apt: string, packages: AptPackage[]) {
|
||||||
const allRepositories = [...new Set(packages.flatMap((pack) => pack.repositories ?? []))]
|
const allRepositories = [...new Set(packages.flatMap((pack) => pack.repositories ?? []))]
|
||||||
if (allRepositories.length !== 0) {
|
if (allRepositories.length !== 0) {
|
||||||
|
@ -192,7 +203,11 @@ async function initApt(apt: string) {
|
||||||
didUpdate = true
|
didUpdate = true
|
||||||
}
|
}
|
||||||
|
|
||||||
const toInstall = ["ca-certificates", "gnupg", "apt-utils"].filter(async (pack) => !(await isPackageInstalled(pack)))
|
const toInstall = await filterAndQualifyAptPackages([
|
||||||
|
{ name: "ca-certificates" },
|
||||||
|
{ name: "gnupg" },
|
||||||
|
{ name: "apt-utils" },
|
||||||
|
])
|
||||||
|
|
||||||
if (toInstall.length !== 0) {
|
if (toInstall.length !== 0) {
|
||||||
execRootSync(apt, ["install", "-y", "--fix-broken", ...toInstall])
|
execRootSync(apt, ["install", "-y", "--fix-broken", ...toInstall])
|
||||||
|
|
Loading…
Reference in New Issue