-
Notifications
You must be signed in to change notification settings - Fork 526
146 lines (128 loc) · 4.44 KB
/
clang_tidy.yml
File metadata and controls
146 lines (128 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: Clang-Tidy
on:
push:
branches: ["main"]
paths:
- "**/*.c"
- "**/*.cc"
- "**/*.cpp"
- "**/*.cxx"
- "**/*.h"
- "**/*.hpp"
- "CMakeLists.txt"
- "**/CMakeLists.txt"
- "cmake/**"
- ".clang-tidy"
pull_request:
branches: ["main"]
paths:
- "**/*.c"
- "**/*.cc"
- "**/*.cpp"
- "**/*.cxx"
- "**/*.h"
- "**/*.hpp"
- "CMakeLists.txt"
- "**/CMakeLists.txt"
- "cmake/**"
- ".clang-tidy"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
clang_tidy:
name: Clang-Tidy Checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y clang-tidy cmake ninja-build
- name: Configure CMake and export compile commands
run: |
cmake -S . -B build -G Ninja \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DENABLE_HASWELL=ON \
-DBUILD_TOOLS=OFF
- name: Collect changed C/C++ files
id: changed_files
uses: tj-actions/changed-files@v46
with:
files: |
**/*.c
**/*.cc
**/*.cpp
**/*.cxx
!thirdparty/**
!build/**
separator: "\n"
- name: Filter changed files to compile database entries
id: tidy_files
if: steps.changed_files.outputs.any_changed == 'true'
run: |
python3 - <<'PY'
import json
import os
from pathlib import Path
changed = [line.strip() for line in """${{ steps.changed_files.outputs.all_changed_files }}""".splitlines() if line.strip()]
compile_db_path = Path("build/compile_commands.json")
with compile_db_path.open("r", encoding="utf-8") as f:
compile_db = json.load(f)
compile_entries = set()
for entry in compile_db:
file_path = entry.get("file")
if not file_path:
continue
normalized = os.path.normpath(file_path).replace("\\", "/")
compile_entries.add(normalized)
selected = []
skipped = []
cwd = Path.cwd()
for file_path in changed:
if not Path(file_path).is_file():
skipped.append(f"{file_path} (missing)")
continue
abs_normalized = os.path.normpath(str((cwd / file_path).resolve())).replace("\\", "/")
rel_normalized = os.path.normpath(file_path).replace("\\", "/")
if abs_normalized in compile_entries or rel_normalized in compile_entries:
selected.append(file_path)
else:
skipped.append(f"{file_path} (no compile_commands entry)")
output_path = os.environ["GITHUB_OUTPUT"]
with open(output_path, "a", encoding="utf-8") as out:
out.write(f"any_tidy_files={'true' if selected else 'false'}\n")
out.write("all_tidy_files<<EOF\n")
out.write("\n".join(selected))
out.write("\nEOF\n")
out.write("skipped_files<<EOF\n")
out.write("\n".join(skipped))
out.write("\nEOF\n")
PY
- name: Show skipped files
if: steps.changed_files.outputs.any_changed == 'true' && steps.tidy_files.outputs.skipped_files != ''
run: |
echo "Skipping files:"
printf '%s\n' "${{ steps.tidy_files.outputs.skipped_files }}"
- name: Run clang-tidy
if: steps.tidy_files.outputs.any_tidy_files == 'true'
run: |
mapfile -t changed_files <<'EOF'
${{ steps.tidy_files.outputs.all_tidy_files }}
EOF
for file in "${changed_files[@]}"; do
if [ -f "$file" ]; then
echo "Running clang-tidy on $file"
clang-tidy -p build --warnings-as-errors='*' "$file"
fi
done
- name: No clang-tidy files to analyze
if: steps.changed_files.outputs.any_changed != 'true' || steps.tidy_files.outputs.any_tidy_files != 'true'
run: |
echo "No changed source files with compile_commands entries matched clang-tidy patterns."