Skip to content

Commit 42d3519

Browse files
committed
ci: create pull requests as github app
1 parent e688a1c commit 42d3519

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

.github/scripts/generate-jwt.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { readFileSync } from "fs";
2+
import jsonwebtoken from "jsonwebtoken";
3+
4+
const { APP_ID } = process.env;
5+
6+
const privateKey = readFileSync("/dev/stdin", "utf8");
7+
const payload = {
8+
iat: Math.floor(Date.now() / 1000),
9+
exp: Math.floor(Date.now() / 1000) + 10 * 60,
10+
iss: APP_ID,
11+
};
12+
const token = jsonwebtoken.sign(payload, privateKey, { algorithm: "RS256" });
13+
console.log(token);

.github/scripts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"type": "module",
66
"dependencies": {
77
"execa": "^9.2.0",
8+
"jsonwebtoken": "^9.0.2",
89
"octokit": "^4.0.2",
910
"yn": "^5.0.0"
1011
}

.github/workflows/release.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,36 @@ jobs:
4545
- name: Install
4646
run: pnpm install --frozen-lockfile
4747

48-
- name: Setup Git User
49-
run: node .github/scripts/setup-git-user.js
50-
5148
- name: Build packages
5249
run: pnpm nx run-many -t build --projects=@knuckles/*
5350

5451
- name: Publish packages
5552
run: pnpm nx release publish
5653

54+
- name: Setup Git User
55+
run: node .github/scripts/setup-git-user.js
56+
57+
- name: Generate JWT and Get Installation Access Token
58+
id: auth
59+
run: |
60+
# Generate JWT
61+
JWT=$(APP_ID=${{ vars.GH_APP_ID }} \
62+
node .github/scripts/generate-jwt.js \
63+
<<< "${{ secrets.GH_APP_PRIVATE_KEY }}")
64+
65+
# Get Installation Access Token
66+
INSTALLATION_TOKEN=$(curl -X POST \
67+
-H "Authorization: Bearer $JWT" \
68+
-H "Accept: application/vnd.github.v3+json" \
69+
https://api.github.com/app/installations/${{ vars.GH_INSTALLATION_ID }}/access_tokens \
70+
| jq -r .token)
71+
72+
echo "TOKEN=${INSTALLATION_TOKEN}" >> $GITHUB_ENV
73+
5774
- name: Create Release Pull Request
5875
run: node .github/scripts/create-versioning-pull-request.js
5976
env:
60-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
GITHUB_TOKEN: ${{ env.TOKEN }}
6178
GITHUB_REPO: ${{ github.repository }}
6279
GITHUB_HEAD_BRANCH: "automated-versioning"
6380
GITHUB_BASE_BRANCH: "main"

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)