-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (105 loc) · 4.55 KB
/
Copy pathci.yml
File metadata and controls
110 lines (105 loc) · 4.55 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
name: CI
# 每次 push 到 main 或開 PR 時,自動跑 repo 內所有 Makefile 的測試。
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
# 安裝 uv(Python 測試用 `uv run python` 跑,符合專案慣例)
# 專案沒有 uv.lock / requirements,關掉 cache 避免無效快取警告
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
enable-cache: false
# gcc / g++ 在 ubuntu-latest 已預裝;顯示版本方便除錯
- name: Show toolchain versions
run: |
g++ --version
gcc --version
make --version | head -1
uv --version
# 掃描每個 Makefile,挑最適合的 target(有 test 就 make test;否則 run;再否則 make),
# 解析每個套件的「All N tests passed」,寫成 Markdown 表格到 Job Summary。
- name: Run all Makefile tests
run: |
set -uo pipefail
summary="${GITHUB_STEP_SUMMARY:-/dev/stdout}"
{
echo "## 🧪 Test Report"
echo ""
echo "| Suite | Target | Result | Status |"
echo "|-------|--------|--------|--------|"
} >> "$summary"
overall=0; total_tests=0; total_suites=0; found=0
while IFS= read -r mk; do
found=1
dir=$(dirname "$mk"); dir=${dir#./}
if grep -qE '^test:' "$mk"; then target=test
elif grep -qE '^run:' "$mk"; then target=run
else target=build; fi
echo "::group::$dir ($target)"
if [ "$target" = build ]; then
echo "$ make -C $dir"
out=$(make -C "$dir" 2>&1); rc=$?
else
echo "$ make -C $dir $target"
out=$(make -C "$dir" "$target" 2>&1); rc=$?
fi
echo "$out"
echo "::endgroup::"
[ "$rc" -ne 0 ] && overall=1
label=""; ran_any=0
while IFS= read -r line; do
if [[ "$line" =~ ^===\ (.+)\ ===$ ]]; then
label="${BASH_REMATCH[1]}"
elif [[ "$line" =~ ^\./([^\ ]+) ]]; then
[ -z "$label" ] && label="$dir → ${BASH_REMATCH[1]}"
elif [[ "$line" =~ ^All\ ([0-9]+)\ tests\ passed$ ]]; then
n="${BASH_REMATCH[1]}"; lbl="${label:-$dir}"
echo "| \`$lbl\` | $target | $n passed | ✅ |" >> "$summary"
label=""; ran_any=1
total_tests=$((total_tests + n)); total_suites=$((total_suites + 1))
fi
done <<< "$out"
if [ "$ran_any" -eq 0 ]; then
if [ "$rc" -eq 0 ]; then
echo "| \`$dir\` | $target | built & ran (smoke) | ✅ |" >> "$summary"
else
echo "| \`$dir\` | $target | FAILED | ❌ |" >> "$summary"
fi
total_suites=$((total_suites + 1))
elif [ "$rc" -ne 0 ]; then
echo "| \`$dir\` | $target | make failed | ❌ |" >> "$summary"
fi
done < <(find . -name Makefile -not -path '*/node_modules/*' | sort)
{
echo ""
if [ "$overall" -eq 0 ]; then
echo "**Total: $total_tests tests across $total_suites suites — ✅ all passed**"
else
echo "**Total: $total_tests tests across $total_suites suites — ❌ failures above**"
fi
echo ""
echo "<details><summary>▶ 本機重現指令</summary>"
echo ""
echo '```bash'
echo "make -C 1_Array_String test # two pointers C++"
echo "make -C dsa/linked_list run # linked list demo (smoke)"
echo "make -C google_dsa test # 全部 24 套件 (C++ + Python)"
echo "make -C google_dsa test-cpp # 只 C++"
echo "make -C google_dsa test-py # 只 Python"
echo "# 單一套件範例:"
echo "g++ -std=c++17 -Wall -Wextra -o google_dsa/09_heap/k_largest google_dsa/09_heap/k_largest.cpp && ./google_dsa/09_heap/k_largest"
echo "( cd google_dsa/09_heap && uv run python test_k_largest.py )"
echo '```'
echo ""
echo "> 展開任一 job step 的 log group(依資料夾折疊),每個套件上方的 \`\$ …\` 就是實際執行的指令。"
echo "</details>"
} >> "$summary"
if [ "$found" -eq 0 ]; then echo "No Makefile found" >&2; exit 1; fi
exit $overall