-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CI action that reports clang-tidy warnings as review comments.
#xls-build-gardener
- Loading branch information
Showing
5 changed files
with
89 additions
and
5 deletions.
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,26 @@ | ||
#!/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. | ||
|
||
# Prepare compilation DB and 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-cached.sh -p1 | ||
|
||
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