mirror of https://github.com/aminya/setup-cpp
fix: update if apt-cache fails + skip init deps if installed
This commit is contained in:
parent
9ab878fa33
commit
a9d70080cf
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
|
@ -31,8 +31,8 @@
|
|||
"build.packages": "pnpm run -r build",
|
||||
"build.parcel": "cross-env NODE_ENV=production parcel build && run-s build.babel && shx cp -r ./dist/actions/* ./dist/modern",
|
||||
"build.babel": "babel ./dist --out-dir dist --plugins @upleveled/babel-plugin-remove-node-prefix --plugins @babel/plugin-transform-private-methods --compact --no-babelrc --source-maps true",
|
||||
"bump": "ncu -u -x numerous,execa,prettier,@types/node,eslint,@types/eslint && pnpm update && pnpx typesync",
|
||||
"clean": "shx rm -rf ./dist ./exe ./packages/*/dist/ ./.parcel-cache && shx mkdir -p ./dist/legacy ./dist/actions ./dist/modern ",
|
||||
"bump": "ncu -u -x numerous,execa,prettier,@types/node,eslint,@types/eslint && pnpm update && pnpx typesync && pnpm run clean",
|
||||
"clean": "shx rm -rf ./dist ./exe ./packages/*/dist/ && shx mkdir -p ./dist/legacy ./dist/actions ./dist/modern ",
|
||||
"copy.matchers": "run-p copy.matchers.legacy copy.matchers.actions",
|
||||
"copy.matchers.legacy": "shx cp ./src/gcc/gcc_matcher.json ./dist/legacy/ && shx cp ./src/msvc/msvc_matcher.json ./dist/legacy/ && shx cp ./src/python/python_matcher.json ./dist/legacy/ && shx cp ./src/llvm/llvm_matcher.json ./dist/legacy/",
|
||||
"copy.matchers.actions": "shx cp ./src/gcc/gcc_matcher.json ./dist/actions/ && shx cp ./src/msvc/msvc_matcher.json ./dist/actions/ && shx cp ./src/python/python_matcher.json ./dist/actions/ && shx cp ./src/llvm/llvm_matcher.json ./dist/actions/",
|
||||
|
|
|
@ -35,36 +35,33 @@ export async function setupAptPack(packages: AptPackage[], update = false): Prom
|
|||
|
||||
process.env.DEBIAN_FRONTEND = "noninteractive"
|
||||
|
||||
const allRepositories = [...new Set(packages.flatMap((pack) => pack.repositories ?? []))]
|
||||
|
||||
if (allRepositories.length !== 0) {
|
||||
for (const repo of allRepositories) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
execRootSync("add-apt-repository", ["-y", repo])
|
||||
}
|
||||
|
||||
updateRepos(apt)
|
||||
}
|
||||
// Add the repos if needed
|
||||
await addRepositories(apt, packages)
|
||||
|
||||
// Qualify the packages into full package name/version
|
||||
let qualifiedPacks = await Promise.all(packages.map((pack) => getAptArg(pack.name, pack.version)))
|
||||
|
||||
// find the packages that are not installed
|
||||
qualifiedPacks = await Promise.all(qualifiedPacks.filter(async (pack) => !(await isPackageInstalled(pack))))
|
||||
|
||||
if (qualifiedPacks.length === 0) {
|
||||
info("All packages are already installed")
|
||||
return { binDir: "/usr/bin/" }
|
||||
}
|
||||
|
||||
// Update the repos if needed
|
||||
if (!didUpdate || update) {
|
||||
updateRepos(apt)
|
||||
didUpdate = true
|
||||
}
|
||||
|
||||
// Initialize apt if needed
|
||||
if (!didInit) {
|
||||
await initApt(apt)
|
||||
didInit = true
|
||||
}
|
||||
|
||||
// Install
|
||||
try {
|
||||
execRootSync(apt, ["install", "--fix-broken", "-y", ...qualifiedPacks])
|
||||
} catch (err) {
|
||||
|
@ -89,6 +86,23 @@ export enum AptPackageType {
|
|||
None = 3,
|
||||
}
|
||||
|
||||
async function addRepositories(apt: string, packages: AptPackage[]) {
|
||||
const allRepositories = [...new Set(packages.flatMap((pack) => pack.repositories ?? []))]
|
||||
if (allRepositories.length !== 0) {
|
||||
if (!didInit) {
|
||||
await initApt(apt)
|
||||
didInit = true
|
||||
}
|
||||
await installAddAptRepo()
|
||||
for (const repo of allRepositories) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
execRootSync("add-apt-repository", ["-y", repo])
|
||||
}
|
||||
updateRepos(apt)
|
||||
didUpdate = true
|
||||
}
|
||||
}
|
||||
|
||||
export async function aptPackageType(name: string, version: string | undefined): Promise<AptPackageType> {
|
||||
if (version !== undefined && version !== "") {
|
||||
const { stdout } = await execa("apt-cache", [
|
||||
|
@ -121,6 +135,13 @@ export async function aptPackageType(name: string, version: string | undefined):
|
|||
// ignore
|
||||
}
|
||||
|
||||
// If apt-cache fails, update the repos and try again
|
||||
if (!didUpdate) {
|
||||
updateRepos(getApt())
|
||||
didUpdate = true
|
||||
return aptPackageType(name, version)
|
||||
}
|
||||
|
||||
return AptPackageType.None
|
||||
}
|
||||
|
||||
|
@ -156,17 +177,27 @@ function updateRepos(apt: string) {
|
|||
execRootSync(apt, apt !== "nala" ? ["update", "-y"] : ["update"])
|
||||
}
|
||||
|
||||
/** Install apt utils and certificates (usually missing from docker containers) */
|
||||
async function installAddAptRepo() {
|
||||
if (await isPackageInstalled("software-properties-common")) {
|
||||
return
|
||||
}
|
||||
execRootSync("apt-get", ["install", "-y", "software-properties-common"])
|
||||
}
|
||||
|
||||
/** Install gnupg and certificates (usually missing from docker containers) */
|
||||
async function initApt(apt: string) {
|
||||
execRootSync(apt, [
|
||||
"install",
|
||||
"--fix-broken",
|
||||
"-y",
|
||||
"software-properties-common",
|
||||
"apt-utils",
|
||||
"ca-certificates",
|
||||
"gnupg",
|
||||
])
|
||||
// Update the repos if needed
|
||||
if (!didUpdate) {
|
||||
updateRepos(apt)
|
||||
didUpdate = true
|
||||
}
|
||||
|
||||
if (!(await isPackageInstalled("ca-certificates"))) {
|
||||
execRootSync(apt, ["install", "--fix-broken", "-y", "ca-certificates"])
|
||||
}
|
||||
if (!(await isPackageInstalled("gnupg"))) {
|
||||
execRootSync(apt, ["install", "--fix-broken", "-y", "gnupg"])
|
||||
}
|
||||
const promises: Promise<string | void>[] = [
|
||||
addAptKeyViaServer(["3B4FE6ACC0B21F32", "40976EAF437D05B5"], "setup-cpp-ubuntu-archive.gpg"),
|
||||
addAptKeyViaServer(["1E9377A2BA9EF27F"], "launchpad-toolchain.gpg"),
|
||||
|
|
Loading…
Reference in New Issue