Skip to content

Commit 5e3bb46

Browse files
committed
chore: use github app for builds
1 parent 61890b8 commit 5e3bb46

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
- run:
1919
name: Updating schema
2020
command: |
21+
git clone "https://x-access-token:$(./scripts/github_token.js 290530)@github.com/heroku/typescript-api-schema.git" repo
22+
cd repo
2123
git config --global push.default simple
2224
git config --global user.name "$GIT_AUTHOR_NAME"
2325
git config --global user.email "$GIT_AUTHOR_EMAIL"

scripts/github_token.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env node
2+
3+
// gets a github auth token for a github app
4+
5+
const jwt = require('jsonwebtoken')
6+
const {HTTP} = require('http-call')
7+
const exp = new Date()
8+
exp.setMinutes(exp.getMinutes() + 10)
9+
const env = k => {
10+
if (process.env[k]) return process.env[k]
11+
else throw new Error(`Must set ${k}`)
12+
}
13+
14+
const token = jwt.sign({
15+
// iss: env('GITHUB_APP_ID')
16+
}, env('GITHUB_APP_PEM'), {
17+
issuer: env('GITHUB_APP_ID'),
18+
algorithm: 'RS256',
19+
expiresIn: '10m'
20+
})
21+
22+
const installation = process.argv[2]
23+
24+
async function run () {
25+
const {body} = await HTTP.post(`https://api.github.com/app/installations/${installation}/access_tokens`, {
26+
headers: {
27+
Authorization: `Bearer ${token}`,
28+
Accept: 'application/vnd.github.machine-man-preview+json"'
29+
}
30+
})
31+
console.log(body.token)
32+
}
33+
34+
run()
35+
.catch(err => {
36+
console.error(err)
37+
process.exit(1)
38+
})

0 commit comments

Comments
 (0)