From 5fbe7d65bf807ec1192aa148d55c9dddc93ef759 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Tue, 30 Apr 2024 01:41:32 -0500 Subject: [PATCH] Add check if git diff succeeded. --- .github/workflows/clang-tidy.yml | 11 ++++++++--- run-clang-tidy.sh | 28 ++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 1a814caee0..b06d802ae8 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -10,9 +10,11 @@ jobs: analyze: runs-on: ubuntu-latest - name: Install clang-tidy + name: clang-tidy steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Install clang-tidy run: | sudo apt install clang-tidy @@ -20,10 +22,13 @@ jobs: - name: Build run: | mkdir build && cd build - cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBUILD_SHARED_LIBS=1 .. - sudo cmake --build . --config Release + CC=clang cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBUILD_SHARED_LIBS=1 .. + CC=clang sudo cmake --build . --config Release cd .. - name: Check for warnings + env: + base_sha: ${{ github.event.pull_request.base.sha }} + head_sha: ${{ github.event.pull_request.head.sha }} run: | ./run-clang-tidy.sh build diff --git a/run-clang-tidy.sh b/run-clang-tidy.sh index 4617884a00..c2760aff83 100755 --- a/run-clang-tidy.sh +++ b/run-clang-tidy.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/sh -x if [ $# -ne 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "$0 " @@ -7,7 +7,11 @@ fi BUILD_PATH="$1" -clang-tidy $(find ./arch ./*.c -type f -iregex ".*\.[c]") -p "$BUILD_PATH" -checks=clang-analyzer-*,-clang-analyzer-cplusplus* | tee ct-warnings.txt +clang-tidy $(find ./arch ./*.c -type f -iregex ".*\.[c]") -p "$BUILD_PATH" -checks=clang-analyzer-*,-clang-analyzer-cplusplus* > ct-warnings.txt +if [ $? -ne 0 ]; then + echo "clang-tidy failed" + exit 1 +fi tmp=$(mktemp) grep ": warning" ct-warnings.txt | grep -oE "^[/a-zA-Z0-9]*\.[ch]" | sort | uniq > $tmp @@ -15,7 +19,14 @@ top_level=$(git rev-parse --show-toplevel) echo "\n\n###### REPORT\n\n" -for modified in $(git diff --name-only origin/next); do +changed_files=$(git diff --name-only $base_sha..$head_sha) +if [ $? -ne 0 ]; then + echo "Failed to get changed files." + exit 1 +fi + +for modified in $changed_files; do + files_changed=1 full_path="$top_level/$modified" if grep -q "$full_path" $tmp; then echo "$full_path as warnings. Please fix them." @@ -23,8 +34,17 @@ for modified in $(git diff --name-only origin/next); do fi done +if [ -z $files_changed ]; then + echo "No files changed." + exit 0 +fi + if [ -z $needs_fixes ]; then - echo "All good" + echo "None of the changed files has clang-tidy warnings." exit 0 fi + +cat ct-warnings.txt +echo -e "\n\nSome changed files have clang-tidy warnings. Please fix them. Or, if completely unrelated, let us know." + exit 1