Skip to content

Commit c176e82

Browse files
committed
ci: improve clang-tidy workflow
1 parent 84d91b1 commit c176e82

File tree

2 files changed

+55
-27
lines changed

2 files changed

+55
-27
lines changed

.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Checks: 'clang-analyzer-*,bugprone-*,modernize-*,readability-*,cppcoreguidelines-*,performance-*,concurrency-*,cert-*,google-*,misc-*'
22
WarningsAsErrors: '*'
3-
HeaderFilterRegex: '^(?!.*(third_party|external)).*'
3+
HeaderFilterRegex: '^(?!.*(third_party|external|/usr/)).*'

.github/workflows/clang_tidy.yml

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,65 @@ name: Clang-Tidy
44
on: # yamllint disable-line rule:truthy
55
pull_request:
66
branches: ['*']
7+
78
jobs:
89
clang-tidy:
910
runs-on: ubuntu-latest
11+
1012
steps:
1113
- name: Checkout code
12-
uses: actions/checkout@v3
13-
- name: Get changed files
14-
uses: jitterbit/get-changed-files@v1
15-
id: changed_files
14+
uses: actions/checkout@v4
15+
16+
- name: Find affected files
17+
id: affected_files
18+
run: |
19+
git fetch origin ${{ github.base_ref }} --depth=1
20+
git diff --name-only origin/${{ github.base_ref }} > affected_files.txt
21+
echo "Affected files:"
22+
cat affected_files.txt
23+
24+
- name: Find affected cpp files
25+
run: |
26+
> affected_cpp_files.txt
27+
28+
while read file; do
29+
if [[ "$file" == *.cpp || "$file" == *.h || "$file" == *.hpp || "$file" == *.cc || "$file" == *.cxx || "$file" == *.hxx ]]; then
30+
echo "$file" >> affected_cpp_files.txt
31+
fi
32+
done < affected_files.txt
33+
34+
sort -u affected_cpp_files.txt -o affected_cpp_files.txt
35+
echo "Affected cpp files:"
36+
cat affected_cpp_files.txt
37+
38+
echo "cpp_files=$(cat affected_cpp_files.txt | tr '\n' ' ')" >> $GITHUB_ENV
39+
40+
- name: Generate Compile Commands
41+
if: env.cpp_files != ''
42+
uses: addnab/docker-run-action@v3
1643
with:
17-
format: space-delimited
18-
token: ${{ secrets.GITHUB_TOKEN }}
19-
- name: Run Clang-Tidy
20-
run: |-
21-
IFS=' ' read -r -a files <<< "${{ steps.changed_files.outputs.all }}"
22-
cpp_files=()
23-
for file in "${files[@]}"; do
24-
if [[ "$file" == *.cpp || "$file" == *.h || "$file" == *.hpp || "$file" == *.cc || "$file" == *.cxx || "$file" == *.hxx ]]; then
25-
cpp_files+=("$file")
26-
fi
27-
done
28-
29-
if [ ${#cpp_files[@]} -gt 0 ]; then
30-
echo -e "Running clang-tidy"
31-
bazel build //... \
32-
--aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect \
33-
--output_groups=report \
34-
--@bazel_clang_tidy//:clang_tidy_config=//:clang_tidy_config
35-
else
36-
echo -e "Skipping clang-tidy since no source files were changed."
37-
fi
44+
image: dtors/base-cpp:latest
45+
run: |
46+
ls /usr/bin/bazelisk
47+
whereis clang-tidy
48+
echo "Generating compile commands"
49+
bazel run @hedron_compile_commands//:refresh_all
50+
51+
- name: Running Clang-Tidy
52+
if: env.cpp_files != ''
53+
uses: addnab/docker-run-action@v3
54+
with:
55+
image: dtors/base-cpp:latest
56+
run: |
57+
> clang_tidy_output.txt
58+
59+
echo "Running Clang-Tidy for: ${cpp_files}"
60+
clang-tidy ${cpp_files} -p ./compile_commands.json -header-filter=.* -system-headers > clang_tidy_output.txt
61+
62+
- name: Skip Clang-Tidy
63+
if: env.cpp_files == ''
64+
run: echo "No affected cpp files found. Skipping Clang-Tidy."
65+
3866
- name: Show failure message
3967
if: failure()
4068
run: |-
@@ -43,5 +71,5 @@ jobs:
4371
1. Generate compile commands:
4472
bazel run @hedron_compile_commands//:refresh_all
4573
2. Run clang-tidy:
46-
find . -name \"*.cpp\" -o -name \"*.h\" -o -name \"*.hpp\" -o -name \"*.cc\" -o -name \"*.cxx\" -o -name \"*.hxx\" | xargs clang-tidy -fix -fix-errors -p ./compile_commands.json
74+
find . -name \"*.cpp\" -o -name \"*.h\" -o -name \"*.hpp\" -o -name \"*.cc\" -o -name \"*.cxx\" -o -name \"*.hxx\" | xargs clang-tidy -fix -fix-errors -p ./compile_commands.json --system-headers=0
4775
======================================================================================"

0 commit comments

Comments
 (0)