name: build - clang-tidy
on:
  workflow_call:

jobs:
  clang_tidy:
    runs-on: ubuntu-latest
    env:
      CC:  /usr/bin/clang
      CXX: /usr/bin/clang++
    steps:
    - name: Checkout
      uses: actions/checkout@v3
      with:
        fetch-depth: 1
    - name: Installing dependencies
      run: sh ./.github/scripts/install_deps.sh
    - name: CMake
      run: |
        # Prepare build dir
        echo "Will use $(nproc) cores."
        mkdir build
        pushd build
        cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
        popd
    - name: Restore cache
      uses: actions/cache/restore@v3
      with:
        path: build/clang-tidy-cache
        key: clang-tidy-cache-${{ github.sha }}
        restore-keys: |
          clang-tidy-cache-
    - name: Check
      # To run a single check, call:
      # python3 ../utils/run-clang-tidy.py -checks=-*,my-check-prefix* | tee ../clang-tidy.log
      run: |
        # run-clang-tidy.py
        pushd build
        python3 ../utils/run-clang-tidy.py -cache | tee ../clang-tidy.log
        popd
    - name: Save cache
      # We want to save the cache even if the report fails because of failed files
      uses: actions/cache/save@v3
      with:
        path: build/clang-tidy-cache
        key: clang-tidy-cache-${{ github.sha }}
    - name: Report
      run: utils/check_clang_tidy_results.py clang-tidy.log
