Skip to content

Commit

Permalink
fix!: only support a single repository/key for each apt package
Browse files Browse the repository at this point in the history
BREAKING the option for repositories/keys are now singular instead of an array
  • Loading branch information
aminya committed Aug 28, 2024
1 parent 2032957 commit adb1af1
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 129 deletions.
56 changes: 28 additions & 28 deletions dist/actions/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/actions/setup-cpp.js.map

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions dist/modern/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.js.map

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions packages/setup-apt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
},
])
```
Expand Down Expand Up @@ -154,7 +152,7 @@ Add an apt key

```ts
await addAptKey({
keys: ["3B4FE6ACC0B21F32", "40976EAF437D05B5"],
key: "3B4FE6ACC0B21F32"
fileName: "bazel-archive-keyring.gpg",
})
```
Expand All @@ -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>

Expand Down
34 changes: 15 additions & 19 deletions packages/setup-apt/src/apt-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`)
*/
Expand All @@ -67,28 +67,24 @@ 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)
const filePath = join(keyStorePath, fileName)
if (!(await pathExists(filePath))) {
initGpg()

await Promise.all(
keys.map(async (key) => {
await execRoot("gpg", [
"--no-default-keyring",
"--keyring",
`gnupg-ring:${filePath}`,
"--keyserver",
keyServer,
"--recv-keys",
key,
])
await execRoot("chmod", ["644", filePath])
}),
)
await execRoot("gpg", [
"--no-default-keyring",
"--keyring",
`gnupg-ring:${filePath}`,
"--keyserver",
keyServer,
"--recv-keys",
key,
])
await execRoot("chmod", ["644", filePath])
}
return filePath
} catch (err) {
Expand Down
18 changes: 9 additions & 9 deletions packages/setup-apt/src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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" },
},
])
* ```
Expand Down Expand Up @@ -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)
}
}))
}
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions src/gcc/gcc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
},
])
}
Expand All @@ -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" },
}])
}
}
Expand Down Expand Up @@ -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" },
},
])
}
Expand Down

0 comments on commit adb1af1

Please sign in to comment.