Skip to content

Commit 6b38420

Browse files
committed
chore: switch to github app automation tokens
1 parent 39953d3 commit 6b38420

File tree

3 files changed

+54
-14
lines changed

3 files changed

+54
-14
lines changed

.github/workflows/release.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
name: CD
1818
if: (!startsWith(github.event.head_commit.message, 'chore(release):'))
1919
runs-on: ubuntu-latest
20-
timeout-minutes: 30
20+
timeout-minutes: 15
2121
needs:
2222
- ci
2323
steps:
@@ -34,8 +34,14 @@ jobs:
3434
run: npm ci
3535
- name: Run build
3636
run: npm run build
37+
- name: Generate app token
38+
id: app-token
39+
uses: actions/[email protected]
40+
with:
41+
app-id: ${{secrets.GH_APP_ID}}
42+
private-key: ${{secrets.GH_APP_PRIVATE_KEY}}
3743
- name: Release
3844
run: npx semantic-release
3945
env:
40-
GITHUB_TOKEN: ${{secrets.RELEASE_TOKEN}}
46+
GITHUB_TOKEN: ${{steps.app-token.outputs.token}}
4147
NPM_TOKEN: ${{secrets.NPM_TOKEN}}

.github/workflows/update-license.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,42 @@ jobs:
3333
- name: Update LICENSE
3434
run: |
3535
sed -i -E "s/$REGEX/\1${{steps.info.outputs.license-year}}\2/" LICENSE
36+
- name: Generate app token
37+
id: app-token
38+
uses: actions/[email protected]
39+
with:
40+
app-id: ${{secrets.GH_APP_ID}}
41+
private-key: ${{secrets.GH_APP_PRIVATE_KEY}}
42+
- name: Generate user info
43+
id: user-info
44+
run: |
45+
USER_NAME="$GH_APP_SLUG[bot]"
46+
USER_ID=$(gh api "/users/$USER_NAME" --jq .id)
47+
USER_EMAIL="[email protected]"
48+
echo "id=$USER_ID" >> $GITHUB_OUTPUT
49+
echo "name=$USER_NAME" >> $GITHUB_OUTPUT
50+
echo "[email protected]" >> $GITHUB_OUTPUT
51+
echo "commit-author=$USER_NAME <$USER_EMAIL>" >> $GITHUB_OUTPUT
52+
env:
53+
GH_APP_SLUG: ${{steps.app-token.outputs.app-slug}}
54+
GH_TOKEN: ${{steps.app-token.outputs.token}}
3655
- name: Handle changes
3756
uses: peter-evans/[email protected]
3857
id: changes
3958
with:
40-
token: ${{secrets.AUTOMATION_TOKEN}}
59+
token: ${{steps.app-token.outputs.token}}
4160
commit-message: ${{steps.info.outputs.update-title}}
42-
committer: ${{env.GIT_USER}}
61+
author: ${{steps.user-info.outputs.commit-author}}
62+
committer: ${{steps.user-info.outputs.commit-author}}
4363
add-paths: LICENSE
44-
author: ${{env.GIT_USER}}
4564
branch: auto/update-license
4665
delete-branch: true
4766
title: ${{steps.info.outputs.update-title}}
4867
body: ${{steps.info.outputs.update-body}}
4968
labels: auto
50-
env:
51-
GIT_USER: ${{secrets.AUTOMATION_USER}} <${{secrets.AUTOMATION_EMAIL}}>
5269
- name: Enable auto-merge
5370
if: steps.changes.outputs.pull-request-operation == 'created'
5471
run: gh pr merge --auto --rebase "$PULL_REQUEST_URL"
5572
env:
5673
PULL_REQUEST_URL: ${{steps.changes.outputs.pull-request-url}}
57-
GITHUB_TOKEN: ${{secrets.AUTOMATION_TOKEN}}
74+
GITHUB_TOKEN: ${{steps.app-token.outputs.token}}

.github/workflows/update-node.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,42 @@ jobs:
3131
echo "update-body=$UPDATE_BODY" >> $GITHUB_OUTPUT
3232
- name: Update .nvmrc
3333
run: echo '${{steps.info.outputs.version}}' > .nvmrc
34+
- name: Generate app token
35+
id: app-token
36+
uses: actions/[email protected]
37+
with:
38+
app-id: ${{secrets.GH_APP_ID}}
39+
private-key: ${{secrets.GH_APP_PRIVATE_KEY}}
40+
- name: Generate user info
41+
id: user-info
42+
run: |
43+
USER_NAME="$GH_APP_SLUG[bot]"
44+
USER_ID=$(gh api "/users/$USER_NAME" --jq .id)
45+
USER_EMAIL="[email protected]"
46+
echo "id=$USER_ID" >> $GITHUB_OUTPUT
47+
echo "name=$USER_NAME" >> $GITHUB_OUTPUT
48+
echo "[email protected]" >> $GITHUB_OUTPUT
49+
echo "commit-author=$USER_NAME <$USER_EMAIL>" >> $GITHUB_OUTPUT
50+
env:
51+
GH_APP_SLUG: ${{steps.app-token.outputs.app-slug}}
52+
GH_TOKEN: ${{steps.app-token.outputs.token}}
3453
- name: Handle changes
3554
uses: peter-evans/[email protected]
3655
id: changes
3756
with:
38-
token: ${{secrets.AUTOMATION_TOKEN}}
57+
token: ${{steps.app-token.outputs.token}}
3958
commit-message: ${{steps.info.outputs.update-title}}
40-
committer: ${{env.GIT_USER}}
59+
author: ${{steps.user-info.outputs.commit-author}}
60+
committer: ${{steps.user-info.outputs.commit-author}}
4161
add-paths: .nvmrc
42-
author: ${{env.GIT_USER}}
4362
branch: auto/update-node
4463
delete-branch: true
4564
title: ${{steps.info.outputs.update-title}}
4665
body: ${{steps.info.outputs.update-body}}
4766
labels: auto,dependencies
48-
env:
49-
GIT_USER: ${{secrets.AUTOMATION_USER}} <${{secrets.AUTOMATION_EMAIL}}>
5067
- name: Enable auto-merge
5168
if: steps.changes.outputs.pull-request-operation == 'created'
5269
run: gh pr merge --auto --rebase "$PULL_REQUEST_URL"
5370
env:
5471
PULL_REQUEST_URL: ${{steps.changes.outputs.pull-request-url}}
55-
GITHUB_TOKEN: ${{secrets.AUTOMATION_TOKEN}}
72+
GITHUB_TOKEN: ${{steps.app-token.outputs.token}}

0 commit comments

Comments
 (0)