-
Notifications
You must be signed in to change notification settings - Fork 18
187 lines (156 loc) · 5.73 KB
/
clang-tidy.yml
File metadata and controls
187 lines (156 loc) · 5.73 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
name: clang-tidy
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
clang-tidy:
runs-on: ubuntu-latest
env:
BUILD_DIR: build
FIXES_DIR: clang_tidy_fixes
REPORT_HTML: clang-tidy-report.html
# Scan these roots for *.cpp
INCLUDE_DIRS: |
src
# Exclude these folders (repo-root relative).
# Tip: list the folder roots; the step adds '/*' for you.
EXCLUDE_DIRS: |
src/tests
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install LLVM/Clang + deps
run: |
sudo apt-get update
sudo apt-get install -y clang-tidy clang cmake ninja-build python3-yaml lcov
- name: Reorganize sources for clang-tidy
run: |
mkdir src
# Move ONLY your two real source files into src
mv tinyexpr.cpp src/
mv tinyexpr.h src/ 2>/dev/null || true # if it exists
# Move the whole tests folder under src/
mv tests src/
# Recreate symlinks so CMake can still find files at their old locations
ln -s src/tinyexpr.cpp tinyexpr.cpp
ln -s src/tests tests
# Create compile_commands.json for clang-tidy
- name: Configure CMake compile_commands.json
run: |
cmake -S src/tests -B "$BUILD_DIR" -DTE_BUILD_TEST_RUNNER=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G Ninja
# If your project generates headers, you can add a light build:
# cmake --build "$BUILD_DIR" -j
- name: Collect target files (include + prune excludes)
id: files
shell: bash
run: |
set -euo pipefail
# Build: find <INCLUDE_DIRS> \( -path EX1/* -o -path EX2/* ... \) -prune -o -type f -name '*.cpp' -print
readarray -t roots <<<"$(printf "%s\n" "$INCLUDE_DIRS" | sed '/^\s*$/d')"
readarray -t exdirs <<<"$(printf "%s\n" "$EXCLUDE_DIRS" | sed '/^\s*$/d')"
if [[ ${#roots[@]} -eq 0 ]]; then
echo "No INCLUDE_DIRS configured"; exit 0
fi
# Assemble prune expression
prune=()
if [[ ${#exdirs[@]} -gt 0 ]]; then
prune+=( "(" )
for i in "${!exdirs[@]}"; do
d="${exdirs[$i]}"; [[ -z "$d" ]] && continue
[[ $i -gt 0 ]] && prune+=( -o )
prune+=( -path "$d/*" )
done
prune+=( ")" -prune -o )
fi
files=$(
find "${roots[@]}" "${prune[@]}" -type f -name '*.cpp' -print | sort
)
echo "files<<EOF" >> "$GITHUB_OUTPUT"
echo "$files" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
echo "Selected files:"
printf '%s\n' $files || true
- name: Short-circuit if none
if: ${{ steps.files.outputs.files == '' }}
run: |
echo "No matching *.cpp after excludes."
echo "No matching *.cpp after excludes." >> $GITHUB_STEP_SUMMARY
- name: Run clang-tidy
if: ${{ steps.files.outputs.files != '' }}
shell: bash
env:
FIXES_DIR: clang_tidy_fixes
run: |
set -euo pipefail
mkdir -p "$FIXES_DIR" logs
# Read the newline-separated list
while IFS= read -r file; do
[[ -z "$file" ]] && continue
echo "=== clang-tidy -> $file ==="
# POSIX-safe path mangling (avoid ${var//.../...} which is a bashism)
base="$(printf '%s' "$file" | sed 's#/#__#g')"
clang-tidy -p "$BUILD_DIR" -fix=false "$file" \
--extra-arg=-fno-color-diagnostics \
--extra-arg=-fdiagnostics-color=never \
> "logs/${base}.txt" 2>&1 || true
done <<< "${{ steps.files.outputs.files }}"
- name: Generate HTML report
if: ${{ steps.files.outputs.files != '' }}
run: |
python3 .github/scripts/clang_tidy_html_report.py \
--logs logs/*.txt \
--out "$REPORT_HTML" \
--counts ct_counts.json \
--fail-on warnings
{
echo "### Clang-Tidy Report (read-only)";
echo;
echo "Generated **$REPORT_HTML** (fail-on=warnings after suppressions).";
} >> "$GITHUB_STEP_SUMMARY"
- name: Workspace file check
if: always()
run: |
echo "=== WORKSPACE TREE (max 4 levels) ==="
find . -maxdepth 4 -type f | sort || true
echo ""
echo "=== Checking report HTML ==="
echo "REPORT_HTML = $REPORT_HTML"
if [ -f "$REPORT_HTML" ]; then
echo "FOUND: $REPORT_HTML"
else
echo "MISSING: $REPORT_HTML"
fi
echo ""
echo "=== Checking ct_counts.json ==="
if [ -f ct_counts.json ]; then
echo "FOUND: ct_counts.json"
else
echo "MISSING: ct_counts.json"
fi
echo ""
echo "=== Checking logs directory ==="
if [ -d logs ]; then
echo "logs/ exists"
ls -al logs
else
echo "logs directory MISSING"
fi
echo ""
echo "=== Checking log files ==="
ls logs/*.txt 2>/dev/null || echo "No log files found"
- name: Upload artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: clang-tidy-report
path: |
${{ env.REPORT_HTML }}
logs/
ct_counts.json
if-no-files-found: warn
retention-days: 14