Skip to content

Commit c95cb12

Browse files
authored
Fix clang-format auto-fixes (#4795)
#### Summary and motivation Branch protections were limiting the ability for GitHub Actions to push straight to master, so I created a GitHub App and granted that app the ability to bypass. Now the clang-format job will use the GitHub App for pushes to master. Org owners can manage [the app](https://github.com/organizations/multitheftauto/settings/apps/multitheftauto) and separately manage [the app installation](https://github.com/organizations/multitheftauto/settings/installations/122647713) at those pages. #### Test plan See commit history of this branch 😀 My pull request is based on `master` on my branch, with the bot set up.
1 parent 50ef80c commit c95cb12

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

.github/workflows/clang-format.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,27 @@ jobs:
1818
shell: pwsh
1919
run: ./utils/clang-format.ps1 -Verbose
2020

21+
- name: Generate GitHub App token
22+
id: app-token
23+
if: |
24+
steps.clang_format.outcome == 'failure' &&
25+
github.ref == 'refs/heads/master' &&
26+
github.event_name == 'push' &&
27+
!github.event.repository.fork
28+
uses: actions/create-github-app-token@v3
29+
with:
30+
client-id: ${{ secrets.GH_APP_MTA_CLIENT_ID }}
31+
private-key: ${{ secrets.GH_APP_MTA_PEM }}
32+
owner: ${{ github.repository_owner }}
33+
repositories: ${{ github.event.repository.name }}
34+
permission-contents: write
35+
2136
- name: Auto-fix formatting issues
2237
if: |
2338
steps.clang_format.outcome == 'failure' &&
2439
github.ref == 'refs/heads/master' &&
25-
github.event_name == 'push'
40+
github.event_name == 'push' &&
41+
!github.event.repository.fork
2642
shell: bash
2743
run: |
2844
# Stage the formatted files (clang-format.ps1 already ran in-place)
@@ -38,15 +54,16 @@ jobs:
3854
fi
3955
4056
# Allow commit to work
41-
git config user.name "github-actions[bot]"
42-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
57+
git config user.name "multitheftauto[bot]"
58+
git config user.email "274826127+multitheftauto[bot]@users.noreply.github.com"
4359
4460
# Append a commit with a fix applied
4561
git commit -m "Fix formatting issues introduced by ${GITHUB_SHA}
4662
4763
cc @${GITHUB_ACTOR} please make sure to run clang-format locally before pushing changes to avoid this in the future."
4864
49-
# And we're off to the races!
65+
# Authenticate with the GitHub App token and push
66+
git remote set-url origin https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/${{ github.repository }}
5067
git push
5168
5269
- name: Report formatting issues

0 commit comments

Comments
 (0)