Skip to content

Commit edbdcee

Browse files
committed
add formatting CI check
1 parent 94ba5f9 commit edbdcee

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

.github/workflows/formatting.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Clang-Format Check
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
paths:
8+
- '**/*.cpp'
9+
- '**/*.h'
10+
- '**/*.hpp'
11+
12+
jobs:
13+
clang-format-check:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Install Clang-Format
21+
run: sudo apt-get install -y clang-format
22+
23+
- name: Run Clang-Format Check
24+
run: |
25+
files=$(find . -name "*.cpp" -o -name "*.hpp" -o -name "*.h")
26+
check_ignore=$(git -c core.excludesFile="format-ignore.txt" check-ignore --stdin --no-index --non-matching --verbose <<< "$files")
27+
files=$(awk '/^::/ {print $2}' <<< "$check_ignore")
28+
29+
echo "Checking $(echo "$files" | wc -l) files"
30+
31+
if [ -n "$files" ]; then
32+
clang-format -style=file -i $files
33+
git diff --exit-code || (echo "Clang-Format check failed!" && exit 1)
34+
else
35+
echo "No files to check."
36+
fi

0 commit comments

Comments
 (0)