blob: 21cc54e32d5855f7fdb17b583eda771ce0059f46 (
plain) (
blame)
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
|
#!/bin/sh
set -eu
TLD="$(cat aux/tld.txt)"
. aux/lib.sh
usage() {
cat <<-'EOF'
Usage:
aux/ci/report.sh -n NAME -o OUTDIR
aux/ci/report.sh -h
EOF
}
help() {
cat <<-'EOF'
Options:
-n NAME the lowercase name of the project
-o OUTDIR directory where to write the files
-h, --help show this message
Generate static HTML files CI report from data stored in git
notes. The metadata about the CI runs are stored in the ref
"refs/notes/ci-data", in the format described by
"aux/ci/run.sh", and the raw logs are stored under the ref
"refs/notes/ci-logs".
Examples:
Generate report for project "myapp" in "public/ci/":
$ sh aux/ci/report.sh -n myapp -o public/ci
EOF
}
for flag in "$@"; do
case "$flag" in
--)
break
;;
--help)
usage
help
exit
;;
*)
;;
esac
done
while getopts 'n:o:h' flag; do
case "$flag" in
n)
NAME="$OPTARG"
;;
o)
OUTDIR="$OPTARG"
;;
h)
usage
help
exit
;;
*)
usage >&2
exit 2
;;
esac
done
shift $((OPTIND - 1))
eval "$(assert_arg "${NAME:-}" '-n NAME')"
eval "$(assert_arg "${OUTDIR:-}" '-o OUTDIR')"
PASS='✅'
FAIL='❌'
mkdir -p "$OUTDIR"/logs "$OUTDIR"/data
for c in $(git notes list | cut -d' ' -f2); do
DATA="$(git notes --ref=refs/notes/ci-data show "$c")"
FILENAME="$(echo "$DATA" | cut -d' ' -f2)"
echo "$DATA" > "$OUTDIR/data/$FILENAME"
git notes --ref=refs/notes/ci-logs show "$c" \
> "$OUTDIR/logs/$FILENAME"
done
{
cat <<-EOF
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="CI logs for $NAME" />
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
<title>$NAME - CI logs</title>
<style>
EOF
cat aux/workflow/style.css | sed 's|^| |'
cat <<-EOF
</style>
<style>
pre {
display: inline;
}
ol {
list-style-type: disc;
}
</style>
</head>
<body>
<main>
<h1>
CI logs for
<a href="https://$TLD/$NAME/en/">$NAME</a>
</h1>
<ol>
EOF
for f in $(find "$OUTDIR/data/" -type f | LANG=C.UTF-8 sort -r); do
DATA="$(cat "$f")"
STATUS="$(echo "$DATA" | cut -d\ -f1)"
FILENAME="$(echo "$DATA" | cut -d\ -f2)"
if [ "$STATUS" = 0 ]; then
STATUS_MARKER="$PASS"
else
STATUS_MARKER="$FAIL"
fi
cat <<-EOF
<li>
<a href="logs/$FILENAME">$STATUS_MARKER <pre>$FILENAME</pre></a>
</li>
EOF
done
cat <<-EOF
</ol>
</main>
</body>
</html>
EOF
} > "$OUTDIR"/index.html.tmp
mv "$OUTDIR"/index.html.tmp "$OUTDIR"/index.html
|