#!/usr/bin/env bash # local_test.sh — 本地编译一份「指向线上后端」的 app 用于发版前自测。 # # 用法: # sh scripts/local_test.sh # 编译 macOS + 启动 # sh scripts/local_test.sh --no-open # 只编译 macOS 不启动 # sh scripts/local_test.sh --ios # 编译 iOS 并装到 USB iPhone(开发签名) # # 后端固定指向生产 https://jiu.51yanmei.com(与 CI compile 脚本一致)。 # 版本号 = 最新 client-v* tag 的 patch+1 加 -dev 后缀(如 v1.1.4-dev), # App 内显示走 APP_VERSION dart-define(update_provider.currentAppVersion), # 与 CI 同一读取链路——本地构建不再显示 pubspec 旧版本(2026-07-04 修复)。 set -euo pipefail export PATH="/opt/homebrew/bin:$PATH" REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "$REPO_ROOT" LATEST_TAG="$(git describe --tags --match 'client-v*' --abbrev=0 2>/dev/null || true)" if [ -n "$LATEST_TAG" ]; then BASE_VER="${LATEST_TAG#client-v}" MAJOR_MINOR="${BASE_VER%.*}" PATCH="${BASE_VER##*.}" VER="${MAJOR_MINOR}.$((PATCH + 1))-dev" else VER="0.0.0-dev" fi DEFINES=( "--dart-define=BASE_URL=https://jiu.51yanmei.com" "--dart-define=PUBLIC_URL=https://jiu.51yanmei.com" "--dart-define=APP_VERSION=v${VER}" ) if [ "${1:-}" = "--ios" ]; then # ── iOS:开发签名构建 + devicectl 装到 USB iPhone ── # Release 配置是 CI 的 Manual+App Store 签名,本机没有分发证书, # 故 xcodebuild 用 Automatic + Apple Development 覆盖(不改工程文件)。 echo "==> 编译 iOS(线上后端,版本 v${VER})" cd client flutter build ios --release --config-only "${DEFINES[@]}" cd ios CD_ID="$(xcrun devicectl list devices 2>/dev/null | grep 'available (paired)' | grep 'iPhone' | grep -oE '[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}' | head -1 || true)" if [ -z "$CD_ID" ]; then echo "!! 未检测到已配对 iPhone(插线并解锁后重试)" >&2 exit 1 fi xcodebuild -workspace Runner.xcworkspace -scheme Runner -configuration Release \ -destination "generic/platform=iOS" \ CODE_SIGN_STYLE=Automatic DEVELOPMENT_TEAM=BYL4KQHMTN \ CODE_SIGN_IDENTITY="Apple Development" PROVISIONING_PROFILE_SPECIFIER= \ -allowProvisioningUpdates -allowProvisioningDeviceRegistration build \ | grep -E "BUILD (SUCCEEDED|FAILED)" APP_PATH="$(find "$HOME/Library/Developer/Xcode/DerivedData" -path '*Release-iphoneos/Runner.app' -maxdepth 6 2>/dev/null | head -1)" if [ -z "$APP_PATH" ]; then echo "!! 找不到构建产物 Runner.app" >&2 exit 1 fi echo "==> 安装到 iPhone(${CD_ID})" xcrun devicectl device install app --device "$CD_ID" "$APP_PATH" | grep -m1 databaseSequenceNumber || true echo "==> 完成:解锁手机打开 岩美酒库(版本 v${VER})" exit 0 fi APP="client/build/macos/Build/Products/Release/jiu_client.app" echo "==> 编译 macOS app(线上后端,版本 v${VER})" cd client flutter build macos --release "${DEFINES[@]}" cd "$REPO_ROOT" echo "==> 产物:$APP" if [ "${1:-}" = "--no-open" ]; then echo "==> 跳过启动(--no-open)" else echo "==> 前台启动 app(终端附着日志,退出 app 才返回;Ctrl-C 可终止)" exec "$APP/Contents/MacOS/jiu_client" fi