clang-tidy: scope the header filter to the object's own headers #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Tap House Style | |
| # Enforces the shared Tap House Rules: (1) a drift check against the canonical | |
| # TapHouse configs, (2) a clang-format layout check, and (3) clang-tidy naming + | |
| # mandatory-braces over the external's own translation units. | |
| # | |
| # tap.python~ only configures with the embedded Python runtime present, and that | |
| # runtime installs on macOS/Windows only — so the clang-tidy gate (which needs a | |
| # compile database) runs on macOS. The drift and clang-format checks are | |
| # platform-independent and stay on Linux. | |
| on: [push, pull_request] | |
| jobs: | |
| drift: | |
| uses: tap/taphouse/.github/workflows/drift-check.yml@v4 | |
| with: | |
| ref: v4 | |
| clang-format: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install clang-format | |
| run: sudo apt-get update -q && sudo apt-get install -y -q clang-format-18 | |
| - name: clang-format check (own sources) | |
| run: clang-format-18 --dry-run --Werror $(git ls-files 'source/projects/*.cpp' 'source/projects/*.h') | |
| clang-tidy: | |
| runs-on: macos-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: Install the embedded Python runtime (needed to configure) | |
| run: ./scripts/install-runtime.sh | |
| - name: Install clang-tidy (LLVM 18) | |
| run: brew install llvm@18 | |
| - name: Configure (compile database) | |
| # Single-arch: the package otherwise defaults to a universal build | |
| # (arm64;x86_64), whose two -arch flags make one compile command emit | |
| # two compiler jobs — which clang-tidy cannot process ("expected exactly | |
| # one compiler job"). One arch is enough to lint the sources. | |
| run: cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_OSX_ARCHITECTURES=arm64 | |
| - name: clang-tidy (Max externals' own TUs; min-api and deps excluded) | |
| run: | | |
| tidy="$(brew --prefix llvm@18)/bin/clang-tidy" | |
| files=$(python3 -c "import json; print('\n'.join(e['file'] for e in json.load(open('build/compile_commands.json')) if '/source/projects/' in e['file']))") | |
| fail=0 | |
| # Scope diagnostics to this object's OWN headers. A broad | |
| # '.*/source/projects/.*' also matches the bundled CPython headers, | |
| # which the build includes via a relative path that passes back | |
| # through source/projects (…/tap.python_tilde/../../../support/…), | |
| # flooding the run with CPython naming violations. | |
| for f in $files; do | |
| out=$("$tidy" -p build -header-filter='.*/tap\.python_tilde/tap\.python_tilde.*' --warnings-as-errors='readability-*' "$f" 2>/dev/null || true) | |
| if echo "$out" | grep -qE "warning:|error:"; then echo "$out"; fail=1; fi | |
| done | |
| [ "$fail" -eq 0 ] && echo "clang-tidy clean." || { echo "::error::clang-tidy found violations"; exit 1; } |