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.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.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",
|
"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",
|
"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/ ./.parcel-cache && shx mkdir -p ./dist/legacy ./dist/actions ./dist/modern ",
|
"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": "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.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/",
|
"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"
|
process.env.DEBIAN_FRONTEND = "noninteractive"
|
||||||
|
|
||||||
const allRepositories = [...new Set(packages.flatMap((pack) => pack.repositories ?? []))]
|
// Add the repos if needed
|
||||||
|
await addRepositories(apt, packages)
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Qualify the packages into full package name/version
|
||||||
let qualifiedPacks = await Promise.all(packages.map((pack) => getAptArg(pack.name, pack.version)))
|
let qualifiedPacks = await Promise.all(packages.map((pack) => getAptArg(pack.name, pack.version)))
|
||||||
|
|
||||||
// find the packages that are not installed
|
// find the packages that are not installed
|
||||||
qualifiedPacks = await Promise.all(qualifiedPacks.filter(async (pack) => !(await isPackageInstalled(pack))))
|
qualifiedPacks = await Promise.all(qualifiedPacks.filter(async (pack) => !(await isPackageInstalled(pack))))
|
||||||
|
|
||||||
if (qualifiedPacks.length === 0) {
|
if (qualifiedPacks.length === 0) {
|
||||||
|
info("All packages are already installed")
|
||||||
return { binDir: "/usr/bin/" }
|
return { binDir: "/usr/bin/" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the repos if needed
|
||||||
if (!didUpdate || update) {
|
if (!didUpdate || update) {
|
||||||
updateRepos(apt)
|
updateRepos(apt)
|
||||||
didUpdate = true
|
didUpdate = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize apt if needed
|
||||||
if (!didInit) {
|
if (!didInit) {
|
||||||
await initApt(apt)
|
await initApt(apt)
|
||||||
didInit = true
|
didInit = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Install
|
||||||
try {
|
try {
|
||||||
execRootSync(apt, ["install", "--fix-broken", "-y", ...qualifiedPacks])
|
execRootSync(apt, ["install", "--fix-broken", "-y", ...qualifiedPacks])
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -89,6 +86,23 @@ export enum AptPackageType {
|
||||||
None = 3,
|
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> {
|
export async function aptPackageType(name: string, version: string | undefined): Promise<AptPackageType> {
|
||||||
if (version !== undefined && version !== "") {
|
if (version !== undefined && version !== "") {
|
||||||
const { stdout } = await execa("apt-cache", [
|
const { stdout } = await execa("apt-cache", [
|
||||||
|
@ -121,6 +135,13 @@ export async function aptPackageType(name: string, version: string | undefined):
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If apt-cache fails, update the repos and try again
|
||||||
|
if (!didUpdate) {
|
||||||
|
updateRepos(getApt())
|
||||||
|
didUpdate = true
|
||||||
|
return aptPackageType(name, version)
|
||||||
|
}
|
||||||
|
|
||||||
return AptPackageType.None
|
return AptPackageType.None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,17 +177,27 @@ function updateRepos(apt: string) {
|
||||||
execRootSync(apt, apt !== "nala" ? ["update", "-y"] : ["update"])
|
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) {
|
async function initApt(apt: string) {
|
||||||
execRootSync(apt, [
|
// Update the repos if needed
|
||||||
"install",
|
if (!didUpdate) {
|
||||||
"--fix-broken",
|
updateRepos(apt)
|
||||||
"-y",
|
didUpdate = true
|
||||||
"software-properties-common",
|
}
|
||||||
"apt-utils",
|
|
||||||
"ca-certificates",
|
if (!(await isPackageInstalled("ca-certificates"))) {
|
||||||
"gnupg",
|
execRootSync(apt, ["install", "--fix-broken", "-y", "ca-certificates"])
|
||||||
])
|
}
|
||||||
|
if (!(await isPackageInstalled("gnupg"))) {
|
||||||
|
execRootSync(apt, ["install", "--fix-broken", "-y", "gnupg"])
|
||||||
|
}
|
||||||
const promises: Promise<string | void>[] = [
|
const promises: Promise<string | void>[] = [
|
||||||
addAptKeyViaServer(["3B4FE6ACC0B21F32", "40976EAF437D05B5"], "setup-cpp-ubuntu-archive.gpg"),
|
addAptKeyViaServer(["3B4FE6ACC0B21F32", "40976EAF437D05B5"], "setup-cpp-ubuntu-archive.gpg"),
|
||||||
addAptKeyViaServer(["1E9377A2BA9EF27F"], "launchpad-toolchain.gpg"),
|
addAptKeyViaServer(["1E9377A2BA9EF27F"], "launchpad-toolchain.gpg"),
|
||||||
|
|
Loading…
Reference in New Issue