fix!: only support a single repository/key for each apt package

BREAKING the option for repositories/keys are now singular instead of an array
This commit is contained in:
Amin Yahyaabadi 2024-08-28 14:23:40 -07:00
parent 2032957802
commit adb1af1e17
No known key found for this signature in database
GPG Key ID: F52AF77F636088F0
10 changed files with 123 additions and 129 deletions

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

View File

@ -109,10 +109,8 @@ await installAptPack([
{
name: "gcc",
version,
repositories: ["ppa:ubuntu-toolchain-r/test"],
addAptKey: [
{ keys: ["1E9377A2BA9EF27F"], fileName: "ubuntu-toolchain-r-test.gpg" },
],
repository: "ppa:ubuntu-toolchain-r/test",
key: { key: "1E9377A2BA9EF27F", fileName: "ubuntu-toolchain-r-test.gpg" },
},
])
```
@ -154,7 +152,7 @@ Add an apt key
```ts
await addAptKey({
keys: ["3B4FE6ACC0B21F32", "40976EAF437D05B5"],
key: "3B4FE6ACC0B21F32"
fileName: "bazel-archive-keyring.gpg",
})
```
@ -178,7 +176,7 @@ Add an apt key via a keyserver
**Parameters:**
- { keys, keyServer = defaultKeyServer, fileName, keyStorePath = defaultKeyServer } (`KeyServerOptions`)
- { key, keyServer = defaultKeyServer, fileName, keyStorePath = defaultKeyServer } (`KeyServerOptions`)
**returns:** Promise<string>

View File

@ -15,7 +15,7 @@ export type AddAptKeyOptions = KeyServerOptions | KeyUrl
*
* @example
* ```ts
* await addAptKey({ keys: ["3B4FE6ACC0B21F32", "40976EAF437D05B5"], fileName: "bazel-archive-keyring.gpg"})
* await addAptKey({ key: "3B4FE6ACC0B21F32" fileName: "bazel-archive-keyring.gpg"})
* ```
*
* @example
@ -46,14 +46,14 @@ export const defaultKeyStorePath = "/etc/apt/trusted.gpg.d"
export type KeyServerOptions = {
/**
* The keys to add
* The key to add
*
* @example
* ```ts
* ["3B4FE6ACC0B21F32", "40976EAF437D05B5"]
* "3B4FE6ACC0B21F32"
* ```
*/
keys: string[]
key: string
/**
* The keyserver to use (Defaults to `keyserver.ubuntu.com`)
*/
@ -67,7 +67,7 @@ export const defaultKeyServer = "keyserver.ubuntu.com"
* @returns The file name of the key that was added or `undefined` if it failed
*/
export async function addAptKeyViaServer(
{ keys, keyServer = defaultKeyServer, fileName, keyStorePath = defaultKeyServer }: KeyServerOptions,
{ key, keyServer = defaultKeyServer, fileName, keyStorePath = defaultKeyServer }: KeyServerOptions,
) {
try {
assertGpgFileName(fileName)
@ -75,8 +75,6 @@ export async function addAptKeyViaServer(
if (!(await pathExists(filePath))) {
initGpg()
await Promise.all(
keys.map(async (key) => {
await execRoot("gpg", [
"--no-default-keyring",
"--keyring",
@ -87,8 +85,6 @@ export async function addAptKeyViaServer(
key,
])
await execRoot("chmod", ["644", filePath])
}),
)
}
return filePath
} catch (err) {

View File

@ -38,10 +38,10 @@ export type AptPackage = {
name: string
/** The version of the package (optional) */
version?: string
/** The repositories to add before installing the package (optional) */
repositories?: string[]
/** The keys to add before installing the package (optional) */
addAptKey?: AddAptKeyOptions[]
/** The repository to add before installing the package (optional) */
repository?: string
/** The key to add before installing the package (optional) */
key?: AddAptKeyOptions
}
const retryErrors = [
@ -69,8 +69,8 @@ const retryErrors = [
{
name: "gcc",
version,
repositories: ["ppa:ubuntu-toolchain-r/test"],
addAptKey: [{ keys: ["1E9377A2BA9EF27F"], fileName: "ubuntu-toolchain-r-test.gpg" }],
repository: "ppa:ubuntu-toolchain-r/test",
key: { key: "1E9377A2BA9EF27F", fileName: "ubuntu-toolchain-r-test.gpg" },
},
])
* ```
@ -133,8 +133,8 @@ export async function installAptPack(packages: AptPackage[], update = false): Pr
async function addAptKeys(packages: AptPackage[]) {
await Promise.all(packages.map(async (pack) => {
if (pack.addAptKey !== undefined) {
await Promise.all(pack.addAptKey.map(addAptKey))
if (pack.key !== undefined) {
await addAptKey(pack.key)
}
}))
}
@ -211,7 +211,7 @@ async function qualifiedNeededAptPackage(apt: string, pack: 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.repository ?? []))]
if (allRepositories.length !== 0) {
if (!didInit) {
await initApt(apt)

View File

@ -114,14 +114,14 @@ export async function setupGcc(version: string, setupDir: string, arch: string,
{
name: "gcc",
version,
repositories: ["ppa:ubuntu-toolchain-r/test"],
addAptKey: [{ keys: ["1E9377A2BA9EF27F"], fileName: "ubuntu-toolchain-r-test.gpg" }],
repository: "ppa:ubuntu-toolchain-r/test",
key: { key: "1E9377A2BA9EF27F", fileName: "ubuntu-toolchain-r-test.gpg" },
},
{
name: "g++",
version,
repositories: ["ppa:ubuntu-toolchain-r/test"],
addAptKey: [{ keys: ["1E9377A2BA9EF27F"], fileName: "ubuntu-toolchain-r-test.gpg" }],
repository: "ppa:ubuntu-toolchain-r/test",
key: { key: "1E9377A2BA9EF27F", fileName: "ubuntu-toolchain-r-test.gpg" },
},
])
}
@ -133,8 +133,8 @@ export async function setupGcc(version: string, setupDir: string, arch: string,
await installAptPack([{
name: "gcc-multilib",
version,
repositories: ["ppa:ubuntu-toolchain-r/test"],
addAptKey: [{ keys: ["1E9377A2BA9EF27F"], fileName: "ubuntu-toolchain-r-test.gpg" }],
repository: "ppa:ubuntu-toolchain-r/test",
key: { key: "1E9377A2BA9EF27F", fileName: "ubuntu-toolchain-r-test.gpg" },
}])
}
}
@ -180,8 +180,8 @@ export async function setupMingw(version: string, setupDir: string, arch: string
{
name: "mingw-w64",
version,
repositories: ["ppa:ubuntu-toolchain-r/test"],
addAptKey: [{ keys: ["1E9377A2BA9EF27F"], fileName: "ubuntu-toolchain-r-test.gpg" }],
repository: "ppa:ubuntu-toolchain-r/test",
key: { key: "1E9377A2BA9EF27F", fileName: "ubuntu-toolchain-r-test.gpg" },
},
])
}