summaryrefslogtreecommitdiff
path: root/docker/scripts/screenshots.sh
blob: 3fc52f5aaeb62ac056e67b6b7393894bf66d0595 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
# Author:  cirakg & claude ai
# Summary: Screenshot the app on each device in the headless simulator and compare with the approved golden images.
#
# Usage:   screenshots.sh DEVICE [DEVICE ...]      (APPROVE=1 saves new goldens)
# Output:  build/screenshots/<DEVICE>.png (the watch screen only), plus a
#          <DEVICE>-diff.png when it differs from test/golden/<DEVICE>.png.
set -euo pipefail
# shellcheck source=ciq-env.sh
source "$(dirname "${BASH_SOURCE[0]}")/ciq-env.sh"

# Pause after the first frame, so animations and late redraws settle.
readonly SETTLE_S=1

(($# > 0)) || die "usage: screenshots.sh DEVICE [DEVICE ...]"
ciq_require_sdk
ciq_require_key

for device in "$@"; do
  build-app.sh debug "${device}"
done

ciq_start_display
ciq_start_simulator

out="${BUILD_DIR}/screenshots"
mkdir -p "${out}"
approve=()
[[ "${APPROVE:-0}" == 1 ]] && approve=(--approve)
failed=0
for device in "$@"; do
  if ! ciq_launch_app "${device}" "${out}/${device}.log"; then
    ciq_stop_app
    log "no first frame on ${device}; see build/screenshots/${device}.log"
    failed=1
    continue
  fi
  sleep "${SETTLE_S}"
  mkdir -p "${out}/raw"
  import -window "$(ciq_simulator_window)" "${out}/raw/${device}-window.png"
  ciq_stop_app
  python3 /work/tools/sim_screenshot.py --raw "${out}/raw/${device}-window.png" \
    --device-dir "${CIQ_HOME}/Devices/${device}" --out "${out}/${device}.png" \
    --golden "/work/test/golden/${device}.png" "${approve[@]}" || failed=1
done

((failed == 0)) || die "screenshot checks failed; see build/screenshots/"
log "screenshots checked on: $*"