Skip to content

Commit

Permalink
Add check if git diff succeeded.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Apr 30, 2024
1 parent 3dd102d commit 5fbe7d6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@ 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
- 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
28 changes: 24 additions & 4 deletions run-clang-tidy.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/sh -x

if [ $# -ne 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "$0 <build-path>"
Expand All @@ -7,24 +7,44 @@ 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
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."
needs_fixes=1
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

0 comments on commit 5fbe7d6

Please sign in to comment.