diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 1e64dabd32a79..ffdf47c1d8f21 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -15,6 +15,9 @@ on: - '**.hpp' - '**/CMakeLists.txt' - '**/Makefile' + - 'build-scripts/clang-tidy.sh' + - 'build-scripts/clang-tidy-wrapper.sh' + - 'build-scripts/get_affected_files.py' - '.github/workflows/clang-tidy.yml' # We only care about the latest revision of a PR, so cancel all previous instances. @@ -34,7 +37,7 @@ jobs: uses: fkirc/skip-duplicate-actions@master with: cancel_others: 'true' - paths: '[ "**.cpp", "**.h", "**.c", "**/CMakeLists.txt", "**/Makefile", "**.hpp", "**.cmake", ".github/workflows/clang-tidy.yml" ]' + paths: '[ "**.cpp", "**.h", "**.c", "**/CMakeLists.txt", "**/Makefile", "**.hpp", "**.cmake", "build-scripts/clang-tidy.sh", "build-scripts/clang-tidy-wrapper.sh", "build-scripts/get_affected_files.py", ".github/workflows/clang-tidy.yml" ]' build: needs: skip-duplicates if: ${{ needs.skip-duplicates.outputs.should_skip != 'true' }} @@ -91,5 +94,10 @@ jobs: run: bash ./build-scripts/clang-tidy.sh - name: show most time consuming checks if: always() - run: | - jq -n 'reduce(inputs.profile | to_entries[]) as {$key,$value} ({}; .[$key] += $value) | with_entries(select(.key|contains(".wall"))) | to_entries | sort_by(.value) | reverse | .[0:10] | from_entries' clang-tidy-trace/*.json + run: | # the folder may not exist if there is no file to analyze + if [ -d clang-tidy-trace ] + then + jq -n 'reduce(inputs.profile | to_entries[]) as {$key,$value} ({}; .[$key] += $value) | with_entries(select(.key|contains(".wall"))) | to_entries | sort_by(.value) | reverse | .[0:10] | from_entries' clang-tidy-trace/*.json + else + echo "clang-tidy-trace folder not found." + fi diff --git a/build-scripts/clang-tidy.sh b/build-scripts/clang-tidy.sh index 2f97bbadfb524..151b277fc79c4 100755 --- a/build-scripts/clang-tidy.sh +++ b/build-scripts/clang-tidy.sh @@ -124,13 +124,16 @@ fi printf "Subset to analyze: '%s'\n" "$CATA_CLANG_TIDY_SUBSET" # We might need to analyze only a subset of the files if they have been split -# into multiple jobs for efficiency +# into multiple jobs for efficiency. The paths from `compile_commands.json` can +# be absolute but the paths from `get_affected_files.py` are relative, so both +# formats are matched. Exit code 1 from grep (meaning no match) is ignored in +# case one subset contains no file to analyze. case "$CATA_CLANG_TIDY_SUBSET" in ( src ) - tidyable_cpp_files=$(printf '%s\n' "$tidyable_cpp_files" | grep '/src/') + tidyable_cpp_files=$(printf '%s\n' "$tidyable_cpp_files" | grep -E '(^|/)src/' || [[ $? == 1 ]]) ;; ( other ) - tidyable_cpp_files=$(printf '%s\n' "$tidyable_cpp_files" | grep -v '/src/') + tidyable_cpp_files=$(printf '%s\n' "$tidyable_cpp_files" | grep -Ev '(^|/)src/' || [[ $? == 1 ]]) ;; esac