Skip to content

Commit 0bbce5a

Browse files
committed
chore: migrate triage workflows to GitHub App (leanprover-community#34752)
This PR migrates `maintainer_bors.yml`, `maintainer_bors_wf_run.yml`, `maintainer_merge.yml`, and `maintainer_merge_wf_run.yml` from using a personal access token (`TRIAGE_TOKEN`) to using a GitHub App. 🤖 Prepared with Claude Code
1 parent 51350af commit 0bbce5a

4 files changed

Lines changed: 48 additions & 11 deletions

File tree

.github/workflows/maintainer_bors.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,19 @@ jobs:
2323
COMMENT_REVIEW: ${{ github.event.review.body }}
2424
PR_NUMBER: ${{ github.event.issue.number }}${{ github.event.pull_request.number }}
2525
HAS_DELEGATED_LABEL: ${{ contains(github.event.issue.labels.*.name, 'delegated') }}
26+
HAS_TRIAGE_SECRET: ${{ secrets.MATHLIB_TRIAGE_APP_ID != '' }}
2627
name: Add ready-to-merge or delegated label
2728
runs-on: ubuntu-latest
2829
if: github.repository == 'leanprover-community/mathlib4'
2930
steps:
31+
- name: Generate app token
32+
if: ${{ env.HAS_TRIAGE_SECRET == 'true' }}
33+
id: app-token
34+
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
35+
with:
36+
app-id: ${{ secrets.MATHLIB_TRIAGE_APP_ID }}
37+
private-key: ${{ secrets.MATHLIB_TRIAGE_PRIVATE_KEY }}
38+
3039
- name: Find bors merge/delegate
3140
id: merge_or_delegate
3241
run: |
@@ -58,7 +67,8 @@ jobs:
5867
printf $'removeLabels=%s\n' "${remove_labels}" >> "${GITHUB_OUTPUT}"
5968
if [ "${AUTHOR}" == 'leanprover-community-mathlib4-bot' ] ||
6069
[ "${AUTHOR}" == 'leanprover-community-bot-assistant' ] ||
61-
[ "${AUTHOR}" == 'mathlib-bors[bot]' ]
70+
[ "${AUTHOR}" == 'mathlib-bors[bot]' ] ||
71+
[ "${AUTHOR}" == 'mathlib-triage[bot]' ]
6272
then
6373
printf $'bot=true\n'
6474
printf $'bot=true\n' >> "${GITHUB_OUTPUT}"
@@ -70,7 +80,7 @@ jobs:
7080
fi
7181
7282
# write an artifact with all data needed below if we don't have access to necessary secrets
73-
if [[ -z '${{ secrets.TRIAGE_TOKEN }}' ]]
83+
if [[ -z '${{ secrets.MATHLIB_TRIAGE_APP_ID }}' ]]
7484
then
7585
printf 'No access to secrets, writing to file.\n'
7686
jq -n \
@@ -131,7 +141,8 @@ jobs:
131141
issue_number: ${{ github.event.issue.number }}${{ github.event.pull_request.number }}
132142
labels: '["${{ steps.merge_or_delegate.outputs.mOrD }}"]'
133143
env:
134-
GITHUB_TOKEN: ${{ secrets.TRIAGE_TOKEN }}
144+
# The create-github-app-token README states that this token is masked and will not be logged accidentally.
145+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
135146

136147
- if: ${{ ! steps.merge_or_delegate.outputs.secrets == '' &&
137148
(! steps.merge_or_delegate.outputs.mOrD == '' &&
@@ -145,7 +156,7 @@ jobs:
145156
for label in awaiting-author maintainer-merge; do
146157
curl --request DELETE \
147158
--url "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}${{ github.event.pull_request.number }}/labels/${label}" \
148-
--header 'authorization: Bearer ${{ secrets.TRIAGE_TOKEN }}'
159+
--header 'authorization: Bearer ${{ steps.app-token.outputs.token }}'
149160
done
150161
151162
- name: On bors r/d-, remove ready-to-merge or delegated label
@@ -158,7 +169,7 @@ jobs:
158169
for label in ready-to-merge delegated; do
159170
curl --request DELETE \
160171
--url "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}${{ github.event.pull_request.number }}/labels/${label}" \
161-
--header 'authorization: Bearer ${{ secrets.TRIAGE_TOKEN }}'
172+
--header 'authorization: Bearer ${{ steps.app-token.outputs.token }}'
162173
done
163174
164175
- name: Set up Python

.github/workflows/maintainer_bors_wf_run.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ jobs:
1313
runs-on: ubuntu-latest
1414
if: ${{ github.repository == 'leanprover-community/mathlib4' && github.event.workflow_run.conclusion == 'success' }}
1515
steps:
16+
- name: Generate app token
17+
id: app-token
18+
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
19+
with:
20+
app-id: ${{ secrets.MATHLIB_TRIAGE_APP_ID }}
21+
private-key: ${{ secrets.MATHLIB_TRIAGE_PRIVATE_KEY }}
22+
1623
- name: Download artifact
1724
id: download-artifact
1825
uses: dawidd6/action-download-artifact@5c98f0b039f36ef966fdb7dfa9779262785ecb05 # v14
@@ -80,7 +87,8 @@ jobs:
8087
issue_number: ${{ steps.extract-data.outputs.pr_number }}
8188
labels: '["${{ steps.extract-data.outputs.mOrD }}"]'
8289
env:
83-
GITHUB_TOKEN: ${{ secrets.TRIAGE_TOKEN }}
90+
# The create-github-app-token README states that this token is masked and will not be logged accidentally.
91+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
8492

8593
- if: ${{ ! steps.extract-data.outputs.mOrD == '' &&
8694
( steps.user_permission.outputs.require-result == 'true' ||
@@ -93,7 +101,7 @@ jobs:
93101
for label in awaiting-author maintainer-merge; do
94102
curl --request DELETE \
95103
--url "https://api.github.com/repos/${{ github.repository }}/issues/${{ steps.extract-data.outputs.pr_number }}/labels/${label}" \
96-
--header 'authorization: Bearer ${{ secrets.TRIAGE_TOKEN }}'
104+
--header 'authorization: Bearer ${{ steps.app-token.outputs.token }}'
97105
done
98106
99107
- name: On bors r/d-, remove ready-to-merge or delegated label
@@ -104,7 +112,7 @@ jobs:
104112
for label in ready-to-merge delegated; do
105113
curl --request DELETE \
106114
--url "https://api.github.com/repos/${{ github.repository }}/issues/${{ steps.extract-data.outputs.pr_number }}/labels/${label}" \
107-
--header 'authorization: Bearer ${{ secrets.TRIAGE_TOKEN }}'
115+
--header 'authorization: Bearer ${{ steps.app-token.outputs.token }}'
108116
done
109117
110118
- name: Set up Python

.github/workflows/maintainer_merge.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
PR_TITLE_PR: ${{ github.event.pull_request.title }}
2828
PR_URL: ${{ github.event.issue.html_url }}${{ github.event.pull_request.html_url }}
2929
EVENT_NAME: ${{ github.event_name }}
30+
HAS_TRIAGE_SECRET: ${{ secrets.MATHLIB_TRIAGE_APP_ID != '' }}
3031
name: Ping maintainers on Zulip
3132
runs-on: ubuntu-latest
3233
if: >- # crude check to skip running this on most reviews / comments
@@ -36,6 +37,14 @@ jobs:
3637
contains(format('{0}{1}', github.event.comment.body, github.event.review.body), 'maintainer delegate')
3738
)
3839
steps:
40+
- name: Generate app token
41+
if: ${{ env.HAS_TRIAGE_SECRET == 'true' }}
42+
id: app-token
43+
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
44+
with:
45+
app-id: ${{ secrets.MATHLIB_TRIAGE_APP_ID }}
46+
private-key: ${{ secrets.MATHLIB_TRIAGE_PRIVATE_KEY }}
47+
3948
- name: Find maintainer merge/delegate
4049
id: merge_or_delegate
4150
run: |
@@ -58,7 +67,7 @@ jobs:
5867
printf $'mOrD=%s\n' "${m_or_d}" > "${GITHUB_OUTPUT}"
5968
6069
# write an artifact with all data needed below if we don't have access to necessary secrets
61-
if [[ -z '${{ secrets.MATHLIB_REVIEWERS_TEAM_KEY }}' ]]
70+
if [[ -z '${{ secrets.MATHLIB_TRIAGE_APP_ID }}' ]]
6271
then
6372
printf 'No access to secrets, writing to file.\n'
6473
jq -n \
@@ -167,7 +176,8 @@ jobs:
167176
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
168177
with:
169178
# labels added by GITHUB_TOKEN won't trigger the Zulip emoji workflow
170-
github-token: ${{secrets.TRIAGE_TOKEN}}
179+
# The create-github-app-token README states that this token is masked and will not be logged accidentally.
180+
github-token: ${{ steps.app-token.outputs.token }}
171181
script: |
172182
const { owner, repo, number: issue_number } = context.issue;
173183
await github.rest.issues.addLabels({ owner, repo, issue_number, labels: ['maintainer-merge'] });

.github/workflows/maintainer_merge_wf_run.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ jobs:
1313
runs-on: ubuntu-latest
1414
if: ${{ github.repository == 'leanprover-community/mathlib4' && github.event.workflow_run.conclusion == 'success' }}
1515
steps:
16+
- name: Generate app token
17+
id: app-token
18+
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
19+
with:
20+
app-id: ${{ secrets.MATHLIB_TRIAGE_APP_ID }}
21+
private-key: ${{ secrets.MATHLIB_TRIAGE_PRIVATE_KEY }}
22+
1623
- name: Download artifact
1724
id: download-artifact
1825
uses: dawidd6/action-download-artifact@5c98f0b039f36ef966fdb7dfa9779262785ecb05 # v14
@@ -140,7 +147,8 @@ jobs:
140147
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
141148
with:
142149
# labels added by GITHUB_TOKEN won't trigger the Zulip emoji workflow
143-
github-token: ${{secrets.TRIAGE_TOKEN}}
150+
# The create-github-app-token README states that this token is masked and will not be logged accidentally.
151+
github-token: ${{ steps.app-token.outputs.token }}
144152
script: |
145153
const { owner, repo } = context.repo;
146154
const issue_number = ${{ steps.extract-data.outputs.pr_number }};

0 commit comments

Comments
 (0)