Skip to content

Commit 5469e7c

Browse files
alanhcclaude
andcommitted
CI: render a test report table in the GitHub job summary
Parse each suite's "All N tests passed" output and write a Markdown table (suite / target / result / status) to $GITHUB_STEP_SUMMARY, plus a total line. Run-only Makefiles (dsa/linked_list) show as smoke tests. Step still exits non-zero on any failure so the run goes red. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 4628892 commit 5469e7c

1 file changed

Lines changed: 54 additions & 18 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,65 @@ jobs:
2828
make --version | head -1
2929
uv --version
3030
31-
# 掃描每個 Makefile,挑最適合的 target:
32-
# 有 test 就 make test;否則有 run 就 make run;再否則只 make(確認能編譯)。
31+
# 掃描每個 Makefile,挑最適合的 target(有 test 就 make test;否則 run;再否則 make),
32+
# 解析每個套件的「All N tests passed」,寫成 Markdown 表格到 Job Summary。
3333
- name: Run all Makefile tests
3434
run: |
35-
set -euo pipefail
36-
found=0
35+
set -uo pipefail
36+
summary="${GITHUB_STEP_SUMMARY:-/dev/stdout}"
37+
{
38+
echo "## 🧪 Test Report"
39+
echo ""
40+
echo "| Suite | Target | Result | Status |"
41+
echo "|-------|--------|--------|--------|"
42+
} >> "$summary"
43+
overall=0; total_tests=0; total_suites=0; found=0
3744
while IFS= read -r mk; do
3845
found=1
39-
dir=$(dirname "$mk")
40-
echo "::group::$dir"
41-
if grep -qE '^test:' "$mk"; then
42-
echo ">>> make -C $dir test"
43-
make -C "$dir" test
44-
elif grep -qE '^run:' "$mk"; then
45-
echo ">>> make -C $dir run"
46-
make -C "$dir" run
46+
dir=$(dirname "$mk"); dir=${dir#./}
47+
if grep -qE '^test:' "$mk"; then target=test
48+
elif grep -qE '^run:' "$mk"; then target=run
49+
else target=build; fi
50+
echo "::group::$dir ($target)"
51+
if [ "$target" = build ]; then
52+
out=$(make -C "$dir" 2>&1); rc=$?
4753
else
48-
echo ">>> make -C $dir"
49-
make -C "$dir"
54+
out=$(make -C "$dir" "$target" 2>&1); rc=$?
5055
fi
56+
echo "$out"
5157
echo "::endgroup::"
58+
[ "$rc" -ne 0 ] && overall=1
59+
label=""; ran_any=0
60+
while IFS= read -r line; do
61+
if [[ "$line" =~ ^===\ (.+)\ ===$ ]]; then
62+
label="${BASH_REMATCH[1]}"
63+
elif [[ "$line" =~ ^\./([^\ ]+) ]]; then
64+
[ -z "$label" ] && label="$dir → ${BASH_REMATCH[1]}"
65+
elif [[ "$line" =~ ^All\ ([0-9]+)\ tests\ passed$ ]]; then
66+
n="${BASH_REMATCH[1]}"; lbl="${label:-$dir}"
67+
echo "| \`$lbl\` | $target | $n passed | ✅ |" >> "$summary"
68+
label=""; ran_any=1
69+
total_tests=$((total_tests + n)); total_suites=$((total_suites + 1))
70+
fi
71+
done <<< "$out"
72+
if [ "$ran_any" -eq 0 ]; then
73+
if [ "$rc" -eq 0 ]; then
74+
echo "| \`$dir\` | $target | built & ran (smoke) | ✅ |" >> "$summary"
75+
else
76+
echo "| \`$dir\` | $target | FAILED | ❌ |" >> "$summary"
77+
fi
78+
total_suites=$((total_suites + 1))
79+
elif [ "$rc" -ne 0 ]; then
80+
echo "| \`$dir\` | $target | make failed | ❌ |" >> "$summary"
81+
fi
5282
done < <(find . -name Makefile -not -path '*/node_modules/*' | sort)
53-
if [ "$found" -eq 0 ]; then
54-
echo "No Makefile found" >&2
55-
exit 1
56-
fi
83+
{
84+
echo ""
85+
if [ "$overall" -eq 0 ]; then
86+
echo "**Total: $total_tests tests across $total_suites suites — ✅ all passed**"
87+
else
88+
echo "**Total: $total_tests tests across $total_suites suites — ❌ failures above**"
89+
fi
90+
} >> "$summary"
91+
if [ "$found" -eq 0 ]; then echo "No Makefile found" >&2; exit 1; fi
92+
exit $overall

0 commit comments

Comments
 (0)