File tree Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Check clang format
2+
3+ on :
4+ push :
5+ branches :
6+ - ' *'
7+ pull_request :
8+ branches :
9+ - ' *'
10+
11+ jobs :
12+ format-check :
13+ runs-on : ubuntu-latest
14+
15+ steps :
16+ - name : Checkout code
17+ uses : actions/checkout@v4
18+
19+ - name : Cache Clang-Format
20+ uses : actions/cache@v4
21+ with :
22+ path : /usr/bin/clang-format
23+ key : ${{ runner.os }}-clang-format-cache
24+ restore-keys : |
25+ ${{ runner.os }}-clang-format-cache
26+
27+ - name : Set up Clang-Format
28+ run : |
29+ if ! command -v clang-format &> /dev/null; then
30+ echo "Clang-Format not found, installing..."
31+ sudo apt-get update
32+ sudo apt-get install -y clang-format
33+ else
34+ echo "Clang-Format is already installed."
35+ fi
36+
37+ - name : Check formatting
38+ run : |
39+ # Find all C/C++ files and check formatting
40+ files=$(find . -name '*.h' -o -name '*.c' -o -name '*.hpp' -o -name '*.cpp')
41+ if [ -z "$files" ]; then
42+ echo "No C/C++ files found."
43+ exit 0
44+ fi
45+
46+ # Initialize a flag to track formatting issues
47+ formatting_issues=0
48+
49+ # Check formatting for each file
50+ for file in $files; do
51+ if clang-format -style=file -output-replacements-xml "$file" | grep -q '<replacement '; then
52+ echo "Formatting issues found in $file"
53+ formatting_issues=1
54+ fi
55+ done
56+
57+ # Exit with the appropriate status code
58+ if [ $formatting_issues -eq 1 ]; then
59+ echo "Please format the files using clang-format and commit the changes."
60+ exit 1
61+ else
62+ echo "All files are properly formatted."
63+ exit 0
64+ fi
You can’t perform that action at this time.
0 commit comments