|
| 1 | +name: clang-tidy |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - '**.h' |
| 7 | + - '**.cpp' |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + review: |
| 15 | + runs-on: ubuntu-22.04 |
| 16 | + steps: |
| 17 | + - name: Checkout PR branch |
| 18 | + uses: actions/checkout@v6 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + |
| 22 | + - name: Setup Python |
| 23 | + uses: actions/setup-python@v6 |
| 24 | + with: |
| 25 | + python-version: "3.11" |
| 26 | + |
| 27 | + - name: Install LLVM and Clang |
| 28 | + uses: KyleMayes/install-llvm-action@v2.0.7 |
| 29 | + with: |
| 30 | + version: "20.1.4" |
| 31 | + |
| 32 | + - name: Setup build dependencies |
| 33 | + run: | |
| 34 | + sudo apt-get update |
| 35 | + sudo apt-get install -y cmake libxml2 libxml2-dev libtinfo-dev zlib1g-dev libzstd-dev |
| 36 | + pip install lit |
| 37 | +
|
| 38 | + - name: Generate Compile Commands |
| 39 | + run: | |
| 40 | + cmake . -B build -DCMAKE_BUILD_TYPE="Release" \ |
| 41 | + -DCMAKE_C_COMPILER="$GITHUB_WORKSPACE/llvm/bin/clang" \ |
| 42 | + -DCMAKE_CXX_COMPILER="$GITHUB_WORKSPACE/llvm/bin/clang++" \ |
| 43 | + -DLLVM_DIR="$GITHUB_WORKSPACE/llvm" \ |
| 44 | + -DBUILD_SHARED_LIBS=ON \ |
| 45 | + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON |
| 46 | + cd build |
| 47 | + cmake --build . --target googletest --parallel $(nproc) |
| 48 | +
|
| 49 | + - name: Run Clang Tidy |
| 50 | + run: | |
| 51 | + # Get list of changed C++ files compared to base branch |
| 52 | + PR_BASE=${{ github.event.pull_request.base.sha }} |
| 53 | + CHANGED_FILES=$(git diff --name-only $PR_BASE HEAD | grep -E '\.(cpp|h)$' || true) |
| 54 | + |
| 55 | + if [ -z "$CHANGED_FILES" ]; then |
| 56 | + echo "No C++ files changed." |
| 57 | + exit 0 |
| 58 | + fi |
| 59 | + |
| 60 | + echo "Running clang-tidy on the following changed files:" |
| 61 | + echo "$CHANGED_FILES" |
| 62 | + |
| 63 | + # Run run-clang-tidy from LLVM if present, or fallback to clang-tidy directly |
| 64 | + export PATH="$GITHUB_WORKSPACE/llvm/bin:$PATH" |
| 65 | + if command -v run-clang-tidy >/dev/null 2>&1; then |
| 66 | + echo "$CHANGED_FILES" | xargs run-clang-tidy -p build -quiet |
| 67 | + else |
| 68 | + echo "$CHANGED_FILES" | xargs clang-tidy -p build --quiet --warnings-as-errors='*' |
| 69 | + fi |
0 commit comments