|
| 1 | +#!/bin/zsh |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +if [[ -z "${STREAM_DEVICE_ID:-}" ]]; then |
| 6 | + typeset -a available_iphones |
| 7 | + available_iphones=("${(@f)$(xcrun devicectl list devices \ |
| 8 | + --filter "properties.hardware.reality = 'physical' AND properties.hardware.deviceType = 'iPhone' AND properties.connection.pairingState = 'paired' AND properties.state.bootState = 'booted'" \ |
| 9 | + --columns 'properties.hardware.udid' \ |
| 10 | + --hide-default-columns \ |
| 11 | + --hide-headers)}") |
| 12 | + if (( ${#available_iphones} != 1 )); then |
| 13 | + print -u2 "Expected one paired, unlocked physical iPhone; found ${#available_iphones}." |
| 14 | + print -u2 "Connect one device or run STREAM_DEVICE_ID=<UDID> bun stream." |
| 15 | + exit 1 |
| 16 | + fi |
| 17 | + STREAM_DEVICE_ID="${available_iphones[1]}" |
| 18 | +fi |
| 19 | +readonly STREAM_DEVICE_ID |
| 20 | +readonly STREAM_DESTINATION="platform=iOS,id=${STREAM_DEVICE_ID}" |
| 21 | +readonly STREAM_DERIVED_DATA_PATH="build/device" |
| 22 | +readonly STREAM_APP_PATH="${STREAM_DERIVED_DATA_PATH}/Build/Products/Debug-iphoneos/Stream.app" |
| 23 | +readonly STREAM_BUNDLE_ID="com.joeblau.Stream" |
| 24 | + |
| 25 | +if ! xcrun devicectl list devices \ |
| 26 | + --filter "properties.hardware.udid = '${STREAM_DEVICE_ID}' AND properties.hardware.reality = 'physical' AND properties.hardware.deviceType = 'iPhone' AND properties.connection.pairingState = 'paired' AND properties.state.bootState = 'booted'" \ |
| 27 | + --columns 'properties.hardware.udid' \ |
| 28 | + --hide-default-columns \ |
| 29 | + --hide-headers | grep -Fqx "${STREAM_DEVICE_ID}"; then |
| 30 | + print -u2 "The selected iPhone is unavailable. Unlock it and connect it to this Mac, then try again." |
| 31 | + exit 1 |
| 32 | +fi |
| 33 | + |
| 34 | +print "Building Stream for ${STREAM_DEVICE_ID}..." |
| 35 | +xcodebuild \ |
| 36 | + -project Stream.xcodeproj \ |
| 37 | + -scheme Stream \ |
| 38 | + -configuration Debug \ |
| 39 | + -destination "${STREAM_DESTINATION}" \ |
| 40 | + -derivedDataPath "${STREAM_DERIVED_DATA_PATH}" \ |
| 41 | + -allowProvisioningUpdates \ |
| 42 | + build |
| 43 | + |
| 44 | +if [[ ! -d "${STREAM_APP_PATH}" ]]; then |
| 45 | + print -u2 "Build succeeded, but ${STREAM_APP_PATH} was not found." |
| 46 | + exit 1 |
| 47 | +fi |
| 48 | + |
| 49 | +print "Installing Stream..." |
| 50 | +xcrun devicectl device install app \ |
| 51 | + --device "${STREAM_DEVICE_ID}" \ |
| 52 | + "${STREAM_APP_PATH}" |
| 53 | + |
| 54 | +print "Launching Stream..." |
| 55 | +xcrun devicectl device process launch \ |
| 56 | + --device "${STREAM_DEVICE_ID}" \ |
| 57 | + --terminate-existing \ |
| 58 | + "${STREAM_BUNDLE_ID}" |
0 commit comments