Skip to content

Commit 0f48d2c

Browse files
committed
Enhance clang-tidy integration in CI workflow
- Improved handling of empty clang-tidy output by ensuring tidy_output.txt is created and readable. - Added checks for empty output to default error and warning counts to zero. - Enhanced output formatting for error and warning counts, ensuring clean integer values. - Added logging for found errors and warnings to improve visibility in CI results.
1 parent a9ea7c8 commit 0f48d2c

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

.github/workflows/ci_tests.yml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,23 +226,43 @@ jobs:
226226
227227
if [ "${#files[@]}" -eq 0 ]; then
228228
echo "No C/C++ files to analyze."
229-
touch tidy_output.txt
229+
echo "" > tidy_output.txt
230230
exit 0
231231
fi
232232
233+
echo "Running clang-tidy on ${#files[@]} files..."
233234
clang-tidy "${files[@]}" -p cmake-build-tidy --format-style=file > tidy_output.txt 2>&1 || true
234-
touch tidy_output.txt
235+
236+
# Ensure file exists and is readable
237+
if [ ! -f tidy_output.txt ]; then
238+
echo "" > tidy_output.txt
239+
fi
235240
236241
- name: Count warnings and errors
237242
id: count_issues
238243
run: |
239-
# Count errors and warnings
240-
errors=$(grep -c "error:" tidy_output.txt || echo "0")
241-
warnings=$(grep -c "warning:" tidy_output.txt || echo "0")
244+
# Count errors and warnings - handle empty file case
245+
if [ ! -s tidy_output.txt ]; then
246+
errors=0
247+
warnings=0
248+
else
249+
errors=$(grep -c "error:" tidy_output.txt 2>/dev/null || echo "0")
250+
warnings=$(grep -c "warning:" tidy_output.txt 2>/dev/null || echo "0")
251+
fi
252+
253+
# Ensure we have clean integer values
254+
errors=$(echo "$errors" | tr -d '\n' | head -c 10)
255+
warnings=$(echo "$warnings" | tr -d '\n' | head -c 10)
256+
257+
# Default to 0 if empty or non-numeric
258+
errors=${errors:-0}
259+
warnings=${warnings:-0}
242260
243261
echo "errors=$errors" >> $GITHUB_OUTPUT
244262
echo "warnings=$warnings" >> $GITHUB_OUTPUT
245263
264+
echo "Found $errors errors and $warnings warnings"
265+
246266
# Fail if more than 3 warnings or any errors
247267
if [ "$errors" -gt 0 ] || [ "$warnings" -gt 3 ]; then
248268
echo "clang-tidy found $errors errors and $warnings warnings"

0 commit comments

Comments
 (0)