-
Notifications
You must be signed in to change notification settings - Fork 179
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 CI action that reports clang-tidy warnings as review comments. #1658
Closed
hzeller
wants to merge
1
commit into
google:main
from
hzeller:feature-20241010-run-clang-tidy-review
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: Auto Review Analyzers | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths-ignore: | ||
# Do not trigger action when docs are updated. | ||
- 'docs/**' | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
clang-tidy: | ||
runs-on: | ||
labels: ubuntu-22.04-64core | ||
|
||
permissions: | ||
# Open PR comments | ||
pull-requests: write | ||
# OPTIONAL: auto-closing conversations requires the `contents` permission | ||
contents: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
fetch-depth: 0 | ||
|
||
- name: Fetch base branch to compare to | ||
run: | | ||
git remote add review-base "https://github.com/${{ github.event.pull_request.base.repo.full_name }}" | ||
git fetch --no-tags --no-recurse-submodules review-base "${{ github.event.pull_request.base.ref }}" | ||
|
||
- name: Restore Nightly Bazel Cache | ||
uses: actions/cache/restore@v4 | ||
with: | ||
path: "~/.cache/bazel" | ||
key: bazel-cache-nightly-${{ runner.os }}-${{ github.sha }} | ||
restore-keys: bazel-cache-nightly-${{ runner.os }}- | ||
|
||
- name: Create compilation DB | ||
run: | | ||
xls/dev_tools/make-compilation-db.sh | ||
|
||
- name: Run clang-tidy on diff | ||
run: | | ||
mkdir clang-tidy-result | ||
git diff -U1000 "$(git merge-base HEAD review-base/${{ github.event.pull_request.base.ref }})" | xls/dev_tools/run-clang-tidy-diff.sh -p1 -path build -export-fixes clang-tidy-result/fixes.yml | ||
|
||
- name: Run clang-tidy-pr-comments action | ||
uses: hzeller/clang-tidy-pr-comments@master | ||
with: | ||
# Token to allow commenting | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
clang_tidy_fixes: clang-tidy-result/fixes.yml | ||
request_changes: true | ||
suggestions_per_comment: 10 |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2023 The XLS Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Run clang-tidy-diff that we already have bundled in our toolchain. | ||
# Reads a unified diff from stdin. If a header is removed, we want to get | ||
# enough context to see that it is not used anywhere; so invoke like | ||
# | ||
# git diff -U1000 | xls/dev_tools/run-clang-tidy-diff.sh -p1 2>/dev/null | ||
|
||
CLANG_TIDY_LLVM_BASE="$(bazel info output_base)/external/llvm_toolchain_llvm/" | ||
|
||
"${CLANG_TIDY_LLVM_BASE}/share/clang/clang-tidy-diff.py" \ | ||
-clang-tidy-binary="${CLANG_TIDY_LLVM_BASE}/bin/clang-tidy" "$@" |
This file contains 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
This file contains 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, I am using my fork here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I meant: when using the action on your xls fork (not a fork of the action).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I see. I did not try that as my personal github does not have access to hi-umpf runners (just building the compilation DB takes more than 30min before I gave up)