diff --git a/.gitea/scripts/bats-coverage.sh b/.gitea/scripts/bats-coverage.sh index 817aef1..5d3652c 100755 --- a/.gitea/scripts/bats-coverage.sh +++ b/.gitea/scripts/bats-coverage.sh @@ -7,8 +7,12 @@ REPORT_DIR="${2:-}" [ -n "$COVERAGE_VOLUME" ] || { echo "ERROR: coverage volume name required" >&2; exit 1; } [ -n "$REPORT_DIR" ] || { echo "ERROR: report directory required" >&2; exit 1; } -mkdir -p "$REPORT_DIR/coverage" -docker run --rm -v "$COVERAGE_VOLUME":/coverage alpine tar c -C /coverage . | tar x -C "$REPORT_DIR/coverage" +HAS_COVERAGE=false +if docker run --rm -v "$COVERAGE_VOLUME":/coverage alpine sh -c '[ -d /coverage ] && ls -A /coverage | grep -q .' 2>/dev/null; then + mkdir -p "$REPORT_DIR/coverage" + docker run --rm -v "$COVERAGE_VOLUME":/coverage alpine tar c -C /coverage . | tar x -C "$REPORT_DIR/coverage" + HAS_COVERAGE=true +fi cat > "$REPORT_DIR/index.html" << EOF @@ -19,7 +23,10 @@ h1{color:#1e293b}a{color:#2563eb;text-decoration:none}a:hover{text-decoration:un

Bats report ${GITHUB_SHA:0:8}

- EOF + +if [ "$HAS_COVERAGE" = true ]; then + echo '
  • Coverage report
  • ' >> "$REPORT_DIR/index.html" +fi + +echo '' >> "$REPORT_DIR/index.html" diff --git a/.gitea/scripts/bats-report.sh b/.gitea/scripts/bats-report.sh index d287350..e10e178 100644 --- a/.gitea/scripts/bats-report.sh +++ b/.gitea/scripts/bats-report.sh @@ -7,8 +7,8 @@ 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) +TOTAL=$(grep -cE '^(ok|not ok) ' "$INPUT" 2>/dev/null) || TOTAL=0 +PASS=$(grep -c '^ok ' "$INPUT" 2>/dev/null) || PASS=0 FAIL=$((TOTAL - PASS)) { diff --git a/.gitea/workflows/build-feature.yml b/.gitea/workflows/build-feature.yml index 224d8a6..12b0f51 100644 --- a/.gitea/workflows/build-feature.yml +++ b/.gitea/workflows/build-feature.yml @@ -59,8 +59,12 @@ jobs: -v bats-workspace:/data \ -v bats-coverage:/coverage \ --entrypoint bash ${{ inputs.bats-image }} \ - -c 'apk add -q lsof python3 jq curl kcov && \ - cd /data && kcov --include-path=/data/scripts/ /coverage/ bats tests/' \ + -c 'apk add -q lsof python3 jq curl && \ + if apk add -q kcov 2>/dev/null; then \ + kcov --include-path=/data/scripts/ /coverage/ bats tests/; \ + else \ + echo "kcov not available, skipping coverage" >&2 && bats tests/; \ + fi' \ > "reports/${GITHUB_SHA:0:8}/bats/results.txt" 2>&1 BATS_EXIT=$? bash .ci/.gitea/scripts/bats-coverage.sh bats-coverage "reports/${GITHUB_SHA:0:8}/bats"