@@ -4,37 +4,63 @@ 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
+ container :
12
+ image : dtors/base-cpp:latest
13
+
10
14
steps :
11
15
- name : Checkout code
12
- uses : actions/checkout@v3
13
- - name : Get changed files
14
- uses : jitterbit/get-changed-files@v1
15
- id : changed_files
16
- 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
16
+ uses : actions/checkout@v4
17
+
18
+ - name : Configure Git Safe Directory
19
+ run : |
20
+ git config --global --add safe.directory $(pwd)
21
+
22
+ - name : Find affected files
23
+ run : |
24
+ git fetch origin ${{ github.base_ref }} --depth=1
25
+ git diff --name-only origin/${{ github.base_ref }} > affected_files.txt
26
+ echo "Affected files:"
27
+ cat affected_files.txt
28
+
29
+ - name : Find affected cpp files
30
+ run : |
31
+ > affected_cpp_files.txt
32
+
33
+ while read file; do
34
+ if [[ "$file" == *.cpp || "$file" == *.h || "$file" == *.hpp || "$file" == *.cc || "$file" == *.cxx || "$file" == *.hxx ]]; then
35
+ echo "$file" >> affected_cpp_files.txt
36
+ fi
37
+ done < affected_files.txt
38
+
39
+ sort -u affected_cpp_files.txt -o affected_cpp_files.txt
40
+ echo "Affected cpp files:"
41
+ cat affected_cpp_files.txt
42
+
43
+ echo "cpp_files=$(cat affected_cpp_files.txt | tr '\n' ' ')" >> $GITHUB_ENV
44
+ shell : bash
45
+
46
+ - name : Generate Compile Commands
47
+ if : env.cpp_files != ''
48
+ run : |
49
+ echo "Generating compile commands"
50
+ bazel run @hedron_compile_commands//:refresh_all
51
+
52
+ - name : Running Clang-Tidy
53
+ if : env.cpp_files != ''
54
+ run : |
55
+ > clang_tidy_output.txt
56
+
57
+ echo "Running Clang-Tidy for: ${cpp_files}"
58
+ clang-tidy ${cpp_files} -p ./compile_commands.json -header-filter=.* -system-headers > clang_tidy_output.txt
59
+
60
+ - name : Skip Clang-Tidy
61
+ if : env.cpp_files == ''
62
+ run : echo "No affected cpp files found. Skipping Clang-Tidy."
63
+
38
64
- name : Show failure message
39
65
if : failure()
40
66
run : |-
43
69
1. Generate compile commands:
44
70
bazel run @hedron_compile_commands//:refresh_all
45
71
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
72
+ 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
73
======================================================================================"
0 commit comments