cf71134b75
CI Feature / Load example-gitea-env.conf to pipeline env (push) Successful in 18s
acc-tests Link to Cucumber reports
CI Feature / Cucumber tests (push) Successful in 1m15s
unit-tests Link to Bats reports
CI Feature / Bats tests (push) Successful in 1m30s
CI Feature / Report Summary (push) Successful in 5s
53 lines
2.3 KiB
Bash
Executable File
53 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
COVERAGE_VOLUME="${2:+${1:-}}"
|
|
REPORT_DIR="${2:-${1:-}}"
|
|
|
|
[ -n "$REPORT_DIR" ] || { echo "ERROR: report directory required" >&2; exit 1; }
|
|
|
|
COVERAGE_DIR="$REPORT_DIR/coverage"
|
|
|
|
if [ -n "$COVERAGE_VOLUME" ]; then
|
|
echo "DEBUG[bats-coverage]: OLD convention — extracting from volume '$1' to '$REPORT_DIR'" >&2
|
|
if docker run --rm -v "$COVERAGE_VOLUME":/data alpine sh -c '
|
|
[ -d /data/coverage ] && ls -A /data/coverage | grep -q .
|
|
' 2>/dev/null; then
|
|
echo "DEBUG[bats-coverage]: coverage found in volume $COVERAGE_VOLUME" >&2
|
|
mkdir -p "$COVERAGE_DIR"
|
|
docker run --rm -v "$COVERAGE_VOLUME":/data alpine tar c -C /data/coverage . | tar x -C "$COVERAGE_DIR"
|
|
echo "DEBUG[bats-coverage]: extracted from volume to $COVERAGE_DIR" >&2
|
|
else
|
|
echo "DEBUG[bats-coverage]: no coverage in volume $COVERAGE_VOLUME" >&2
|
|
fi
|
|
else
|
|
echo "DEBUG[bats-coverage]: NEW convention — copying from ./coverage/ to '$REPORT_DIR'" >&2
|
|
echo "DEBUG[bats-coverage]: coverage dir exists? $([ -d coverage ] && echo YES || echo NO)" >&2
|
|
if [ -d coverage ]; then
|
|
echo "DEBUG[bats-coverage]: files in coverage/: $(ls coverage/ 2>/dev/null | wc -l)" >&2
|
|
echo "DEBUG[bats-coverage]: coverage/index.html exists? $([ -f coverage/index.html ] && echo YES || echo NO)" >&2
|
|
mkdir -p "$COVERAGE_DIR"
|
|
cp -a coverage/. "$COVERAGE_DIR/"
|
|
echo "DEBUG[bats-coverage]: copied to $COVERAGE_DIR" >&2
|
|
fi
|
|
fi
|
|
|
|
echo "DEBUG[bats-coverage]: target $COVERAGE_DIR/index.html exists? $([ -f "$COVERAGE_DIR/index.html" ] && echo YES || echo NO)" >&2
|
|
|
|
if [ -d "$COVERAGE_DIR" ] && [ ! -f "$COVERAGE_DIR/index.html" ]; then
|
|
SHA8="${GITHUB_SHA:0:8}"
|
|
{
|
|
echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">'
|
|
echo "<title>Coverage report ${SHA8}</title>"
|
|
echo '<style>body{font-family:sans-serif;margin:2em}h1{color:#1e293b}ul{list-style:none;padding:0}li{margin:.5em 0}a{color:#2563eb}</style>'
|
|
echo "</head><body><h1>Coverage report <code>${SHA8}</code></h1><ul>"
|
|
while IFS= read -r -d '' f; do
|
|
base=$(basename "$f")
|
|
name="${base%.*}"
|
|
name="${name//-/ }"
|
|
echo "<li><a href=\"${base}\">${name^}</a></li>"
|
|
done < <(find "$COVERAGE_DIR" -maxdepth 1 -type f \( -name '*.html' -o -name '*.txt' \) ! -name index.html -print0 2>/dev/null || true)
|
|
echo '</ul></body></html>'
|
|
} > "$COVERAGE_DIR/index.html"
|
|
fi
|