Skip to content

Commit 5a8fe26

Browse files
authored
Merge pull request #19 from rust-lang/ci-gh-app
Use GitHub app for PR authentication
2 parents 9267510 + 72e0cb5 commit 5a8fe26

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

.github/workflows/rustc-pull.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: 'Josh Subtree Sync'
33
on:
44
workflow_call:
55
inputs:
6+
github-app-id:
7+
description: 'ID of a GitHub app that will create the sync PR'
8+
required: true
9+
type: string
610
branch-name:
711
description: 'Name of the branch to create for the sync'
812
required: false
@@ -27,8 +31,8 @@ on:
2731
required: false
2832
type: string
2933
secrets:
30-
token:
31-
description: 'GITHUB_TOKEN from the caller workflow'
34+
github-app-secret:
35+
description: 'Secret for a GitHub app that will create the sync PR'
3236
required: true
3337
zulip-api-token:
3438
description: 'Zulip API token for authentication'
@@ -81,6 +85,12 @@ jobs:
8185
8286
exit ${exitcode}
8387
88+
- uses: actions/create-github-app-token@v2
89+
id: app-token
90+
with:
91+
app-id: ${{ inputs.github-app-id }}
92+
private-key: ${{ secrets.github-app-secret }}
93+
8494
- name: Push changes to a branch
8595
if: ${{ steps.josh-sync.outputs.pull_result == 'pull-finished' }}
8696
run: |
@@ -92,7 +102,7 @@ jobs:
92102
id: update-pr
93103
if: ${{ steps.josh-sync.outputs.pull_result == 'pull-finished' }}
94104
env:
95-
GITHUB_TOKEN: ${{ secrets.token }}
105+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
96106
run: |
97107
# Check if an open pull request already exists
98108
RESULT=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | length' --json title`
@@ -114,10 +124,16 @@ jobs:
114124
steps:
115125
- uses: actions/checkout@v4
116126

127+
- uses: actions/create-github-app-token@v2
128+
id: app-token
129+
with:
130+
app-id: ${{ inputs.github-app-id }}
131+
private-key: ${{ secrets.github-app-secret }}
132+
117133
- name: Compute message
118134
id: create-message
119135
env:
120-
GITHUB_TOKEN: ${{ secrets.token }}
136+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
121137
run: |
122138
if [ "${{ needs.perform-pull.result }}" == "failure" ]; then
123139
WORKFLOW_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,19 @@ jobs:
6060
pull:
6161
uses: rust-lang/josh-sync/.github/workflows/rustc-pull.yml@main
6262
with:
63+
github-app-id: ${{ vars.APP_CLIENT_ID }}
6364
# If you want the Zulip post functionality
6465
#zulip-stream-id: 1234 # optional
6566
#zulip-bot-email: [email protected] # optional
6667
pr-base-branch: master # optional
6768
branch-name: rustc-pull # optional
6869
secrets:
6970
#zulip-api-token: <Zulip API TOKEN> # optional
70-
token: ${{ secrets.GITHUB_TOKEN }}
71+
github-app-secret: ${{ secrets.APP_PRIVATE_KEY }}
7172
```
7273
74+
You will need to have a GitHub app configured on the repository with permissions to create pull requests in order to use the workflow.
75+
7376
## Git peculiarities
7477
7578
NOTE: If you use Git/SSH protocol to push to your fork of [rust-lang/rust],

0 commit comments

Comments
 (0)