Skip to content
This repository was archived by the owner on Jul 7, 2025. It is now read-only.

Commit b077f95

Browse files
authored
Update dependencies and support custom installation_id (#26)
1 parent 516ef60 commit b077f95

File tree

13 files changed

+2011
-825
lines changed

13 files changed

+2011
-825
lines changed

.eslintrc.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ on:
77
jobs:
88
publish:
99
name: Publish
10-
runs-on: ubuntu-18.04
10+
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v1
12+
- uses: actions/checkout@v2
1313
- uses: dylanvann/[email protected]
1414
with:
1515
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ on:
77
jobs:
88
test:
99
name: Test
10-
runs-on: ubuntu-18.04
10+
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v1
12+
- uses: actions/checkout@v2
1313
- name: Install
1414
run: yarn install --frozen-lockfile
15+
- name: Deduplicate dependencies
16+
run: yarn run yarn-deduplicate --fail
1517
- name: Build
1618
run: yarn run build
17-
- name: ESLint
18-
run: yarn run eslint
19-
- name: Prettier
20-
run: yarn run check-prettier
19+
- name: Format
20+
run: yarn run prettier --check
21+
- name: Lint
22+
run: yarn run xo

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The MIT License (MIT)
2-
Copyright (c) 2020 Thibault Derousseaux <[email protected]>
2+
Copyright (c) 2021 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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ However, for organizations, GitHub Apps are [a more appropriate automation solut
1111
```yml
1212
jobs:
1313
job:
14-
runs-on: ubuntu-18.04
14+
runs-on: ubuntu-latest
1515
steps:
1616
- name: Generate token
1717
id: generate_token
1818
uses: tibdex/github-app-token@v1
1919
with:
2020
app_id: ${{ secrets.APP_ID }}
2121
private_key: ${{ secrets.PRIVATE_KEY }}
22+
# Optional (defaults to ID of the repository's installation).
23+
# installation_id: 1337
2224
# Optional (defaults to the current repository).
23-
# repository: owner/repo
25+
# repository: "owner/repo"
2426
- name: Use token
2527
env:
2628
TOKEN: ${{ steps.generate_token.outputs.token }}

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ inputs:
88
private_key:
99
description: Private key of the GitHub App (can be Base64 encoded).
1010
required: true
11+
installation_id:
12+
description: The ID of the installation for which the token will be requested (defaults to the ID of the repository's installation).
1113
repository:
1214
description: The full name of the repository for which the token will be requested (defaults to the current repository).
1315
outputs:

package.json

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
11
{
22
"name": "github-app-token",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"license": "MIT",
5+
"main": "dist/index.js",
56
"files": [
67
"action.yml",
78
"dist"
89
],
9-
"main": "dist/index.js",
1010
"scripts": {
11-
"build": "ncc build src/index.ts --minify --v8-cache",
12-
"check-prettier": "yarn run prettier --check",
13-
"eslint": "eslint --ignore-path .gitignore --max-warnings 0 \"./**/*.{js,ts}\"",
14-
"format-prettier": "yarn run prettier --write",
15-
"prettier": "prettier --ignore-path .gitignore \"./**/*.{js,json,md,ts,yml}\""
11+
"build": "ncc build src/index.ts --minify --target es2018 --v8-cache",
12+
"prettier": "prettier --ignore-path .gitignore \"./**/*.{js,json,md,ts,yml}\"",
13+
"xo": "xo"
1614
},
1715
"devDependencies": {
18-
"@actions/core": "^1.2.6",
19-
"@actions/github": "^4.0.0",
20-
"@octokit/auth-app": "^2.10.5",
21-
"@types/is-base64": "^1.1.0",
22-
"@types/node": "^14.14.14",
23-
"@typescript-eslint/eslint-plugin": "^4.10.0",
24-
"@typescript-eslint/parser": "^4.10.0",
25-
"@vercel/ncc": "^0.26.1",
26-
"eslint": "^7.16.0",
27-
"eslint-config-prettier": "^7.1.0",
28-
"eslint-config-xo": "^0.33.1",
29-
"eslint-config-xo-typescript": "^0.37.0",
30-
"eslint-import-resolver-typescript": "^2.3.0",
31-
"eslint-plugin-import": "^2.22.1",
32-
"eslint-plugin-sort-destructure-keys": "^1.3.5",
33-
"eslint-plugin-typescript-sort-keys": "^1.5.0",
34-
"eslint-plugin-unicorn": "^24.0.0",
16+
"@actions/core": "^1.6.0",
17+
"@actions/github": "^5.0.0",
18+
"@octokit/auth-app": "^3.6.1",
19+
"@octokit/request": "^5.6.2",
20+
"@types/is-base64": "^1.1.1",
21+
"@types/node": "^16.11.6",
22+
"@vercel/ncc": "^0.31.1",
23+
"eslint-config-prettier": "^8.3.0",
24+
"eslint-plugin-import": "^2.25.2",
25+
"eslint-plugin-sort-destructure-keys": "^1.4.0",
26+
"eslint-plugin-typescript-sort-keys": "^2.0.0",
3527
"is-base64": "^1.1.0",
36-
"prettier": "^2.2.1",
37-
"promise-retry": "^2.0.1",
38-
"typescript": "^4.1.3"
28+
"prettier": "^2.4.1",
29+
"prettier-plugin-packagejson": "^2.2.13",
30+
"typescript": "^4.4.4",
31+
"xo": "^0.46.4",
32+
"yarn-deduplicate": "^3.1.0"
3933
}
4034
}
File renamed without changes.

src/fetch-installation-token.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
import { env } from "process";
12
import { getOctokit } from "@actions/github";
23
import { createAppAuth } from "@octokit/auth-app";
34
import { request } from "@octokit/request";
45

56
export const fetchInstallationToken = async ({
67
appId,
8+
installationId,
79
owner,
810
privateKey,
911
repo,
1012
}: Readonly<{
1113
appId: string;
14+
installationId?: number;
1215
owner: string;
1316
privateKey: string;
1417
repo: string;
@@ -19,14 +22,18 @@ export const fetchInstallationToken = async ({
1922
request: request.defaults({
2023
// GITHUB_API_URL is part of GitHub Actions' built-in environment variables.
2124
// See https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables.
22-
baseUrl: process.env["GITHUB_API_URL"]
23-
})
25+
baseUrl: env.GITHUB_API_URL,
26+
}),
2427
});
25-
const authApp = await app({ type: "app" });
26-
const octokit = getOctokit(authApp.token);
27-
const {
28-
data: { id: installationId },
29-
} = await octokit.apps.getRepoInstallation({ owner, repo });
28+
29+
if (installationId === undefined) {
30+
const authApp = await app({ type: "app" });
31+
const octokit = getOctokit(authApp.token);
32+
({
33+
data: { id: installationId },
34+
} = await octokit.rest.apps.getRepoInstallation({ owner, repo }));
35+
}
36+
3037
const installation = await app({ installationId, type: "installation" });
3138
return installation.token;
3239
};

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import { Buffer } from "buffer";
12
import { getInput, info, setFailed, setOutput, setSecret } from "@actions/core";
23
import { context } from "@actions/github";
3-
44
import isBase64 from "is-base64";
5-
65
import { fetchInstallationToken } from "./fetch-installation-token";
76

87
const run = async () => {
@@ -13,13 +12,15 @@ const run = async () => {
1312
? Buffer.from(privateKeyInput, "base64").toString("utf8")
1413
: privateKeyInput;
1514

15+
const installationId = getInput("installation_id");
1616
const repositoryInput = getInput("repository");
1717
const [owner, repo] = repositoryInput
1818
? repositoryInput.split("/")
1919
: [context.repo.owner, context.repo.repo];
2020

2121
const installationToken = await fetchInstallationToken({
2222
appId,
23+
installationId: installationId ? Number(installationId) : undefined,
2324
owner,
2425
privateKey,
2526
repo,

0 commit comments

Comments
 (0)