name: clang-tidy on: # Paths filtering is intentionally not used at the trigger level. # - For pushes, dorny/paths-filter in the setup job determines which opted-in # libraries changed (via each library's path_filters) and builds the matrix. # - For PRs, the workflow must always run so the required check is registered # for every PR; the clang-tidy job is skipped when no opted-in component is affected. push: branches: - develop - release/therock-* pull_request: workflow_dispatch: concurrency: # For PRs, group by PR number so a new commit cancels any in-progress run # for the same PR. For postsubmits, group by commit SHA (unique per commit) # so runs never cancel each other. The workflow name is prepended to avoid # conflicts between different workflows. group: ${{ github.workflow }}-${{ github.event.number || github.sha }} cancel-in-progress: true jobs: setup: name: "Setup" runs-on: ubuntu-24.04 outputs: matrix: ${{ steps.build-matrix.outputs.matrix }} steps: - name: Checkout rocm-libraries uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: sparse-checkout: .github sparse-checkout-cone-mode: true fetch-depth: 2 - name: Define opted-in libraries id: lib-config run: | # To opt in a new library: add one jq -cn block to LIBS below, then: # - Add an "Install deps ()" step in the clang-tidy job if needed. # - Add a "Run clang-tidy ()" step in the clang-tidy job. # Required fields: name, path_filters (array), checkout_paths (array) # Optional fields: (all build config is handled in the per-library run step) # path_filters controls which file changes trigger clang-tidy for this library; # use specific globs rather than /** to avoid false triggers. # NOTE: dorny/paths-filter uses picomatch where '?' means "any single char", # NOT GitHub Actions' "zero or one of preceding char". Use explicit extensions. # checkout_paths lists all repo paths needed for sparse checkout. LIBS=() # stinkytofu LIBS+=($(jq -cn '{ name: "stinkytofu", path_filters: [ "shared/stinkytofu/**/*.{c,h,cpp,hpp,cxx,hxx,def}", "shared/stinkytofu/.clang-tidy", "cmake/modules/ClangTidy.cmake", "cmake/modules/CheckToolVersion.cmake" ], checkout_paths: ["shared/stinkytofu", "cmake/modules"] }')) # MIOpen LIBS+=($(jq -cn '{ name: "miopen", path_filters: [ "projects/miopen/**/*.{c,h,cpp,hpp,cxx,hxx}", "projects/miopen/cmake/ClangTidy.cmake", "projects/miopen/.clang-tidy" ], checkout_paths: ["projects/miopen", "shared/ctest"] }')) # Common filters applied to every library — changes here re-run all opted-in libraries. COMMON_FILTERS='[".github/workflows/clang-tidy.yml"]' printf '%s\n' "${LIBS[@]}" \ | jq -rs --argjson common "$COMMON_FILTERS" \ '.[] | "\(.name):\n" + ((.path_filters + $common) | map(" - \"\(.)\"") | join("\n")) + "\n"' \ > path-filters.yml LIBS_JSON=$(printf '%s\n' "${LIBS[@]}" \ | jq -sc '[.[] | . + {checkout_paths_str: (.checkout_paths | join("\n"))}]') echo "libs=${LIBS_JSON}" >> "$GITHUB_OUTPUT" - name: Detect changed opted-in projects uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1 id: changes with: filters: path-filters.yml - name: Build job matrix id: build-matrix run: | CHANGED='${{ steps.changes.outputs.changes }}' LIBS='${{ steps.lib-config.outputs.libs }}' IS_DISPATCH=${{ github.event_name == 'workflow_dispatch' }} MATRIX=$( echo "$LIBS" | jq -c \ --argjson changed "$CHANGED" \ --argjson dispatch "$IS_DISPATCH" \ '[.[] | select($dispatch or (.name as $n | $changed | index($n) != null))] | {"include": .}' ) echo "matrix=${MATRIX}" >> "$GITHUB_OUTPUT" clang-tidy: name: "clang-tidy (${{ matrix.name }})" needs: setup if: needs.setup.outputs.matrix != '{"include":[]}' strategy: matrix: ${{ fromJSON(needs.setup.outputs.matrix) }} fail-fast: false runs-on: azure-linux-scale-rocm steps: - name: Checkout rocm-libraries uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: sparse-checkout: ${{ matrix.checkout_paths_str }} sparse-checkout-cone-mode: true - name: Checkout TheRock uses: actions/checkout@v6.0.2 with: repository: ROCm/TheRock path: TheRock - name: Install base dependencies run: | sudo apt-get update sudo apt-get install -y \ ninja-build \ python3-venv \ python3-dev \ lsb-release wget \ software-properties-common \ gnupg python3 -m venv .venv . .venv/bin/activate pip install boto3 cmake pip install -r TheRock/requirements.txt - name: Install ROCm run: | sudo .venv/bin/python3 TheRock/build_tools/install_rocm_from_artifacts.py \ --latest-release \ --amdgpu-family gfx94X-dcgpu \ --output-dir /opt/rocm \ --base-only # Per-library optional dependency steps — only the matching step runs. # Add a new step here when opting in a library that has custom deps. - name: Install deps (stinkytofu) if: matrix.name == 'stinkytofu' run: | wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh sudo ./llvm.sh 20 sudo apt-get update sudo apt-get install -y \ clang-tidy-20 \ clang-tools-20 \ libgtest-dev \ python3-dev . .venv/bin/activate pip install -r shared/stinkytofu/requirements.txt - name: Install deps (miopen) if: matrix.name == 'miopen' run: | . .venv/bin/activate # cmake 4.x removed compat with cmake_minimum_required(VERSION <3.5); # several MIOpen deps (e.g. bzip2@1.0.8) still declare old minimums. pip install 'cmake<4' \ https://github.com/pfultz2/cget/archive/b5dd36cafa2804e6146c5021eb2469c4b2d3ad42.tar.gz \ https://github.com/RadeonOpenCompute/rbuild/archive/c33b1a7e74ae7f72379364b523f73d30fd4d765c.tar.gz wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh sudo ./llvm.sh 21 sudo apt-get install -y clang-tidy-21 cp projects/miopen/requirements.txt /tmp/requirements.txt cp projects/miopen/rbuild.ini /tmp/rbuild.ini cp projects/miopen/dev-requirements.txt /tmp/dev-requirements.txt # Strip deps not available/needed on CI runner sed -i '/composablekernel/d; /half/d; /rocMLIR/d' /tmp/requirements.txt cd /tmp && CMAKE_GENERATOR=Ninja rbuild prepare -s develop -d /tmp/miopen-deps - name: Run clang-tidy (stinkytofu) if: matrix.name == 'stinkytofu' run: | . .venv/bin/activate export ROCM_PATH=/opt/rocm cd shared/stinkytofu invoke build invoke tidy - name: Run clang-tidy (miopen) if: matrix.name == 'miopen' run: | . .venv/bin/activate export PATH=/opt/rocm/bin:/opt/rocm/llvm/bin:$PATH export CXX=/opt/rocm/llvm/bin/clang++ # TODO: remove -DMIOPEN_USE_MLIR=OFF once rocMLIR is removed from MIOpen cmake -S projects/miopen -B build-miopen -G Ninja \ -DMIOPEN_BACKEND=HIP \ -DBUILD_DEV=ON \ -DMIOPEN_USE_MLIR=OFF \ -DCLANG_TIDY_EXE=/usr/bin/clang-tidy-21 \ -DCMAKE_PREFIX_PATH="/opt/rocm;/tmp/miopen-deps" \ -DROCM_PATH=/opt/rocm ninja -C build-miopen analyze clang_tidy_summary: name: "clang-tidy summary" if: always() needs: - setup - clang-tidy runs-on: ubuntu-24.04 steps: - name: Output failed jobs run: | echo '${{ toJson(needs) }}' FAILED_JOBS="$(echo '${{ toJson(needs) }}' \ | jq --raw-output \ 'map_values(select(.result!="success" and .result!="skipped")) | keys | join(",")' \ )" if [[ "${FAILED_JOBS}" != "" ]]; then echo "The following jobs failed: ${FAILED_JOBS}" exit 1 fi