-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathci-summary.sh
More file actions
executable file
·103 lines (94 loc) · 2.98 KB
/
ci-summary.sh
File metadata and controls
executable file
·103 lines (94 loc) · 2.98 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
#!/bin/sh
#
# scripts/ci/ci-summary.sh
#
# Wrapped awk script that reads the test record file and emits a markdown
# summary to stdout, intended for piping into $GITHUB_STEP_SUMMARY.
#
set -eu
file=${1:-${CI_TEST_RECORD_FILE:-build/tests/results.tsv}}
if [ ! -s "$file" ]; then
echo "## Test results"
echo
echo "_No results recorded._"
exit 0
fi
awk -F'\t' '
{
key = $1 "\t" $2
cat[key] = $1
name[key] = $2
status[key] = $3
logf[key] = $4
seen[key] = NR # last-wins
}
END {
# Per-category counts
for (k in seen) {
c = cat[k]
cats[c] = 1
if (status[k] == "PASS") { cat_pass[c]++; total_pass++ }
else if (status[k] == "FAIL") { cat_fail[c]++; total_fail++ }
total++
}
# Header
printf("## Test results\n\n")
if (total_fail > 0) {
printf("**%d / %d passed** (%d failed)\n\n", total_pass, total, total_fail)
} else {
printf("**%d / %d passed**\n\n", total_pass, total)
}
# Failure logs as collapsible blocks
if (total_fail > 0) {
printf("### Failure logs (last 20 lines)\n\n")
for (k in seen) {
if (status[k] != "FAIL") continue
printf("<details><summary><code>%s/%s</code> — <code>%s</code></summary>\n\n",
cat[k], name[k], (logf[k] != "" ? logf[k] : "(no log captured)"))
if (logf[k] != "") {
printf("```\n")
n = 0
while ((getline line < logf[k]) > 0) buf[++n % 20] = line
close(logf[k])
start = (n < 20) ? 1 : n - 19
for (j = start; j <= n; j++) print buf[j % 20]
delete buf
printf("```\n")
} else {
printf("_No log file recorded._\n")
}
printf("\n</details>\n\n")
}
printf("---\n\n")
}
# Per-category sections. Categories with failures float to the top
# via a single insertion sort; otherwise alphabetical.
n = 0
for (c in cats) ordered[++n] = c
for (i = 2; i <= n; i++) {
cur = ordered[i]; j = i - 1
while (j >= 1) {
a = ordered[j]; b = cur
af = (cat_fail[a] ? 0 : 1); bf = (cat_fail[b] ? 0 : 1)
if (af < bf || (af == bf && a < b)) break
ordered[j+1] = ordered[j]; j--
}
ordered[j+1] = cur
}
for (i = 1; i <= n; i++) {
c = ordered[i]
cp = cat_pass[c] + 0; cf = cat_fail[c] + 0
ct = cp + cf
if (cf > 0) printf("### %s (%d/%d, %d failed)\n\n", c, cp, ct, cf)
else printf("### %s (%d/%d)\n\n", c, cp, ct)
printf("| Test | Status |\n|---|---|\n")
# FAIL rows first, then PASS, each in test-execution order.
for (k in seen) if (cat[k] == c && status[k] == "FAIL") emit(k)
for (k in seen) if (cat[k] == c && status[k] == "PASS") emit(k)
printf("\n")
}
}
function emit(k) {
printf("| `%s` | %s |\n", name[k], status[k])
}
' "$file"