#!/usr/bin/env bash set -euo pipefail SUITE_PATH="${1:-}" [ -n "$SUITE_PATH" ] || { echo "ERROR: suite_path argument required" >&2; exit 1; } [ -n "${GITEA_API_URL:-}" ] || { echo "ERROR: GITEA_API_URL is not set" >&2; exit 1; } [ -n "${GIT_PAGES_URL:-}" ] || { echo "ERROR: GIT_PAGES_URL is not set" >&2; exit 1; } [ -n "${GIT_PAGES_PUBLISH_TOKEN:-}" ] || { echo "ERROR: GIT_PAGES_PUBLISH_TOKEN is not set" >&2; exit 1; } [ -n "${GITHUB_REPOSITORY:-}" ] || { echo "ERROR: GITHUB_REPOSITORY is not set" >&2; exit 1; } [ -n "${GITHUB_SHA:-}" ] || { echo "ERROR: GITHUB_SHA is not set" >&2; exit 1; } OWNER="${GITHUB_REPOSITORY%%/*}" REPO="${GITHUB_REPOSITORY##*/}" SHA8="${GITHUB_SHA:0:8}" PAGES_USER="${GIT_PAGES_PUBLISH_USER:-publish}" REPORT_DIR="reports/${SHA8}/${SUITE_PATH%/}" REPORT_BASE="${GIT_PAGES_URL}/${OWNER}/${REPO}/reports/${SHA8}" [ -d "$REPORT_DIR" ] || { echo "ERROR: not a directory: $REPORT_DIR" >&2; exit 1; } PUBLISH_SITE_URL="${GIT_PAGES_URL}/" WORK=$(mktemp -d) TAR=$(mktemp) trap 'rm -rf "$WORK" "$TAR"' EXIT RELPATH="${REPORT_DIR#reports/${SHA8}/}" if [ "$RELPATH" != "$REPORT_DIR" ] && [ -n "$RELPATH" ]; then TARGET="$WORK/${OWNER}/${REPO}/reports/${SHA8}/${RELPATH}" else TARGET="$WORK/${OWNER}/${REPO}/reports/${SHA8}" fi mkdir -p "$TARGET" cp -a "$REPORT_DIR/." "$TARGET/" if [ ! -f "$TARGET/index.html" ]; then items=() while IFS= read -r -d '' f; do items+=("$(basename "$f")") done < <(find "$TARGET" -maxdepth 1 -type f ! -name index.html -print0 2>/dev/null || true) while IFS= read -r -d '' d; do name=$(basename "$d") [ -f "$d/index.html" ] && items+=("$name") done < <(find "$TARGET" -maxdepth 1 -type d ! -name . -print0 2>/dev/null || true) if [ ${#items[@]} -gt 1 ]; then { echo '' echo "Test report ${SHA8}" echo '' echo "

Test report ${SHA8}

' } > "$TARGET/index.html" fi fi cat > "$TARGET/.meta" <&2 cat /tmp/git-pages-publish-response.txt >&2 exit 1 ;; esac echo "$REPORT_BASE"