Skip to content

Commit 115b5b4

Browse files
committed
Use a GitHub App to grant permissions to the LLVM updating bot
1 parent 1d5c1e2 commit 115b5b4

1 file changed

Lines changed: 40 additions & 16 deletions

File tree

.github/workflows/upgrade-llvm.yml

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,48 @@ on:
55
- cron: "0 6 * * *" # Daily at 1am EST / 2am EDT
66
workflow_dispatch:
77

8-
permissions:
9-
contents: write
10-
pull-requests: write
8+
env:
9+
BRANCH: automated/upgrade-halide-llvm
1110

1211
jobs:
1312
upgrade:
14-
runs-on: ubuntu-latest
13+
runs-on: ubuntu-slim
1514
steps:
15+
- uses: actions/create-github-app-token@v2
16+
id: app-token
17+
with:
18+
app-id: ${{ secrets.LLVM_UPDATER_ID }}
19+
private-key: ${{ secrets.LLVM_UPDATER_PRIVATE_KEY }}
20+
21+
- name: Get GitHub App user ID
22+
id: get-user-id
23+
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
24+
env:
25+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
26+
27+
- name: Configure git and environment
28+
run: |
29+
echo "GH_TOKEN=${{ steps.app-token.outputs.token }}" >> "$GITHUB_ENV"
30+
git config --global user.name "${{ steps.app-token.outputs.app-slug }}[bot]"
31+
git config --global user.email "${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com"
32+
1633
- uses: actions/checkout@v4
34+
with:
35+
token: ${{ steps.app-token.outputs.token }}
36+
37+
- name: Switch to existing PR branch if present
38+
id: branch
39+
run: |
40+
if gh pr view "$BRANCH" --json state -q .state 2>/dev/null | grep -q OPEN; then
41+
echo "pr-exists=true" >> "$GITHUB_OUTPUT"
42+
git fetch origin "$BRANCH"
43+
git checkout "$BRANCH"
44+
else
45+
echo "pr-exists=false" >> "$GITHUB_OUTPUT"
46+
# Delete stale remote branch (e.g. leftover from a merged PR)
47+
git push origin --delete "$BRANCH" 2>/dev/null || true
48+
git checkout -b "$BRANCH"
49+
fi
1750
1851
- uses: astral-sh/setup-uv@v5
1952

@@ -38,25 +71,16 @@ jobs:
3871
3972
- name: Create or update PR
4073
if: steps.diff.outputs.changed == 'true'
41-
env:
42-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4374
run: |
44-
BRANCH="automated/upgrade-halide-llvm"
4575
TITLE="Upgrade halide-llvm to ${{ steps.diff.outputs.versions }}"
4676
47-
git config user.name "github-actions[bot]"
48-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
49-
git checkout -B "$BRANCH"
5077
git add uv.lock
5178
git commit -m "$TITLE"
5279
53-
# Update existing PR or create a new one
54-
if gh pr view "$BRANCH" --json state -q .state 2>/dev/null | grep -q OPEN; then
55-
git push -u origin "$BRANCH" --force-with-lease \
56-
&& gh pr edit "$BRANCH" --title "$TITLE"
80+
if [ "${{ steps.branch.outputs.pr-exists }}" = "true" ]; then
81+
git push -u origin "$BRANCH"
82+
gh pr edit "$BRANCH" --title "$TITLE"
5783
else
58-
# Delete stale remote branch (e.g. leftover from a merged PR)
59-
git push origin --delete "$BRANCH" 2>/dev/null || true
6084
git push -u origin "$BRANCH"
6185
gh pr create \
6286
--title "$TITLE" \

0 commit comments

Comments
 (0)