Skip to content

Commit

Permalink
Add format check to CI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stefankiesz committed Nov 29, 2023
1 parent a6144e1 commit 60f6242
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ on:
- master

jobs:
clang-format-check:
runs-on: macos-11
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Install clang-format
run: |
brew install clang-format
clang-format --version
- name: Run clang format check
run: |
bash scripts/check-clang.sh
mac-os-build-clang:
runs-on: macos-12
env:
Expand Down
29 changes: 29 additions & 0 deletions scripts/check-clang.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

if [[ -z $CLANG_FORMAT ]] ; then
CLANG_FORMAT=clang-format
fi

if NOT type $CLANG_FORMAT 2> /dev/null ; then
echo "No appropriate clang-format found."
exit 1
fi

FAIL=0
SOURCE_FILES=`find src samples tst -type f \( -name '*.h' -o -name '*.c' \) -not -path "*/external/*"`
echo "Performing clang format compliance check...."
for i in $SOURCE_FILES
do
$CLANG_FORMAT -output-replacements-xml $i | grep -c "<replacement " > /dev/null
if [ $? -ne 1 ]
then
echo "$i failed clang-format check."
FAIL=1
fi
done

if [ $FAIL -ne 1 ]; then
echo "Clang check passed for the project"
fi

exit $FAIL

0 comments on commit 60f6242

Please sign in to comment.