|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +readonly DISTRO_SLUG="${1:?distribution slug is required}" |
| 5 | +readonly ARTIFACT_DIR="${2:?artifact directory is required}" |
| 6 | + |
| 7 | +case "$DISTRO_SLUG" in |
| 8 | + ubuntu-22.04|omarchy-4.0.3) ;; |
| 9 | + *) |
| 10 | + echo "Unsupported distribution slug: $DISTRO_SLUG" >&2 |
| 11 | + exit 1 |
| 12 | + ;; |
| 13 | +esac |
| 14 | + |
| 15 | +if [[ -z "${PAGES_TOKEN:-}" || -z "${GITHUB_REPOSITORY:-}" || |
| 16 | + -z "${GITHUB_RUN_ID:-}" ]]; then |
| 17 | + echo "GitHub Pages publishing environment is incomplete" >&2 |
| 18 | + exit 1 |
| 19 | +fi |
| 20 | + |
| 21 | +report="$(find "$ARTIFACT_DIR" -type f -name '*.html' -print -quit 2>/dev/null || true)" |
| 22 | +if [[ -z "$report" ]]; then |
| 23 | + echo "### Midscene HTML report" >> "$GITHUB_STEP_SUMMARY" |
| 24 | + echo "No HTML report was generated for this run." >> "$GITHUB_STEP_SUMMARY" |
| 25 | + exit 0 |
| 26 | +fi |
| 27 | + |
| 28 | +site_dir="$(mktemp -d)" |
| 29 | +trap 'rm -rf -- "$site_dir"' EXIT |
| 30 | +remote="https://x-access-token:${PAGES_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" |
| 31 | + |
| 32 | +if ! git clone --quiet --depth 1 --branch gh-pages "$remote" "$site_dir"; then |
| 33 | + rm -rf -- "$site_dir" |
| 34 | + mkdir -p "$site_dir" |
| 35 | + git -C "$site_dir" init --quiet --initial-branch=gh-pages |
| 36 | + git -C "$site_dir" remote add origin "$remote" |
| 37 | +fi |
| 38 | + |
| 39 | +runs_dir="$site_dir/midscene/$DISTRO_SLUG/runs" |
| 40 | +run_dir="$runs_dir/$GITHUB_RUN_ID" |
| 41 | +mkdir -p "$run_dir" |
| 42 | +cp "$report" "$run_dir/index.html" |
| 43 | +cp "$report" "$site_dir/midscene/$DISTRO_SLUG/index.html" |
| 44 | +touch "$site_dir/.nojekyll" |
| 45 | + |
| 46 | +# Keep exact links for the five newest runs of each distribution. The stable |
| 47 | +# distribution URL above always points to its latest report. |
| 48 | +while IFS= read -r old_run; do |
| 49 | + [[ "$old_run" =~ ^[0-9]+$ ]] || continue |
| 50 | + rm -rf -- "$runs_dir/$old_run" |
| 51 | +done < <(find "$runs_dir" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | |
| 52 | + sort -nr | tail -n +6) |
| 53 | + |
| 54 | +cat > "$site_dir/index.html" <<'EOF' |
| 55 | +<!doctype html> |
| 56 | +<html lang="en"> |
| 57 | + <head> |
| 58 | + <meta charset="utf-8"> |
| 59 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 60 | + <title>Doubao Say · Midscene E2E reports</title> |
| 61 | + </head> |
| 62 | + <body> |
| 63 | + <main> |
| 64 | + <h1>Doubao Say · Midscene E2E reports</h1> |
| 65 | + <p>These synthetic test reports and their screenshots are public.</p> |
| 66 | + <ul> |
| 67 | + <li><a href="midscene/ubuntu-22.04/">Ubuntu 22.04 · latest</a></li> |
| 68 | + <li><a href="midscene/omarchy-4.0.3/">Omarchy 4.0.3 · latest</a></li> |
| 69 | + </ul> |
| 70 | + </main> |
| 71 | + </body> |
| 72 | +</html> |
| 73 | +EOF |
| 74 | + |
| 75 | +git -C "$site_dir" config user.name "github-actions[bot]" |
| 76 | +git -C "$site_dir" config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 77 | +git -C "$site_dir" add --all |
| 78 | +git -C "$site_dir" commit --quiet -m "docs: publish $DISTRO_SLUG report for run $GITHUB_RUN_ID" |
| 79 | +git -C "$site_dir" push --quiet origin gh-pages |
| 80 | + |
| 81 | +repository_name="${GITHUB_REPOSITORY#*/}" |
| 82 | +report_url="https://${GITHUB_REPOSITORY_OWNER}.github.io/${repository_name}/midscene/${DISTRO_SLUG}/runs/${GITHUB_RUN_ID}/" |
| 83 | +{ |
| 84 | + echo "### Midscene HTML report" |
| 85 | + echo "[Open the interactive ${DISTRO_SLUG} report](${report_url})" |
| 86 | + echo |
| 87 | + echo "The report and its screenshots are publicly accessible through GitHub Pages." |
| 88 | +} >> "$GITHUB_STEP_SUMMARY" |
0 commit comments