feat(ci): integrate clang-tidy for changed C/C++ files #4
Workflow file for this run
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: Clang-Tidy | |
| on: | |
| push: | |
| branches: ["main"] | |
| paths: | |
| - "**/*.c" | |
| - "**/*.cc" | |
| - "**/*.cpp" | |
| - "**/*.cxx" | |
| - "**/*.h" | |
| - "**/*.hpp" | |
| - "CMakeLists.txt" | |
| - "**/CMakeLists.txt" | |
| - "cmake/**" | |
| - ".clang-tidy" | |
| pull_request: | |
| branches: ["main"] | |
| paths: | |
| - "**/*.c" | |
| - "**/*.cc" | |
| - "**/*.cpp" | |
| - "**/*.cxx" | |
| - "**/*.h" | |
| - "**/*.hpp" | |
| - "CMakeLists.txt" | |
| - "**/CMakeLists.txt" | |
| - "cmake/**" | |
| - ".clang-tidy" | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| jobs: | |
| clang_tidy: | |
| name: Clang-Tidy Checks | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y clang-tidy cmake ninja-build | |
| - name: Configure CMake and export compile commands | |
| run: | | |
| cmake -S . -B build -G Ninja \ | |
| -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ | |
| -DENABLE_HASWELL=ON \ | |
| -DBUILD_TOOLS=OFF | |
| - name: Collect changed C/C++ files | |
| id: changed_files | |
| uses: tj-actions/changed-files@v46 | |
| with: | |
| files: | | |
| **/*.c | |
| **/*.cc | |
| **/*.cpp | |
| **/*.cxx | |
| **/*.h | |
| **/*.hpp | |
| !thirdparty/** | |
| !build/** | |
| separator: "\n" | |
| - name: Run clang-tidy | |
| if: steps.changed_files.outputs.any_changed == 'true' | |
| run: | | |
| mapfile -t changed_files <<'EOF' | |
| ${{ steps.changed_files.outputs.all_changed_files }} | |
| EOF | |
| for file in "${changed_files[@]}"; do | |
| if [ -f "$file" ]; then | |
| echo "Running clang-tidy on $file" | |
| clang-tidy -p build --warnings-as-errors='*' "$file" | |
| fi | |
| done | |
| - name: No changed C/C++ files | |
| if: steps.changed_files.outputs.any_changed != 'true' | |
| run: | | |
| echo "No changed C/C++ files matched clang-tidy patterns." |