name: Check clang-tidy

on:
  push:
    branches-ignore:
      - gh-readonly-queue/**
  pull_request:
  merge_group:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.ref != 'refs/heads/master' && !startsWith(github.ref, 'refs/tags/') }}

jobs:
  check-clang-tidy:
    runs-on: ubuntu-latest
    env:
      CARGO_HTTP_MULTIPLEXING: false
    steps:
    - name: Checkout repository
      uses: actions/checkout@v4
      with:
        submodules: recursive

    - name: Prepare Linux
      run: |
        sudo apt-get update -y
        sudo apt-get install \
          cmake \
          libavcodec-dev \
          libavformat-dev \
          libavutil-dev \
          libfreetype6-dev \
          libglew-dev \
          libmariadb-dev \
          libminiupnpc-dev \
          libnotify-dev \
          libsdl2-dev \
          libsqlite3-dev \
          libswresample-dev \
          libswscale-dev \
          libwebsockets-dev \
          libx264-dev \
          ninja-build \
          pkg-config \
          -y

    - name: Install Vulkan SDK
      uses: humbletim/install-vulkan-sdk@v1.2
      with:
        version: 1.3.296.0
        cache: true

    - name: Cache Rust dependencies
      uses: Swatinem/rust-cache@v2
      with:
          cache-bin: false # WORKAROUND(https://github.com/Swatinem/rust-cache/issues/341)
          workspaces: |
              src/mastersrv
              src/masterping
              ./

    - name: Install Clang 20
      run: |
        sudo apt-get update
        sudo apt-get install -y wget gnupg lsb-release
        wget https://apt.llvm.org/llvm.sh
        chmod +x llvm.sh
        sudo ./llvm.sh 20 all

    - name: Build with clang-tidy
      run: |
        mkdir clang-tidy
        cd clang-tidy
        cmake -G Ninja \
          -DCMAKE_CXX_COMPILER=clang++-20 \
          -DCMAKE_C_COMPILER=clang-20 \
          -DCMAKE_CXX_CLANG_TIDY="clang-tidy-20;-warnings-as-errors=*" \
          -DCMAKE_C_CLANG_TIDY="clang-tidy-20;-warnings-as-errors=*" \
          -DCMAKE_BUILD_TYPE=Debug \
          -DANTIBOT=ON \
          -DAUTOUPDATE=ON \
          -DDISCORD=ON \
          -DDOWNLOAD_GTEST=ON \
          -DMYSQL=ON \
          -DSTEAM=ON \
          -DUPNP=ON \
          -DVIDEORECORDER=ON \
          -DVULKAN=ON \
          -DWEBSOCKETS=ON \
          -Werror=dev ..
        cmake --build . --config Debug --target everything testrunner -- -k 0
