节点在线、应用在线、配置在线使用令牌查询
大石头 authored at 2021-12-16 19:49:30
1.84 KiB
Stardust
#!/usr/bin/env bash
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
PROJECT="$ROOT/StarAgent.iOS/StarAgent.iOS.csproj"
CONFIGURATION="${CONFIGURATION:-Release}"
RUNTIME="${RUNTIME:-iossimulator-arm64}"
BUNDLE_ID="com.newlife.staragent"
TIMEOUT="${TIMEOUT:-180}"
ARTIFACTS="$ROOT/Bin/Agent/mobile/ios/artifacts"

mkdir -p "$ARTIFACTS"

if [ "${SKIP_BUILD:-0}" != "1" ]; then
  dotnet build "$PROJECT" -c "$CONFIGURATION" -f net10.0-ios -p:RuntimeIdentifier="$RUNTIME" --nologo
fi

APP="$(find "$ROOT/Bin/Agent/mobile/ios" -maxdepth 5 -name "*.app" -print -quit)"
if [ -z "$APP" ]; then
  echo "iOS app bundle not found."
  exit 1
fi

UDID="$(xcrun simctl list devices available | awk -F '[()]' '/iPhone/ {print $2; exit}')"
if [ -z "$UDID" ]; then
  echo "No iPhone simulator available."
  exit 1
fi

echo "Using simulator $UDID"
xcrun simctl boot "$UDID" 2>/dev/null || true
xcrun simctl bootstatus "$UDID" -b
xcrun simctl install "$UDID" "$APP"
xcrun simctl terminate "$UDID" "$BUNDLE_ID" 2>/dev/null || true
xcrun simctl launch "$UDID" "$BUNDLE_ID" --smoke

RESULT=""
DEADLINE=$((SECONDS + TIMEOUT))
while [ "$SECONDS" -lt "$DEADLINE" ]; do
  DATA_DIR="$(xcrun simctl get_app_container "$UDID" "$BUNDLE_ID" data 2>/dev/null || true)"
  if [ -n "$DATA_DIR" ]; then
    RESULT="$(find "$DATA_DIR" -name agent-smoke.json -print -quit 2>/dev/null || true)"
    if [ -n "$RESULT" ]; then
      break
    fi
  fi
  sleep 2
done

if [ -z "$RESULT" ]; then
  echo "agent-smoke.json not found within ${TIMEOUT}s. Recent app log:"
  xcrun simctl spawn "$UDID" log show --last 2m --style compact --predicate 'process == "StarAgent.iOS"' || true
  exit 1
fi

cp "$RESULT" "$ARTIFACTS/ios-smoke.json"
cat "$RESULT"

if command -v jq >/dev/null 2>&1; then
  jq -e '.ok == true' "$RESULT" >/dev/null
else
  grep -q '"ok":true' "$RESULT"
fi

echo "iOS smoke passed."