Skip to content

Commit 44d4a52

Browse files
authored
Upgrade deps (tibdex#64)
1 parent c3ff703 commit 44d4a52

10 files changed

+1066
-636
lines changed

.github/workflows/test.yml

+11-10
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v3
13-
- name: Install
14-
run: yarn install --frozen-lockfile
15-
- name: Deduplicate dependencies
16-
run: yarn run yarn-deduplicate --fail --strategy fewer
17-
- name: Build
18-
run: yarn run build
19-
- name: Format
20-
run: yarn run prettier --check
21-
- name: Lint
22-
run: yarn run xo
13+
- run: yarn install --frozen-lockfile
14+
- run: yarn run yarn-deduplicate --fail --strategy fewer
15+
- run: yarn run build
16+
- run: yarn run prettier --check
17+
- run: yarn run xo
18+
- id: generate_token
19+
uses: ./
20+
with:
21+
app_id: ${{ vars.TEST_GITHUB_APP_ID }}
22+
private_key: ${{ secrets.TEST_GITHUB_APP_PRIVATE_KEY }}
23+
- run: node --eval "assert('${{ steps.generate_token.outputs.token }}'.length > 0);"

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The MIT License (MIT)
2-
Copyright (c) 2022 Thibault Derousseaux <[email protected]>
2+
Copyright (c) 2023 Thibault Derousseaux <[email protected]>
33

44
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
55

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ jobs:
4646
run: |
4747
echo "The generated token is masked: ${TOKEN}"
4848
```
49+
50+
[Another use case for this action can (or could) be found in GitHub's own docs](https://web.archive.org/web/20230115194214/https://docs.github.com/en/issues/planning-and-tracking-with-projects/automating-your-project/automating-projects-using-actions#example-workflow-authenticating-with-a-github-app).

package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-app-token",
3-
"version": "1.7.0",
3+
"version": "1.8.0",
44
"license": "MIT",
55
"type": "module",
66
"files": [
@@ -9,31 +9,31 @@
99
],
1010
"scripts": {
1111
"prebuild": "tsc --build",
12-
"build": "ncc build src/index.ts --minify --target es2021 --v8-cache",
12+
"build": "ncc build src/index.ts --minify --target es2021 --v8-cache",
1313
"prettier": "prettier --ignore-path .gitignore \"./**/*.{cjs,js,json,md,ts,yml}\"",
1414
"xo": "xo"
1515
},
1616
"dependencies": {
1717
"@actions/core": "^1.10.0",
1818
"@actions/github": "^5.1.1",
19-
"@octokit/auth-app": "^4.0.7",
20-
"@octokit/request": "^6.2.2",
19+
"@octokit/auth-app": "^4.0.9",
20+
"@octokit/request": "^6.2.3",
2121
"ensure-error": "^4.0.0",
2222
"is-base64": "^1.1.0"
2323
},
2424
"devDependencies": {
25-
"@types/error-cause": "^1.0.1",
25+
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
2626
"@types/is-base64": "^1.1.1",
2727
"@types/node": "^16.11.26",
28-
"@vercel/ncc": "^0.34.0",
29-
"eslint-config-prettier": "^8.5.0",
30-
"eslint-plugin-import": "^2.26.0",
28+
"@vercel/ncc": "^0.36.1",
29+
"eslint-config-prettier": "^8.6.0",
30+
"eslint-plugin-import": "^2.27.5",
3131
"eslint-plugin-sort-destructure-keys": "^1.4.0",
3232
"eslint-plugin-typescript-sort-keys": "^2.1.0",
33-
"prettier": "^2.7.1",
34-
"prettier-plugin-packagejson": "^2.3.0",
35-
"typescript": "^4.8.4",
36-
"xo": "^0.52.4",
37-
"yarn-deduplicate": "^5.0.0"
33+
"prettier": "^2.8.3",
34+
"prettier-plugin-packagejson": "^2.4.0",
35+
"typescript": "^4.9.4",
36+
"xo": "^0.53.1",
37+
"yarn-deduplicate": "^6.0.1"
3838
}
3939
}

prettier.config.cjs

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"use strict";
22

33
module.exports = {
4+
importOrder: ["^node:(.*)$", "<THIRD_PARTY_MODULES>", "^[./]"],
5+
importOrderGroupNamespaceSpecifiers: true,
6+
importOrderSeparation: true,
7+
importOrderSortSpecifiers: true,
48
trailingComma: "all",
59
};

src/fetch-installation-token.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { getOctokit } from "@actions/github";
22
import { createAppAuth } from "@octokit/auth-app";
33
import { request } from "@octokit/request";
4-
import ensureError from "ensure-error";
54

65
export const fetchInstallationToken = async ({
76
appId,
@@ -42,7 +41,7 @@ export const fetchInstallationToken = async ({
4241
} catch (error: unknown) {
4342
throw new Error(
4443
"Could not get repo installation. Is the app installed on this repo?",
45-
{ cause: ensureError(error) },
44+
{ cause: error },
4645
);
4746
}
4847
}
@@ -56,7 +55,7 @@ export const fetchInstallationToken = async ({
5655
return installation.token;
5756
} catch (error: unknown) {
5857
throw new Error("Could not create installation access token.", {
59-
cause: ensureError(error),
58+
cause: error,
6059
});
6160
}
6261
};

src/index.ts

+43-45
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,49 @@
11
import { Buffer } from "node:buffer";
2+
23
import { getInput, info, setFailed, setOutput, setSecret } from "@actions/core";
34
import ensureError from "ensure-error";
45
import isBase64 from "is-base64";
6+
57
import { fetchInstallationToken } from "./fetch-installation-token.js";
68

7-
const run = async () => {
8-
try {
9-
const appId = getInput("app_id", { required: true });
10-
11-
const installationIdInput = getInput("installation_id");
12-
const installationId = installationIdInput
13-
? Number(installationIdInput)
14-
: undefined;
15-
16-
const permissionsInput = getInput("permissions");
17-
const permissions = permissionsInput
18-
? (JSON.parse(permissionsInput) as Record<string, string>)
19-
: undefined;
20-
21-
const privateKeyInput = getInput("private_key", { required: true });
22-
const privateKey = isBase64(privateKeyInput)
23-
? Buffer.from(privateKeyInput, "base64").toString("utf8")
24-
: privateKeyInput;
25-
26-
const repositoryInput = getInput("repository", { required: true });
27-
const [owner, repo] = repositoryInput.split("/");
28-
29-
const githubApiUrlInput = getInput("github_api_url", { required: true });
30-
const githubApiUrl = new URL(githubApiUrlInput);
31-
32-
const installationToken = await fetchInstallationToken({
33-
appId,
34-
githubApiUrl,
35-
installationId,
36-
owner,
37-
permissions,
38-
privateKey,
39-
repo,
40-
});
41-
42-
setSecret(installationToken);
43-
setOutput("token", installationToken);
44-
info("Token generated successfully!");
45-
} catch (_error: unknown) {
46-
const error = ensureError(_error);
47-
setFailed(error);
48-
}
49-
};
50-
51-
void run();
9+
try {
10+
const appId = getInput("app_id", { required: true });
11+
12+
const installationIdInput = getInput("installation_id");
13+
const installationId = installationIdInput
14+
? Number(installationIdInput)
15+
: undefined;
16+
17+
const permissionsInput = getInput("permissions");
18+
const permissions = permissionsInput
19+
? (JSON.parse(permissionsInput) as Record<string, string>)
20+
: undefined;
21+
22+
const privateKeyInput = getInput("private_key", { required: true });
23+
const privateKey = isBase64(privateKeyInput)
24+
? Buffer.from(privateKeyInput, "base64").toString("utf8")
25+
: privateKeyInput;
26+
27+
const repositoryInput = getInput("repository", { required: true });
28+
const [owner, repo] = repositoryInput.split("/");
29+
30+
const githubApiUrlInput = getInput("github_api_url", { required: true });
31+
const githubApiUrl = new URL(githubApiUrlInput);
32+
33+
const installationToken = await fetchInstallationToken({
34+
appId,
35+
githubApiUrl,
36+
installationId,
37+
owner,
38+
permissions,
39+
privateKey,
40+
repo,
41+
});
42+
43+
setSecret(installationToken);
44+
setOutput("token", installationToken);
45+
info("Token generated successfully!");
46+
} catch (_error: unknown) {
47+
const error = ensureError(_error);
48+
setFailed(error);
49+
}

tsconfig.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"compilerOptions": {
33
"forceConsistentCasingInFileNames": true,
4-
"module": "nodenext",
5-
"moduleResolution": "nodenext",
4+
"module": "Node16",
5+
"moduleResolution": "Node16",
66
"noEmit": true,
77
"strict": true,
8-
"target": "es2021",
9-
"types": ["node", "error-cause/auto"]
8+
"target": "ES2022",
9+
"types": ["node"]
1010
},
1111
"include": ["src"]
1212
}

xo.config.cjs

-11
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ module.exports = {
3131
},
3232
],
3333
"import/no-namespace": "error",
34-
"import/order": [
35-
"error",
36-
{
37-
alphabetize: {
38-
caseInsensitive: true,
39-
order: "asc",
40-
},
41-
"newlines-between": "never",
42-
},
43-
],
4434
"no-console": "error",
4535
"object-shorthand": [
4636
"error",
@@ -53,7 +43,6 @@ module.exports = {
5343
caseSensitive: false,
5444
},
5545
],
56-
"sort-imports": ["error", { ignoreDeclarationSort: true }],
5746
"sort-keys": [
5847
"error",
5948
"asc",

0 commit comments

Comments
 (0)