-
Notifications
You must be signed in to change notification settings - Fork 17
75 lines (62 loc) · 2.63 KB
/
runclangformat.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Run ClangFormat
on:
issue_comment: # GitHub PRs are considered the same type of thing as issues.
types: [ created ]
jobs:
reformat:
name: ClangFormat
# If we are a pull_request, we have the trigger comment, and the person
# requesting is the one who made the PR, then we run.
if: >-
github.event.issue.pull_request != ''
&& github.event.comment.body == 'Do: Reformat'
&& github.event.comment.user.id == github.event.issue.user.id
# We must run on a ubuntu, as we use unix-only commands
runs-on: ubuntu-latest
steps:
# Add an emote reaction to acknowledge the request.
# For long-running tasks, this is helpful.
# For just clang-format, it may not be needed, but it's still nice.
- name: Acknowledge
uses: peter-evans/create-or-update-comment@v1.4.1
with:
comment-id: ${{ github.event.comment.id }}
reactions: rocket # (Launch)
- uses: actions/checkout@v2
with:
# We need the entire history so that we can rebase many commits.
fetch-depth: 0
- name: Checkout PR
uses: dawidd6/action-checkout-pr@v1
with:
pr: ${{ github.event.issue.number }}
- name: Get clang-format
run: sudo apt-get install clang-format-9
- name: Clang format each commit in place
run: |
# Git requires user email and name to do commits.
# As we are only amending each commit, these shouldn't end up in the
# history.
# Set user email to the email of the last commit:
git config --local user.email "$(git log -n 1 --pretty=format:'%ae')"
git config --local user.name 'GitHub Action'
# Rebases every commit since when this PR branched off of master.
# The sed command tells git that we want to edit the code for each commit.
GIT_EDITOR="sed -iE 's/^pick/edit/g'" git rebase -i $(git merge-base master HEAD)
# Abort on error
set -e
echo '>>> Beginning Rebasing...'
# While a rebase is ongoing, `git status` contains the text "rebase".
while [[ -n $(git status | grep rebase) ]]; do
# Run clang-format
find . -name '*.hpp' -o -name '*.cpp' | xargs -L1 clang-format-9 -style=file -i --verbose
# Add all changes and update the commit
echo '>>> Rewriting commit...'
git add -A
git commit --amend --no-edit
echo '>>> Continuing Rebasing...'
git rebase --continue
done
echo '>>> Finished Rebasing!'
- name: Push
run: git push --force -v