#!/usr/bin/env bash set -euo pipefail DESCRIPTION="${1:-}" CONTEXT="${2:-}" SUITE="${3:-}" [ -n "$DESCRIPTION" ] || { echo "ERROR: description argument required" >&2; exit 1; } [ -n "$CONTEXT" ] || { echo "ERROR: context argument required" >&2; exit 1; } [ -n "$SUITE" ] || { echo "ERROR: suite argument required" >&2; exit 1; } REPORT_DIR="reports/${SUITE}" if [ ! -d "$REPORT_DIR" ]; then echo "ERROR: $REPORT_DIR not found" >&2 bash .ci/scripts/report-status.sh failure "$DESCRIPTION" "$CONTEXT" exit 1 fi cd "$REPORT_DIR" FILES=() while IFS= read -r -d '' f; do FILES+=("$(basename "$f")") done < <(find . -maxdepth 1 -type f ! -name index.html -print0 2>/dev/null || true) SUBDIRS=() while IFS= read -r -d '' d; do name="${d#./}" [ -f "$name/index.html" ] && SUBDIRS+=("$name") done < <(find . -maxdepth 1 -type d ! -name . -print0 2>/dev/null || true) TOTAL=$(( ${#FILES[@]} + ${#SUBDIRS[@]} )) if [ "$TOTAL" -eq 0 ]; then echo "ERROR: no reportable items in $REPORT_DIR" >&2 bash .ci/scripts/report-status.sh failure "$DESCRIPTION" "$CONTEXT" exit 1 fi SHA8="${GITHUB_SHA:0:8}" humanize() { local name="$1" name="${name%.*}" name="${name//-/ }" name="${name//_/ }" echo "${name^}" } generate_index() { local html html='' html+="$DESCRIPTION" html+='' html+="

$DESCRIPTION

' printf '%s' "$html" > index.html } cd - > /dev/null # Stage reports for backward-compatible publish STAGED="reports/${SHA8}/${SUITE}" mkdir -p "$STAGED" cp -a "$REPORT_DIR/." "$STAGED/" if [ "$TOTAL" -eq 1 ]; then if [ ${#FILES[@]} -eq 1 ]; then ENTRY="${FILES[0]}" else ENTRY="${SUBDIRS[0]}/index.html" fi bash .ci/scripts/publish-git-pages.sh "$SUITE" URL="${GIT_PAGES_URL}/${GITHUB_REPOSITORY}/reports/${SHA8}/${SUITE}/${ENTRY}" bash .ci/scripts/report-status.sh success "$DESCRIPTION" "$CONTEXT" "" "$URL" else bash .ci/scripts/publish-git-pages.sh "$SUITE" bash .ci/scripts/report-status.sh success "$DESCRIPTION" "$CONTEXT" "$SUITE" fi rm -rf "$STAGED"