Files
gitea-ci-library/.gitea/scripts/bats-report.sh
T
moilanik 1770c3b1c3
CI / load-config (push) Successful in 13s
ci-bats Bats tests FAILED
ci-cucumber Cucumber tests passed
CI / feature (push) Failing after 1m24s
CI / main (push) Has been skipped
coverage report
2026-06-13 18:30:27 +03:00

37 lines
1.4 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
REPORT_DIR="${1:-reports/bats}"
INPUT="$REPORT_DIR/results.txt"
OUTPUT="$REPORT_DIR/test-report.html"
[ -f "$INPUT" ] || { echo "ERROR: $INPUT not found" >&2; exit 1; }
TOTAL=$(grep -cE '^(ok|not ok) ' "$INPUT" 2>/dev/null || echo 0)
PASS=$(grep -c '^ok ' "$INPUT" 2>/dev/null || echo 0)
FAIL=$((TOTAL - PASS))
{
echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">'
echo "<title>Bats test report ${GITHUB_SHA:0:8}</title>"
echo '<style>body{font-family:sans-serif;margin:2em;max-width:960px}'
echo 'h1{color:#1e293b}.pass{color:#059669}.fail{color:#dc2626}'
echo 'table{width:100%;border-collapse:collapse;margin-top:1em}'
echo 'th,td{border:1px solid #e2e8f0;padding:8px;text-align:left}'
echo 'th{background:#f8fafc}</style></head><body>'
echo "<h1>Bats test report <code>${GITHUB_SHA:0:8}</code></h1>"
echo "<p>Total: ${TOTAL} | Passed: <span class='pass'>${PASS}</span> | Failed: <span class='fail'>${FAIL}</span></p>"
echo '<table><tr><th>#</th><th>Status</th><th>Test</th></tr>'
while IFS=' ' read -r status num rest; do
case "$status" in
ok) echo "<tr><td>${num}</td><td class='pass'>PASS</td><td>${rest}</td></tr>" ;;
not) echo "<tr><td>${num}</td><td class='fail'>FAIL</td><td>${rest}</td></tr>" ;;
esac
done < <(grep -E '^(ok|not ok) ' "$INPUT")
echo '</table></body></html>'
} > "$OUTPUT"
echo "$OUTPUT"