Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clang-tidy PR comment bot #1269

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for these comments. These workflow files have magic functions so I really like you commenting what it's doing :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copy pasted them so I can't take credit 😅

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)
Loading