Skip to content

Commit abfccfb

Browse files
committed
Produce Markdown test summary
1 parent f1a1168 commit abfccfb

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

script/cibuild

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,38 @@
22
# Usage: script/cibuild [--no-package]
33
set -e
44

5+
ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
6+
TMPDIR="$ROOTDIR/test/tmp"
7+
8+
# Remove possible remnants of previous test runs
9+
rm -rf "${TMPDIR:?}/*"
10+
11+
print_test_results() {
12+
if [ -n "$GITHUB_STEP_SUMMARY" ]; then
13+
echo -e "### Test results\n" >> "$GITHUB_STEP_SUMMARY"
14+
echo "| Test suite | Result | Successful | Failed | Skipped | Duration |" >> "$GITHUB_STEP_SUMMARY"
15+
echo "|---|---|--:|--:|--:|--:|" >> "$GITHUB_STEP_SUMMARY"
16+
sort -V "$TMPDIR/results" >> "$GITHUB_STEP_SUMMARY"
17+
fi
18+
}
19+
520
# Enable verbose logging of ssh commands
621
export GHE_VERBOSE_SSH=true
722

823
if ! find test -name "test-*.sh" -print0 | xargs -0 -n 1 /bin/bash; then
24+
print_test_results
925
exit 1
1026
fi
1127

28+
print_test_results
29+
1230
# Bail out when --no-package given
1331
[ "$1" = "--no-package" ] && exit 0
1432

1533
# files we'll md5sum at the end
1634
pkg_files=
1735

1836
# Build the tarball
19-
ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
20-
TMPDIR="$ROOTDIR/test/tmp"
21-
2237
echo "Building tar.gz package ..."
2338
if script/package-tarball 1>$TMPDIR/package-tarball.txt 2>&1; then
2439
pkg_files=$(grep '^Package ' < $TMPDIR/package-tarball.txt | cut -f 2 -d ' ')

test/testlib.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ TRASHDIR="$TMPDIR/$(basename "$0")-$$"
3232

3333
test_suite_file_name="$(basename "${BASH_SOURCE[1]}")"
3434
test_suite_name="${GHE_TEST_SUITE_NAME:-${test_suite_file_name%.*}}"
35+
results_file="$TMPDIR/results"
36+
test_suite_before_time=$(date '+%s.%3N')
3537

3638
# Set GIT_{AUTHOR,COMMITTER}_{NAME,EMAIL}
3739
# This removes the assumption that a git config that specifies these is present.
@@ -85,6 +87,27 @@ failures=0
8587
atexit () {
8688
res=$?
8789

90+
test_suite_after_time=$(date '+%s.%3N')
91+
test_suite_elapsed_time=$(echo "scale=3; $test_suite_after_time - $test_suite_before_time" | bc)
92+
93+
# Temporarily redirect stdout output to results file
94+
exec 3<&1
95+
exec 1>>"$results_file"
96+
97+
# Print test summary for this test suite
98+
echo -n "| $test_suite_name | "
99+
100+
if [ "$failures" -eq "0" ]; then
101+
echo -n ":green_circle: passed"
102+
else
103+
echo -n ":red_circle: failed"
104+
fi
105+
106+
printf " | $successes | $failures | $skipped | %.3f s |\\n" "$test_suite_elapsed_time"
107+
108+
# Restore stdout
109+
exec 1<&3
110+
88111
[ -z "$KEEPTRASH" ] && rm -rf "$TRASHDIR"
89112
if [ $failures -gt 0 ]; then
90113
exit 1

0 commit comments

Comments
 (0)