#!/bin/sh # Docs' screenshot gate (rastrillo/native RastrilloSnapshots): the library, # Oficina ID onboarding, Other ways to sign in, the team picker and Settings, # light and dark, and on iPhone at the default size and AX3; and the editor's # page from fixed fixtures (EditorSnapshots.swift: Mac paged and pageless at # 100% and 150%, iPhone and iPad width, page breaks, a scripted edit, ar, ru). # # native/scripts/snapshots.sh [compare|record] [mac|iphone|all] # # compare (the default) fails on any changed, missing or stale picture; # record redraws the baselines in apple/Tests/DocsSnapshots/__Snapshots__/docs*. # Review the contact sheets, apple/.build/snapshots/docs*/index.html, before # committing a recording. Push baselines one commit per push, with # `git -c http.postBuffer=209715200 push`: without it the hub drops a pack # over about 1 MB ("unexpected disconnect while reading sideband packet"), # and pushes back to back trip its per-IP limit. # # Both halves run even when the first fails, and each ends by printing the # environment it drew on beside the one its baselines were drawn on. A # change there is drift, not a regression: see BUILDING.md, "The # screenshot gate", before re-recording anything. # # A screen that hangs the main thread never reaches the kit's own 3 s # limit, so each half has a wall clock: SNAPSHOT_MAC_LIMIT seconds (default # 300) for the Mac test run, after its build; and XCTest's execution time # allowance, 120 s a test, for the iPhone half. # # Not in .amadan/ci.d: baselines are exact only on the OS and simulator # runtime that drew them (ENVIRONMENT beside them says which). The runner # scripts are rastrillo/native's own, from the pinned checkout; the iPhone # half runs on its "Rastrillo Snapshots" simulator under its lock. set -eu cd "$(dirname "$0")/.." mode=${1:-compare} platforms=${2:-all} case "$mode" in compare|record) ;; *) echo "usage: $0 [compare|record] [mac|iphone|all]" >&2; exit 2 ;; esac case "$platforms" in mac|iphone|all) ;; *) echo "usage: $0 [compare|record] [mac|iphone|all]" >&2; exit 2 ;; esac if [ "${OFICINA_SKIP_PREPARE:-0}" != 1 ]; then scripts/build-crdt.sh; fi swift package --package-path apple resolve shared=${OFICINA_NATIVE_PACKAGE_PATH:-apple/.build/checkouts/native} case "$shared" in /*) ;; *) shared="$(pwd)/$shared" ;; esac tools="$shared/tools" # Stops a process and everything under it. kill_tree() { for child in $(pgrep -P "$1" 2>/dev/null); do kill_tree "$child"; done kill -TERM "$1" 2>/dev/null || true } # Runs the rest of the line, stopping it after $1 seconds. with_limit() { limit=$1 shift "$@" & pid=$! ( sleep "$limit" echo "the snapshot run passed its ${limit} s limit: a screen hung the main thread; stopping it" >&2 kill_tree "$pid" ) & watchdog=$! set +e wait "$pid" status=$? set -e kill_tree "$watchdog" return "$status" } # What each catalog's run drew on, and what its baselines were drawn on. print_environment() { python3 - "$1" <<'EOF' import json, pathlib, sys platform = sys.argv[1] shown = None for results in sorted(pathlib.Path("apple/.build/snapshots").glob(f"*/{platform}/results.json")): run = json.loads(results.read_text()) here = run.get("environment", "") if shown is None: print(f"{platform} half drawn on:") print(" " + here.replace("\n", "\n ")) shown = here recorded = run.get("baselineEnvironment") or "(none recorded)" if recorded == here: print(f" {run['app']}: baselines drawn on the same") else: print(f" {run['app']}: ENVIRONMENT DIFFERS from its baselines, drawn on:") print(" " + recorded.replace("\n", "\n ")) print(" Drift, not a regression: re-record from main in its own commit first (BUILDING.md).") EOF } failed=0 case "$platforms" in mac|all) (cd apple && swift build --build-tests) if ! (cd apple && with_limit "${SNAPSHOT_MAC_LIMIT:-300}" "$tools/snapshots-mac.sh" "$mode" DocsSnapshots); then failed=1; fi print_environment mac ;; esac case "$platforms" in iphone|all) xcodegen generate --spec ios/project.yml # Build products stay under apple/.build, beside the Mac half's. if ! (cd apple && SNAPSHOT_DERIVED_DATA=.build/xcode "$tools/snapshots-iphone.sh" "$mode" DocsPhoneSnapshots DocsPhoneSnapshots \ -project ../ios/DocsPhone.xcodeproj -test-timeouts-enabled YES -default-test-execution-time-allowance 120); then failed=1 grep -h "exceeded execution time allowance" apple/.build/snapshots-iphone.log || true fi print_environment iphone ;; esac exit "$failed"