Issue #10: Test code style check DO NOT MERGE #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Code Style Check (PR Only) | |
| on: | |
| pull_request: # Runs only on PRs, not on main branch | |
| jobs: | |
| format-check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v3 | |
| - name: Install clang-format and clang-tidy | |
| run: sudo apt-get install -y clang-format clang-tidy | |
| - name: Find Modified C++ Files in PR | |
| id: changed-files | |
| run: | | |
| FILES=$(git diff --name-only origin/${{ github.base_ref }} -- '*.cpp' '*.h') | |
| if [[ -z "$FILES" ]]; then | |
| echo "✅ No modified C++ files in this PR." | |
| exit 0 | |
| fi | |
| echo "🔍 Checking the following modified files:" | |
| echo "$FILES" | |
| echo "FILES=$FILES" >> $GITHUB_ENV | |
| - name: Check formatting with clang-format | |
| run: | | |
| if echo "$FILES" | xargs clang-format --dry-run --Werror; then | |
| echo "✅ Code formatting is correct." | |
| else | |
| echo "❌ Code formatting issues found! Run 'clang-format -i <file>' before committing." | |
| exit 1 | |
| fi | |
| - name: Check code quality with clang-tidy | |
| run: | | |
| if [ -f "compile_commands.json" ]; then | |
| echo "$FILES" | xargs run-clang-tidy -p=compile_commands.json | |
| else | |
| echo "⚠️ Warning: compile_commands.json not found. clang-tidy checks skipped." | |
| fi |