Skip to content

Commit

Permalink
Run clang tidy on diff with CI
Browse files Browse the repository at this point in the history
Added a script for CI execution. This script is not intended for local
user execution due to the following reasons:

1. `clang-tidy-diff` supports exit with a failure code when there are
   errors from version 17 or 18 onward. (The exact version is uncertain.
   For more details, please refer to
   llvm/llvm-project#65000.)
2. `bear` has different command line interfaces between version <= 2.4.x
    and onward. (For more details, please refer to
    https://github.com/rizsotto/Bear?tab=readme-ov-file#how-to-use.)

The script may not function properly if any of these issues arise. In
the CI environment, we ensure that the versions of these dependencies
are up-to-date. Specifically, the version of `clang-tidy-diff` is
specified as `18`, and the version of `Bear` on Ubuntu 22.04 is 3.0.x.
  • Loading branch information
Lai-YT committed Feb 23, 2024
1 parent 1d94f7c commit b4c64c2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,26 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
# Fetch all history for proper diffing.
fetch-depth: 0
- name: coding convention
run: |
sudo apt-get install -q -y clang-format
scripts/check-format.sh
- name: Install cxxopts
run: scripts/install-cxxopts.sh
- name: Install fmt
run: scripts/install-fmt.sh
- name: static checks
run: |
sudo add-apt-repository -y 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main'
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install -q -y bear clang-tidy-18
export CLANG_TIDY_DIFF=clang-tidy-diff-18.py
scripts/check-tidy.sh
test:
runs-on: ubuntu-22.04
strategy:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ venv.bak/

# VS Code configs
.vscode

# Compilation database
compile_commands.json
26 changes: 26 additions & 0 deletions scripts/check-tidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env sh

#
# Runs clang-tidy on the diff between main and HEAD.
# Note: This script is intended to be run in CI.
#

set -eu

if [ -z "${GITHUB_ACTIONS+x}" ]; then
echo "error: this script is intended to be run in CI"
exit 1
fi

CLANG_TIDY_DIFF=${CLANG_TIDY_DIFF:-clang-tidy-diff.py}

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
)

# Run a clean build to generate compile_commands.json.
make clean
bear -- make
git fetch origin main:refs/remotes/origin/main
git diff -U0 "origin/${GITHUB_BASE_REF}" | ${CLANG_TIDY_DIFF} -p1

0 comments on commit b4c64c2

Please sign in to comment.