-
Notifications
You must be signed in to change notification settings - Fork 12
33 lines (29 loc) · 1.16 KB
/
format.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
name: Clang format
on: [pull_request]
jobs:
clang-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install prerequisites
run: |
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-11 100
sudo update-alternatives --install /usr/bin/git-clang-format git-clang-format /usr/bin/git-clang-format-11 100
- name: Run clang-format on changed files
run: |
set -x
git fetch origin ${{ github.event.pull_request.base.ref }}
base_commit=$(git rev-parse ${{ github.event.pull_request.base.sha }})
result_output=$(git diff --diff-filter d --name-only "$base_commit" |
xargs -d '\n' git-clang-format --commit "$base_commit" --diff --style file)
if [ "$result_output" = 'no modified files to format' ] ||
[ "$result_output" = 'clang-format did not modify any files' ]
then
exit 0
else
git-clang-format --commit "$base_commit" --diff --style file
echo "$result_output"
exit 1
fi