1+ name : Code Quality
2+
3+ on :
4+ push :
5+ branches : [ main, master, develop ]
6+ pull_request :
7+ branches : [ main, master, develop ]
8+
9+ jobs :
10+ code-quality :
11+ name : Code Quality Checks
12+ runs-on : ubuntu-latest
13+ steps :
14+ - uses : actions/checkout@v3
15+ with :
16+ fetch-depth : 0 # Fetch all history for proper git diff
17+
18+ - name : Install dependencies
19+ run : |
20+ sudo apt-get update
21+ sudo apt-get install -y clang-format clang-tidy cmake g++ make
22+ bash scripts/install_dependency.sh
23+
24+ - name : Get changed C/C++ files
25+ id : changed-files
26+ uses : tj-actions/changed-files@v41
27+ with :
28+ files : |
29+ **/*.c
30+ **/*.h
31+ **/*.cpp
32+ **/*.cc
33+ **/*.hpp
34+
35+ - name : Create log directory
36+ run : mkdir -p logs
37+
38+ - name : Clang-format check
39+ if : steps.changed-files.outputs.any_changed == 'true'
40+ run : |
41+ echo "Running clang-format checks..."
42+ FORMAT_ERRORS=0
43+
44+ for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
45+ echo "Checking formatting for $file"
46+ if ! clang-format --dry-run --Werror "$file" >> logs/format.log 2>&1; then
47+ echo "::error file=$file::Formatting issues in $file"
48+ FORMAT_ERRORS=$((FORMAT_ERRORS + 1))
49+ fi
50+ done
51+
52+ if [ $FORMAT_ERRORS -gt 0 ]; then
53+ echo "Found formatting issues in $FORMAT_ERRORS files."
54+ echo "You can fix these issues with: clang-format -i <file>"
55+ cat logs/format.log
56+ exit 1
57+ else
58+ echo "Formatting check passed."
59+ fi
60+
61+ - name : Configure CMake
62+ if : steps.changed-files.outputs.any_changed == 'true'
63+ run : |
64+ cmake -B build -DCMAKE_BUILD_TYPE=Debug \
65+ -DCMAKE_C_FLAGS="-Wall -Wextra -Werror -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable -Wpedantic -Wformat=2 -Wformat-security -Wshadow -Wwrite-strings -Wstrict-prototypes -Wold-style-definition -Wredundant-decls -Wnested-externs -Wmissing-include-dirs" \
66+ -DCMAKE_CXX_FLAGS="-Wall -Wextra -Werror -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-pedantic -Wformat=2 -Wformat-security -Wshadow -Wwrite-strings -Wmissing-include-dirs" \
67+ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
68+
69+ - name : Clang-tidy check
70+ if : steps.changed-files.outputs.any_changed == 'true'
71+ run : |
72+ echo "Running clang-tidy checks..."
73+ FILES_WITH_ISSUES=0
74+
75+ for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
76+ echo "Checking $file with clang-tidy"
77+ LOG_FILE="logs/tidy_$(basename "$file").log"
78+
79+ # Run clang-tidy with selected checks (same as pre-commit hook)
80+ if ! clang-tidy -p=build \
81+ -checks='-*,bugprone-*,cert-*,clang-analyzer-*,cppcoreguidelines-*,performance-*,portability-*,readability-*,-readability-magic-numbers,-readability-braces-around-statements,-cppcoreguidelines-avoid-magic-numbers,-readability-identifier-length,-clang-diagnostic-unused-command-line-argument' \
82+ "$file" > "$LOG_FILE" 2>&1; then
83+ echo "::error file=$file::clang-tidy found issues in $file"
84+ cat "$LOG_FILE"
85+ FILES_WITH_ISSUES=$((FILES_WITH_ISSUES + 1))
86+ fi
87+ done
88+
89+ if [ $FILES_WITH_ISSUES -gt 0 ]; then
90+ echo "clang-tidy found issues in $FILES_WITH_ISSUES files."
91+ exit 1
92+ else
93+ echo "clang-tidy check passed successfully."
94+ fi
95+
96+ - name : Compilation check
97+ if : steps.changed-files.outputs.any_changed == 'true'
98+ run : |
99+ echo "Checking for compilation warnings..."
100+ if cmake --build build -j$(nproc) > logs/compile.log 2>&1; then
101+ echo "Compilation successful!"
102+ else
103+ echo "Compilation failed. Please fix the warnings."
104+ cat logs/compile.log
105+ exit 1
106+ fi
0 commit comments