Skip to content

Commit

Permalink
Add clang-tidy PR comment bot (#1269)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsmithtt authored Nov 15, 2024
1 parent 3ee0467 commit 8f3f90a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,37 @@ jobs:
cmake --install ${{ steps.strings.outputs.build-output-dir }} --component Test
- name: Lint
id: lint
shell: bash
if: matrix.build.enable_perf == 'OFF'
run: |
source env/activate
cmake --build ${{ steps.strings.outputs.build-output-dir }} -- clang-tidy
- name: Unique-ify clang-tidy fixes
shell: bash
if: failure() && steps.lint.outcome == 'failure'
run: |
source env/activate
python tools/scripts/filter-clang-tidy-fixes.py ${{ steps.strings.outputs.build-output-dir }}/clang-tidy-fixes.yaml
- name: Clang-tidy PR Comments
uses: platisd/clang-tidy-pr-comments@a8811fa17cd6bd02c52a3791b44f9840777e396a
if: failure() && steps.lint.outcome == 'failure'
with:
# The GitHub token (or a personal access token)
github_token: ${{ secrets.GITHUB_TOKEN }}
# The path to the clang-tidy fixes generated above
clang_tidy_fixes: ${{ steps.strings.outputs.build-output-dir }}/clang-tidy-fixes.yaml
# Optionally set to true if you want the Action to request
# changes in case warnings are found
request_changes: false
# Optionally set the number of comments per review
# to avoid GitHub API timeouts for heavily loaded
# pull requests
suggestions_per_comment: 10
python_path: "python3"

- name: Run Test
shell: bash
run: |
Expand Down
2 changes: 1 addition & 1 deletion cmake/modules/LintTools.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# clang-tidy setup
add_custom_target(clang-tidy-filter-out-external-srcs COMMAND python3 ${TTMLIR_SOURCE_DIR}/tools/scripts/filter-compile-commands.py ${TTMLIR_BINARY_DIR}/compile_commands.json "${TTMLIR_SOURCE_DIR}")
add_custom_target(clang-tidy COMMAND run-clang-tidy.py -p ${PROJECT_BINARY_DIR} -warnings-as-errors '*' -extra-arg-before=-DDISABLE_STATIC_ASSERT_TESTS -extra-arg-before=-D__cpp_structured_bindings=202400 DEPENDS clang-tidy-filter-out-external-srcs)
add_custom_target(clang-tidy COMMAND run-clang-tidy.py -p ${PROJECT_BINARY_DIR} -export-fixes clang-tidy-fixes.yaml -warnings-as-errors '*' -extra-arg-before=-DDISABLE_STATIC_ASSERT_TESTS -extra-arg-before=-D__cpp_structured_bindings=202400 DEPENDS clang-tidy-filter-out-external-srcs)
add_custom_target(clang-format COMMAND git-clang-format)
20 changes: 20 additions & 0 deletions tools/scripts/filter-clang-tidy-fixes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC
#
# SPDX-License-Identifier: Apache-2.0
import yaml
import sys

with open(sys.argv[1], "r") as fd:
d = yaml.load(fd, yaml.SafeLoader)

fixes = d["Diagnostics"]
uniques = set([str(f) for f in fixes])
unique_fixes = []
for f in fixes:
if str(f) in uniques:
unique_fixes.append(f)
uniques.remove(str(f))
d["Diagnostics"] = unique_fixes

with open(sys.argv[1], "w") as fd:
yaml.dump(d, fd)

0 comments on commit 8f3f90a

Please sign in to comment.