-
-
Notifications
You must be signed in to change notification settings - Fork 69
224 lines (196 loc) · 9.14 KB
/
Copy pathclang-tidy.yml
File metadata and controls
224 lines (196 loc) · 9.14 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
name: Clang-Tidy
permissions:
contents: read
on:
pull_request:
branches: [ main ]
types: [ opened, synchronize, reopened, ready_for_review ]
paths-ignore:
- '**.md'
- 'docs/**'
- 'docs-site/**'
- '.github/FUNDING.yml'
- 'CITATION.cff'
- 'LICENSE'
- '.clang-format'
- '.clang-tidy'
- '.gitignore'
env:
BUILD_TYPE: Release
# Force Node.js 24 for all JavaScript actions (eliminates Node.js 20 deprecation warnings)
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
clang-tidy:
if: github.event.pull_request.draft == false
name: Static Analysis with Clang-Tidy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y clang-tidy-18 clang-18 jq
# Create symlinks for easier access
sudo ln -sf /usr/bin/clang-tidy-18 /usr/bin/clang-tidy
sudo ln -sf /usr/bin/clang-18 /usr/bin/clang
sudo ln -sf /usr/bin/clang++-18 /usr/bin/clang++
- name: Verify Clang-Tidy Installation
run: |
which clang-tidy
clang-tidy --version
- name: Configure CMake
env:
CC: clang-18
CXX: clang++-18
run: |
cmake -B ${{github.workspace}}/build \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_C_COMPILER=clang-18 \
-DCMAKE_CXX_COMPILER=clang++-18 \
-DUNIVERSAL_BUILD_EDUCATION=ON \
-DUNIVERSAL_BUILD_NUMBER_POSITS=ON
- name: Build (to generate compile_commands.json)
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j "$(nproc)"
- name: Verify compile_commands.json
run: |
ls -lh ${{github.workspace}}/build/compile_commands.json
echo "Number of compilation units:"
jq '. | length' ${{github.workspace}}/build/compile_commands.json
- name: Run Clang-Tidy on Core Headers
# Advisory check - comprehensive analysis without blocking the build
continue-on-error: true
run: |
cd ${{github.workspace}}
# Define comprehensive header list covering all major number systems
cat > build/core-headers.txt << EOF
include/sw/universal/native/ieee754.hpp
include/sw/universal/numerics/error_free_ops.hpp
include/sw/universal/traits/number_traits.hpp
include/sw/universal/number/edecimal/edecimal.hpp
include/sw/universal/number/erational/erational.hpp
include/sw/universal/number/integer/integer.hpp
include/sw/universal/number/fixpnt/fixpnt.hpp
include/sw/universal/number/rational/rational.hpp
include/sw/universal/number/cfloat/cfloat.hpp
include/sw/universal/number/areal/areal.hpp
include/sw/universal/number/lns/lns.hpp
include/sw/universal/number/dbns/dbns.hpp
include/sw/universal/number/posit/posit.hpp
include/sw/universal/number/posit2/posit.hpp
include/sw/universal/number/posito/posito.hpp
include/sw/universal/number/sorn/sorn.hpp
include/sw/universal/number/dd/dd.hpp
include/sw/universal/number/qd/qd.hpp
include/sw/universal/number/dd_cascade/dd_cascade.hpp
include/sw/universal/number/td_cascade/td_cascade.hpp
include/sw/universal/number/qd_cascade/qd_cascade.hpp
include/sw/universal/internal/blockbinary/blockbinary.hpp
include/sw/universal/internal/blockdecimal/blockdecimal.hpp
include/sw/universal/internal/blockfraction/blockfraction.hpp
include/sw/universal/internal/blocksignificand/blocksignificand.hpp
include/sw/universal/internal/blocktriple/blocktriple.hpp
include/sw/universal/internal/value/value.hpp
include/sw/universal/internal/floatcascade/floatcascade.hpp
EOF
echo "Running clang-tidy on core headers..."
> build/clang-tidy-results.txt
total_files=0
files_with_issues=0
while IFS= read -r file; do
if [ -f "$file" ]; then
total_files=$((total_files + 1))
echo "Analyzing: $file"
# Run clang-tidy and capture output
if ! clang-tidy -p=build "$file" 2>&1 | tee -a build/clang-tidy-results.txt | grep -q "warning:\|error:"; then
echo " No issues found"
else
files_with_issues=$((files_with_issues + 1))
echo " Issues found (see artifact for details)"
fi
fi
done < build/core-headers.txt
echo "" | tee -a build/clang-tidy-results.txt
echo "=== Summary ===" | tee -a build/clang-tidy-results.txt
echo "Files analyzed: $total_files" | tee -a build/clang-tidy-results.txt
echo "Files with issues: $files_with_issues" | tee -a build/clang-tidy-results.txt
- name: Run Clang-Tidy on Sample Tests
# Advisory check on representative test files
continue-on-error: true
run: |
cd ${{github.workspace}}
# Sample API tests from various number systems
find static/*/api -name "api.cpp" -type f 2>/dev/null | head -n 10 > build/test-files.txt
if [ -s build/test-files.txt ]; then
echo "Running clang-tidy on sample test files..." >> build/clang-tidy-results.txt
echo "" >> build/clang-tidy-results.txt
echo "=== Test Files ==="
while IFS= read -r file; do
echo "Analyzing: $file"
clang-tidy -p=build "$file" 2>&1 | tee -a build/clang-tidy-results.txt | head -n 20 || true
done < build/test-files.txt
fi
- name: Generate Analysis Summary
if: always()
run: |
cd ${{github.workspace}}
# Count issues
warnings=$(grep -c "warning:" build/clang-tidy-results.txt 2>/dev/null || echo "0")
errors=$(grep -c "error:" build/clang-tidy-results.txt 2>/dev/null || echo "0")
# Generate summary
echo "## Clang-Tidy Static Analysis (Advisory)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "This is an **advisory check** - findings do not block the PR." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Metric | Count |" >> $GITHUB_STEP_SUMMARY
echo "|----------|-----------|" >> $GITHUB_STEP_SUMMARY
echo "| Warnings | $warnings |" >> $GITHUB_STEP_SUMMARY
echo "| Errors | $errors |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "$warnings" -eq 0 ] && [ "$errors" -eq 0 ]; then
echo "**No issues found!** All analyzed files passed clang-tidy checks." >> $GITHUB_STEP_SUMMARY
else
echo "**Issues detected** - Download the \`clang-tidy-results\` artifact for full details." >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Files Analyzed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- All core number system headers (integer, fixpnt, cfloat, posit, lns, etc.)" >> $GITHUB_STEP_SUMMARY
echo "- Sample API test files" >> $GITHUB_STEP_SUMMARY
echo "- Core infrastructure headers (floatcascade, traits)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Running Locally" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "# Generate compile database and run clang-tidy" >> $GITHUB_STEP_SUMMARY
echo "mkdir build && cd build" >> $GITHUB_STEP_SUMMARY
echo "cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON" >> $GITHUB_STEP_SUMMARY
echo "make" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "# Check specific file" >> $GITHUB_STEP_SUMMARY
echo "clang-tidy -p=. ../include/sw/universal/number/posit/posit.hpp" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
# Show top issues in summary (if any)
if [ "$warnings" -gt 0 ] || [ "$errors" -gt 0 ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Sample Issues" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
grep -E "warning:|error:" build/clang-tidy-results.txt | head -n 10 >> $GITHUB_STEP_SUMMARY || true
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "_Full results available in artifacts_" >> $GITHUB_STEP_SUMMARY
fi
- name: Upload Analysis Results
if: always()
uses: actions/upload-artifact@v7
with:
name: clang-tidy-results
path: |
build/clang-tidy-results.txt
build/core-headers.txt
build/test-files.txt
.clang-tidy