Skip to content

Commit 06844e4

Browse files
committed
Add github actions clang-format job
1 parent 7d30335 commit 06844e4

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

.github/workflows/pull-request-checks.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,42 @@ on:
44
branches: [ develop ]
55

66
jobs:
7+
check-clang-format:
8+
runs-on: ubuntu-20.04
9+
steps:
10+
- uses: actions/checkout@v2
11+
with:
12+
submodules: true
13+
- name: Fetch dependencies
14+
env:
15+
# This is needed in addition to -yq to prevent apt-get from asking for
16+
# user input
17+
DEBIAN_FRONTEND: noninteractive
18+
run: |
19+
sudo apt-get install -yq clang-format-7
20+
- name: Check updated lines of code match clang-format-7 style
21+
env:
22+
BASE_BRANCH: ${{ github.base_ref }}
23+
PR_BRANCH: ${{ github.ref }}
24+
run: |
25+
echo "Pull request's base branch is: ${BASE_BRANCH}"
26+
echo "Pull request's branch is: ${PR_BRANCH}"
27+
clang-format-7 --version
28+
while read file ; do EXCLUDES+="':(top,exclude)$file' " ; done < .clang-format-ignore
29+
MERGE_BASE=$(git merge-base ${BASE_BRANCH} ${PR_BRANCH})
30+
echo "Checking for formatting errors introduced since $MERGE_BASE"
31+
# use eval so that quotes (as inserted into $EXCLUDES above) are not interpreted as parts of file names
32+
eval git-clang-format-7 --binary clang-format-7 $MERGE_BASE -- $EXCLUDES
33+
git diff > formatted.diff
34+
if [[ -s formatted.diff ]] ; then
35+
echo 'Formatting error! The following diff shows the required changes'
36+
echo 'Use the raw log to get a version of the diff that preserves spacing'
37+
cat formatted.diff
38+
exit 1
39+
fi
40+
echo 'No formatting errors found'
41+
exit 0
42+
743
check-macos-10_15-cmake-clang:
844
runs-on: macos-10.15
945
steps:

0 commit comments

Comments
 (0)