@@ -4,37 +4,65 @@ name: Clang-Tidy
4
4
on : # yamllint disable-line rule:truthy
5
5
pull_request :
6
6
branches : ['*']
7
+
7
8
jobs :
8
9
clang-tidy :
9
10
runs-on : ubuntu-latest
11
+
10
12
steps :
11
13
- 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
16
43
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
+
38
66
- name : Show failure message
39
67
if : failure()
40
68
run : |-
43
71
1. Generate compile commands:
44
72
bazel run @hedron_compile_commands//:refresh_all
45
73
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
47
75
======================================================================================"
0 commit comments