File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed
Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -3,24 +3,31 @@ name: Clang format
33on : [pull_request]
44
55jobs :
6- clang-format-8 :
6+ clang-format :
77 runs-on : ubuntu-latest
88 steps :
99 - uses : actions/checkout@v2
1010 with :
1111 ref : ${{ github.event.pull_request.head.sha }}
12- - name : Run clang-foramt on changed files
12+
13+ - name : Install prerequisites
14+ run : |
15+ sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-11 100
16+ sudo update-alternatives --install /usr/bin/git-clang-format git-clang-format /usr/bin/git-clang-format-11 100
17+
18+ - name : Run clang-format on changed files
1319 run : |
1420 set -x
1521 git fetch origin ${{ github.event.pull_request.base.ref }}
16- git fetch origin pull/${{ github.event.pull_request.number }}/head:${{ github.event.pull_request.head.ref }}
17- BASE_COMMIT=$(git rev-parse ${{ github.event.pull_request.base.sha }})
18- COMMIT_FILES=$(git diff --name-only ${BASE_COMMIT} | grep -i -v LinkDef)
19- RESULT_OUTPUT=$(git-clang-format-8 --commit ${BASE_COMMIT} --diff --binary $(which clang-format-8) ${COMMIT_FILES})
20- if [ "$RESULT_OUTPUT" == "no modified files to format" ] || [ "$RESULT_OUTPUT" == "clang-format did not modify any files" ]; then
22+ base_commit=$(git rev-parse ${{ github.event.pull_request.base.sha }})
23+ result_output=$(git diff --diff-filter d --name-only "$base_commit" |
24+ xargs -d '\n' git-clang-format --commit "$base_commit" --diff --style file)
25+ if [ "$result_output" = 'no modified files to format' ] ||
26+ [ "$result_output" = 'clang-format did not modify any files' ]
27+ then
2128 exit 0
2229 else
23- git-clang-format-8 --commit $BASE_COMMIT --diff --binary $(which clang-format-8)
24- echo "$RESULT_OUTPUT "
30+ git-clang-format --commit "$base_commit" --diff --style file
31+ echo "$result_output "
2532 exit 1
2633 fi
You can’t perform that action at this time.
0 commit comments