-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (54 loc) · 1.52 KB
/
check.yml
File metadata and controls
60 lines (54 loc) · 1.52 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
49
50
51
52
53
54
55
56
57
58
59
60
name: Code Format Check
on:
push:
branches: ["main"]
paths:
- ".github/workflows/**"
- "src/**"
- "tests/**"
- "Makefile"
- ".clang-format"
pull_request:
branches: ["main"]
paths:
- ".github/workflows/**"
- "src/**"
- "tests/**"
- "Makefile"
- ".clang-format"
workflow_dispatch:
jobs:
code-format-check:
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Show OS info
run: |
sw_vers
- name: Install clang-format
run: |
brew install clang-format
- name: Run clang-format check
run: |
echo "Checking code format with clang-format..."
clang-format --version
FILES=$(find src tests -name '*.cpp' -o -name '*.hpp')
FORMAT_DIFF=""
for file in $FILES; do
DIFF=$(clang-format --style File --fallback-style LLVM \
--output-replacements-xml "$file" | grep "<replacement " \
|| true)
if [ -n "$DIFF" ]; then
echo "Formatting issues found in $file"
FORMAT_DIFF=1
fi
done
if [ -n "$FORMAT_DIFF" ]; then
echo "Code format check failed!"
echo "Please run 'clang-format -i --style File --fallback-style " \
"LLVM <file>' locally to fix formatting."
exit 1
else
echo "Code format check passed."
fi