diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae3c8bdd..9ebcb290 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,11 @@ jobs: run: | sudo apt-get install -q -y clang-format scripts/check-format.sh + - name: static checks + run: | + sudo apt-get install -q -y bear clang-tidy-17 + scripts/check-tidy.sh + test: runs-on: ubuntu-22.04 strategy: diff --git a/.gitignore b/.gitignore index 2677be12..f87af72a 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,6 @@ venv.bak/ # VS Code configs .vscode + +# Compilation database +compile_commands.json diff --git a/scripts/check-tidy.sh b/scripts/check-tidy.sh new file mode 100755 index 00000000..8c88cbf9 --- /dev/null +++ b/scripts/check-tidy.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env sh + +# +# Runs clang-tidy-diff.py on the diff between main and HEAD. +# + +set -eu + +command -v bear >/dev/null 2>&1 || ( + echo "error: bear is required to generate compile_commands.json; see https://github.com/rizsotto/Bear" + exit 1 +) + +# number of jobs to run +NPROCS=1 +# Find available processor numbers based on different OS. +OS="$(uname -s)" +case $OS in +'Linux') + NPROCS="$(grep -c ^processor /proc/cpuinfo)" + ;; +'Darwin') + NPROCS="$(sysctl -n hw.ncpu)" + ;; +esac + +# Run a clean build to generate compile_commands.json. +make clean +bear make -j"${NPROCS}" +git diff -U0 main..HEAD | clang-tidy-diff -p1 -j"${NPROCS}"