#!/bin/bash set -euo pipefail APP_NAME="OrionToolbar" SCHEME="OrionToolbar" PROJECT="OrionToolbar.xcodeproj" ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" BUILD_DIR="$ROOT_DIR/.build" LOG_DIR="$ROOT_DIR/build-logs" CONFIGURATION="Release" LAUNCH=false RUN_TESTS=true for arg in "$@"; do case "$arg" in --launch) LAUNCH=true ;; --no-tests) RUN_TESTS=false ;; *) echo "Unknown argument: $arg" echo "Usage: $0 [--launch] [--no-tests]" exit 2 ;; esac done mkdir -p "$BUILD_DIR" "$LOG_DIR" LOG_FILE="$LOG_DIR/build-test-$(date +%Y%m%d-%H%M%S).log" exec > >(tee -a "$LOG_FILE") 2>&1 echo echo "============================================================" echo " ORION TOOLBAR - RELEASE BUILD AND TEST" echo "============================================================" echo cd "$ROOT_DIR" echo "==> Environment" xcodebuild -version swift --version echo echo "==> Checking project" test -d "$PROJECT" || { echo "ERROR: Xcode project not found." exit 1 } echo echo "==> Checking Parallels" PRLCTL="" for candidate in \ /usr/local/bin/prlctl \ "/Applications/Parallels Desktop.app/Contents/MacOS/prlctl" do if [ -x "$candidate" ]; then PRLCTL="$candidate" break fi done if [ -n "$PRLCTL" ]; then echo "Parallels CLI: $PRLCTL" echo echo "==> Discovering virtual machines" "$PRLCTL" list -a -j | python3 -c ' import json import sys machines = json.load(sys.stdin) print(f"Discovered {len(machines)} virtual machines") print() for machine in machines: print( f"{machine.get('name', 'Unknown'):<35} " f"{machine.get('status', 'unknown'):<12} " f"{machine.get('uuid', '')}" ) ' else echo "WARNING: Parallels CLI not found." fi echo echo "==> Building Release configuration" xcodebuild \ -project "$PROJECT" \ -scheme "$SCHEME" \ -configuration "$CONFIGURATION" \ -destination "generic/platform=macOS" \ -derivedDataPath "$BUILD_DIR" \ CODE_SIGNING_ALLOWED=NO \ clean build APP_PATH="$BUILD_DIR/Build/Products/$CONFIGURATION/$APP_NAME.app" if [ ! -d "$APP_PATH" ]; then echo "ERROR: Built application not found." exit 1 fi echo echo "==> Validating application bundle" plutil -lint "$APP_PATH/Contents/Info.plist" echo echo "==> Application information" defaults read "$APP_PATH/Contents/Info" \ CFBundleIdentifier || true defaults read "$APP_PATH/Contents/Info" \ CFBundleShortVersionString || true defaults read "$APP_PATH/Contents/Info" \ CFBundleVersion || true echo echo "==> Checking executable" EXECUTABLE=$( /usr/libexec/PlistBuddy \ -c "Print CFBundleExecutable" \ "$APP_PATH/Contents/Info.plist" ) test -x "$APP_PATH/Contents/MacOS/$EXECUTABLE" file "$APP_PATH/Contents/MacOS/$EXECUTABLE" echo echo "==> Checking available test targets" if [ "$RUN_TESTS" = true ]; then TEST_OUTPUT="$LOG_DIR/test-targets.txt" xcodebuild \ -list \ -project "$PROJECT" > "$TEST_OUTPUT" if grep -Eq '^[[:space:]]+.*Tests$' "$TEST_OUTPUT"; then echo "Test targets detected." xcodebuild \ -project "$PROJECT" \ -scheme "$SCHEME" \ -configuration "$CONFIGURATION" \ -destination "platform=macOS" \ -derivedDataPath "$BUILD_DIR" \ CODE_SIGNING_ALLOWED=NO \ test else echo "No test targets detected; skipping XCTest." fi fi echo echo "==> Build size" du -sh "$APP_PATH" if [ "$LAUNCH" = true ]; then echo echo "==> Launching OrionToolbar" open "$APP_PATH" fi echo echo "============================================================" echo " BUILD AND TEST COMPLETE" echo "============================================================" echo echo "Application:" echo "$APP_PATH" echo echo "Log:" echo "$LOG_FILE" echo