listless

A simple list app for Apple platforms
Log | Files | Refs | README | LICENSE

screenshots-watch.sh (2412B)


      1 #!/bin/bash
      2 set -euo pipefail
      3 
      4 DO_COMPOSE=false
      5 while getopts "c" opt; do
      6   case $opt in
      7     c) DO_COMPOSE=true ;;
      8     *) ;;
      9   esac
     10 done
     11 shift $((OPTIND - 1))
     12 
     13 MAJOR="${1:-11}"
     14 RUNTIME=$(xcrun simctl list runtimes available \
     15   | grep "watchOS ${MAJOR}\." \
     16   | sed 's/.*watchOS \([0-9.]*\).*/\1/' \
     17   | sort -t. -k1,1n -k2,2n \
     18   | tail -1)
     19 
     20 if [ -z "$RUNTIME" ]; then
     21   echo "No available watchOS ${MAJOR}.x simulator runtime found." >&2
     22   exit 1
     23 fi
     24 
     25 DEVICE=$(xcrun simctl list devices available "watchOS ${RUNTIME}" \
     26   | grep "Apple Watch" \
     27   | head -1 \
     28   | sed 's/^ *\(.*\) ([A-F0-9-]*).*/\1/')
     29 
     30 if [ -z "$DEVICE" ]; then
     31   echo "No available Apple Watch simulator found for watchOS ${RUNTIME}." >&2
     32   exit 1
     33 fi
     34 
     35 echo "Using ${DEVICE}, watchOS ${RUNTIME}"
     36 
     37 # Boot simulator if needed
     38 UDID=$(xcrun simctl list devices available "watchOS ${RUNTIME}" \
     39   | grep "$DEVICE" \
     40   | head -1 \
     41   | sed 's/.*(\([A-F0-9-]*\)).*/\1/')
     42 
     43 xcrun simctl boot "$UDID" 2>/dev/null || true
     44 
     45 SCREENSHOT_TMP="/tmp/listless-screenshots"
     46 FRAMED_TMP="/tmp/listless-framed"
     47 MARKETING_DIR="$(pwd)/Marketing"
     48 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
     49 
     50 CAPTION="Get Up and Do"
     51 
     52 # Run screenshot tests (writes to SCREENSHOT_TMP)
     53 xcodebuild test \
     54   -scheme "Listless watchOS" \
     55   -destination "platform=watchOS Simulator,name=${DEVICE},OS=${RUNTIME}" \
     56   -only-testing:"Listless watchOS UI Tests/ListlessWatchScreenshots" \
     57   2>&1
     58 
     59 if ! ls "${SCREENSHOT_TMP}"/*.png 1>/dev/null 2>&1; then
     60   echo "No screenshots found in ${SCREENSHOT_TMP}."
     61   exit 1
     62 fi
     63 
     64 mkdir -p "${MARKETING_DIR}"
     65 
     66 if [ "$DO_COMPOSE" = true ]; then
     67   mkdir -p "${FRAMED_TMP}"
     68 
     69   echo ""
     70   echo "Framing screenshot..."
     71   file="${SCREENSHOT_TMP}/01-items.png"
     72   shortcuts run "Frame Screenshots" -i "$file" -o "${FRAMED_TMP}/framed_0.png"
     73   echo "  Framed screenshot"
     74 
     75   echo "Composing final image..."
     76   swift "${SCRIPT_DIR}/screenshots-ios-compose.swift" "${FRAMED_TMP}/framed_0.png" "${MARKETING_DIR}/watch_0.png" "$CAPTION" 422 514
     77   echo "  watch_0.png — ${CAPTION}"
     78 
     79   rm -rf "${FRAMED_TMP}"
     80 else
     81   OUTPUT_DIR="$(pwd)"
     82   echo ""
     83   cp "${SCREENSHOT_TMP}/01-items.png" "${OUTPUT_DIR}/watch_0.png"
     84 fi
     85 
     86 rm -rf "${SCREENSHOT_TMP}"
     87 
     88 if [ "$DO_COMPOSE" = true ]; then
     89   echo ""
     90   echo "Screenshots saved to ${MARKETING_DIR}/"
     91   ls -la "${MARKETING_DIR}"/watch_*.png
     92 else
     93   echo ""
     94   echo "Screenshots saved to ${OUTPUT_DIR}/"
     95   ls -la "${OUTPUT_DIR}"/watch_*.png
     96 fi