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 CI action that reports clang-tidy warnings as review comments. #1658

Closed
Closed
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
59 changes: 59 additions & 0 deletions .github/workflows/review-actions.yml
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
Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member Author

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)

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
3 changes: 1 addition & 2 deletions xls/dev_tools/make-compilation-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set -e
readonly OUTPUT_BASE="$(bazel info output_base)"

readonly COMPDB_SCRIPT="${OUTPUT_BASE}/external/com_grail_bazel_compdb/generate.py"
[ -r "${COMPDB_SCRIPT}" ] || bazel fetch @com_grail_bazel_compdb//...
[ -r "${COMPDB_SCRIPT}" ] || bazel fetch --noshow_progress @com_grail_bazel_compdb//...

python3 "${COMPDB_SCRIPT}"

Expand All @@ -33,4 +33,3 @@ s/ -f[^ ]*/ /g # remove all -fxyz options
s/ --target[^ ]*/ /g # target platform not needed, might confuse
s/ -stdlib=libc++/ / # otherwise, clang-tidy does not find c++ headers
EOF

25 changes: 25 additions & 0 deletions xls/dev_tools/run-clang-tidy-diff.sh
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" "$@"
4 changes: 2 additions & 2 deletions xls/dslx/errors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#include "xls/dslx/errors.h"

#include <string>
#include <string_view>
//#include <string> testing
//#include <string_view>

#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
Expand Down
2 changes: 1 addition & 1 deletion xls/ir/function_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <memory>
#include <optional>
#include <ostream>
#include <string>
// #include <string> // testing clang tidy
#include <string_view>
#include <utility>
#include <variant>
Expand Down
Loading