Skip to content

Commit 5683e6a

Browse files
authored
[CI][Lint] Retire format.sh and add clang-tidy to GHA workflow (#1044)
* [Lint] Retire `format.sh` and add `clang-tidy` to GHA workflow * chore: update clang-tidy settings * chore: upgrade clang-format and clang-tidy version * lint: resolve clang-tidy errors * [Maint] restore format.sh * [CI] pre-commit autoupdate * [Minor] fix `command -v` usage
1 parent 151d9e6 commit 5683e6a

24 files changed

+219
-339
lines changed

.clang-tidy

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
Checks: >
1+
---
2+
InheritParentConfig: true
3+
ExtraArgs: ['-v']
4+
FormatStyle: file
5+
UseColor: true
6+
WarningsAsErrors: '*'
7+
ExcludeHeaderFilterRegex: '^(3rdparty|tvm)/.*$'
8+
9+
# NOTE: there must be no spaces before the '-', so put the comma last.
10+
Checks: >-
211
# 1. Retained categories: easier to find bugs/performance issues
312
clang-analyzer-*,
413
cppcoreguidelines-pro-type-static-cast-downcast,
@@ -47,7 +56,3 @@ Checks: >
4756
-clang-analyzer-deadcode.DeadStores,
4857
-clang-analyzer-optin.cplusplus.VirtualCall,
4958
-clang-diagnostic-tautological-constant-compare,
50-
51-
WarningsAsErrors: '*'
52-
53-
HeaderFilterRegex: '^(?!.*(3rdparty|build)).*$'

.github/workflows/ci.yml

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -287,21 +287,39 @@ jobs:
287287
echo "Clearing uv cache at ${UV_CACHE_DIR} due to failure."
288288
uv cache clean
289289
290-
- name: Run format check
291-
id: format-check
290+
- name: Run clang-tidy
291+
id: clang-tidy
292+
if: runner.os == 'Linux'
292293
run: |
293-
mkdir -p build
294+
echo "\$ $(command -v clang-tidy) --version" && clang-tidy --version
295+
296+
if [[ -x "$(command -v run-clang-tidy)" ]]; then
297+
echo "Using run-clang-tidy from $(command -v run-clang-tidy)"
298+
CLANG_TIDY=(run-clang-tidy)
299+
else
300+
echo "Downloading run-clang-tidy script"
301+
wget -O run-clang-tidy.py https://raw.githubusercontent.com/llvm/llvm-project/refs/heads/release/21.x/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
302+
CLANG_TIDY=(uv run --no-project --script -- run-clang-tidy.py)
303+
fi
304+
if [[ -x "$(command -v clang-apply-replacements)" ]]; then
305+
echo "Using clang-apply-replacements from $(command -v clang-apply-replacements)"
306+
CLANG_TIDY+=(-fix -clang-apply-replacements-binary="$(command -v clang-apply-replacements)")
307+
else
308+
echo "::warning::clang-apply-replacements not found in PATH, automatic fixing disabled."
309+
fi
310+
294311
# Run cmake to create the build directory with compile_commands.json
295-
(
296-
cd build
297-
cmake .. ${CLANG_TIDY_CMAKE_OPTIONS} # no quotes here
298-
)
312+
cmake -S . -B cmake-build --fresh ${CLANG_TIDY_CMAKE_OPTIONS} # no quotes here
313+
314+
CXX_FILES=$(find src -type f -iname "*.[ch]pp" -o -iname "*.cc" -o -iname "*.c" -o -iname "*.h")
299315
rc=0
300-
bash format.sh || rc="$?"
301-
rm -rf build
302-
if [[ "${rc}" -ne 0 ]]; then
303-
echo "::error::Format check failed. Please run 'bash format.sh' locally to fix the issues."
304-
exit 1
316+
"${CLANG_TIDY[@]}" -clang-tidy-binary="$(command -v clang-tidy)" \
317+
-p="cmake-build" ${CXX_FILES} || rc="$?"
318+
rm -rf cmake-build run-clang-tidy.py
319+
if (( rc != 0 )); then
320+
echo "::error::clang-tidy found issues (exit code: ${rc}). Please run 'clang-tidy --fix' locally to fix them."
321+
git diff --color=always || true
322+
exit "${rc}"
305323
fi
306324
307325
- name: Enable core dump generation (Linux / GitHub-hosted runners)

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,7 @@ tilelang/jit/adapter/cython/.cycache
9797

9898
# claude
9999
**/.claude
100+
101+
# CMake
102+
cmake-build/
103+
cmake-build-*/

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ repos:
3232
args: [--ignore-case]
3333
files: ^docs/spelling_wordlist\.txt$
3434
- repo: https://github.com/pre-commit/mirrors-clang-format
35-
rev: v15.0.7 # sync with requirements-lint.txt
35+
rev: v21.1.2 # sync with requirements-lint.txt
3636
hooks:
3737
- id: clang-format
3838
exclude: |
@@ -41,7 +41,7 @@ repos:
4141
^.+\.json$
4242
)
4343
- repo: https://github.com/astral-sh/ruff-pre-commit
44-
rev: v0.14.0 # sync with requirements-lint.txt
44+
rev: v0.14.1 # sync with requirements-lint.txt
4545
hooks:
4646
- id: ruff-check
4747
args: [--fix, --exit-non-zero-on-fix]

0 commit comments

Comments
 (0)