Skip to content

Commit 60f6242

Browse files
committed
Add format check to CI tests
1 parent a6144e1 commit 60f6242

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ on:
1010
- master
1111

1212
jobs:
13+
clang-format-check:
14+
runs-on: macos-11
15+
steps:
16+
- name: Clone repository
17+
uses: actions/checkout@v3
18+
- name: Install clang-format
19+
run: |
20+
brew install clang-format
21+
clang-format --version
22+
- name: Run clang format check
23+
run: |
24+
bash scripts/check-clang.sh
25+
1326
mac-os-build-clang:
1427
runs-on: macos-12
1528
env:

scripts/check-clang.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ -z $CLANG_FORMAT ]] ; then
4+
CLANG_FORMAT=clang-format
5+
fi
6+
7+
if NOT type $CLANG_FORMAT 2> /dev/null ; then
8+
echo "No appropriate clang-format found."
9+
exit 1
10+
fi
11+
12+
FAIL=0
13+
SOURCE_FILES=`find src samples tst -type f \( -name '*.h' -o -name '*.c' \) -not -path "*/external/*"`
14+
echo "Performing clang format compliance check...."
15+
for i in $SOURCE_FILES
16+
do
17+
$CLANG_FORMAT -output-replacements-xml $i | grep -c "<replacement " > /dev/null
18+
if [ $? -ne 1 ]
19+
then
20+
echo "$i failed clang-format check."
21+
FAIL=1
22+
fi
23+
done
24+
25+
if [ $FAIL -ne 1 ]; then
26+
echo "Clang check passed for the project"
27+
fi
28+
29+
exit $FAIL

0 commit comments

Comments
 (0)