Repository navigation
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: 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 | ||
| fetch-depth: 0 | ||
| - 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: Determine changed C/C++ source files | ||
| id: changed-cpp | ||
| shell: bash | ||
| run: | | ||
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | ||
| BASE_SHA="${{ github.event.pull_request.base.sha }}" | ||
| elif [[ "${{ github.event_name }}" == "merge_group" ]]; then | ||
| BASE_SHA="${{ github.event.merge_group.base_sha }}" | ||
| else | ||
| BASE_SHA="${{ github.event.before }}" | ||
| fi | ||
| if [[ -z "${BASE_SHA}" || "${BASE_SHA}" == "0000000000000000000000000000000000000000" ]]; then | ||
| BASE_SHA="$(git rev-parse HEAD^)" | ||
| fi | ||
| git diff --name-only "${BASE_SHA}" "${GITHUB_SHA}" | grep -E '^src/.*\.(c|cpp)$' > changed_cpp_files.txt || true | ||
| if [[ -s changed_cpp_files.txt ]]; then | ||
| echo "has_files=true" >> "${GITHUB_OUTPUT}" | ||
| else | ||
| echo "has_files=false" >> "${GITHUB_OUTPUT}" | ||
| fi | ||
| - 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: Run clang-tidy on changed files | ||
| run: | | ||
| if [[ "${{ steps.changed-cpp.outputs.has_files }}" != "true" ]]; then | ||
| echo "No changed C/C++ source files to check." | ||
| exit 0 | ||
| fi | ||
| cmake -S . -B clang-tidy -G Ninja \ | ||
| -DCMAKE_CXX_COMPILER=clang++-20 \ | ||
| -DCMAKE_C_COMPILER=clang-20 \ | ||
| -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ | ||
| -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 | ||
| mkdir -p clang-tidy/src/generated | ||
| python3 datasrc/compile.py client_content_header > clang-tidy/src/generated/client_data.h | ||
| python3 datasrc/compile.py content_types_header > clang-tidy/src/generated/data_types.h | ||
| python3 datasrc/compile.py network_header > clang-tidy/src/generated/protocol.h | ||
| python3 -m datasrc.seven.compile network_header > clang-tidy/src/generated/protocol7.h | ||
| python3 -m datasrc.seven.compile client_content_header > clang-tidy/src/generated/client_data7.h | ||
| python3 datasrc/crosscompile.py map_header > clang-tidy/src/generated/protocolglue.h | ||
| cmake --build clang-tidy --target generate_protocol | ||
| xargs -a changed_cpp_files.txt -d '\n' clang-tidy-20 -p clang-tidy -warnings-as-errors='*' -header-filter='^ | ||
| -checks='-bugprone-exception-escape,-misc-redundant-expression,-misc-use-internal-linkage,-modernize-loop-convert,-readability-avoid-unconditional-preprocessor-if,-readability-container-contains,-readability-make-member-function-const,-readability-redundant-casting,-readability-static-definition-in-anonymous-namespace,-readability-use-anyofallof' | ||