Skip to content

Commit

Permalink
Add better error handling to format-pr workflow (#1918)
Browse files Browse the repository at this point in the history
It will now leave a comment when it hits a known failure case
  • Loading branch information
GarboMuffin authored Feb 7, 2025
1 parent f80c813 commit 0eb2af5
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions .github/workflows/format-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,16 @@ jobs:
comment-push:
runs-on: ubuntu-latest
needs: comment-format-untrusted
permissions:
# Needed for the temporary token to have permission to leave comments.
pull-requests: write
steps:
- name: Checkout upstream
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
repository: TurboWarp/extensions
# Can't use the default workflow token because commits made by it won't cause more
# workflows to un, so any commits it pushes get stuck in limbo waiting for workflows
# workflows to run, so any commits it pushes get stuck in limbo waiting for workflows
# to run that will never run.
# Can't use a deploy key because it won't be able to access the fork that the pull
# request is coming from.
Expand All @@ -113,15 +116,32 @@ jobs:
with:
name: comment-format-untrusted-artifact
path: extensions
- name: Commit
- name: Commit and push
run: |
# It wouldn't be hard to include the branch name in the comments, but that is untrusted input so it
# doesn't seem like a good idea to let anyone get the bot to say anything they want.
commit_failed() {
echo "No changes to commit"
gh pr comment "$PR_NUM" -b "The formatting bot didn't find any formatting issues. It currently only checks the extensions folder. To format all files, the pull request's author can manually run the 'Format pull request' workflow from the 'Actions' tab on the fork."
exit 0
}
push_failed() {
echo "Failed to push"
gh pr comment "$PR_NUM" -b "The formatting bot couldn't push changes. Either maintainer edit permission is disabled or the pull request is from a non-personal account. The pull request's author can still run the 'Format pull request' workflow from the 'Actions' tab on the fork."
exit 0
}
git config --global user.name "$GITHUB_ACTOR"
git config --global user.email "[email protected]"
git stage .
git commit --author "DangoCat[bot] <[email protected]>" -m "[Automated] Format code" || echo "No changes to commit"
- name: Push
# Explicitly set push.default to upstream, otherwise by default git might complain about us being on a
# branch called "DangoCat/master" but the corresponding branch on remote "DangoCat" is just "master".
run: |
git commit --author "DangoCat[bot] <[email protected]>" -m "[Automated] Format code" || commit_failed
# Explicitly set push.default to upstream, otherwise by default git might complain about us being on a
# branch called "DangoCat/master" but the corresponding branch on remote "DangoCat" is just "master".
git config --global push.default upstream
git push
git push || push_failed
env:
PR_NUM: "${{ github.event.issue.number }}"
GH_TOKEN: "${{ github.token }}"

0 comments on commit 0eb2af5

Please sign in to comment.