-
Notifications
You must be signed in to change notification settings - Fork 3
48 lines (40 loc) · 1.29 KB
/
Copy pathformat-check.yml
File metadata and controls
48 lines (40 loc) · 1.29 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
name: Format Check
on:
pull_request:
branches: [main]
paths:
- "src/**"
jobs:
clang-format:
name: clang-format
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Install clang-format
run: sudo apt-get update && sudo apt-get install -y clang-format
- name: Check formatting
run: |
FAILED=0
FILES=$(find src/ -type f \( -name "*.cpp" -o -name "*.hpp" -o -name "*.h" \))
for file in $FILES; do
# Generate the diff between current and formatted versions
DIFF=$(clang-format "$file" | diff -u "$file" - || true)
if [ -n "$DIFF" ]; then
echo "::error file=$file::File is not formatted according to .clang-format"
echo "$DIFF"
echo ""
FAILED=1
fi
done
if [ "$FAILED" -eq 1 ]; then
echo ""
echo "Some files are not properly formatted."
echo ""
echo "Fix locally with:"
echo ' find src/ -type f \( -name "*.cpp" -o -name "*.hpp" -o -name "*.h" \) | xargs clang-format -i'
exit 1
fi
echo "All files are properly formatted."