|
| 1 | +name: iOS Expo Build and Test |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: read |
| 5 | + actions: read |
| 6 | + |
| 7 | +# Complete workflow using deploy-ios.sh to build fresh with Expo and run tests |
| 8 | +# This workflow demonstrates building from source using Expo, deploying to simulator, and testing |
| 9 | + |
| 10 | +on: |
| 11 | + # Manual trigger with customization options |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + client_id: |
| 15 | + description: 'Auth0 Client ID for test environment' |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + build_mode: |
| 19 | + description: 'Build configuration' |
| 20 | + required: false |
| 21 | + type: choice |
| 22 | + options: |
| 23 | + - debug |
| 24 | + - release |
| 25 | + default: 'debug' |
| 26 | + ios_version: |
| 27 | + description: 'iOS platform version for simulator' |
| 28 | + required: false |
| 29 | + type: string |
| 30 | + default: '26.0' |
| 31 | + device_name: |
| 32 | + description: 'iOS simulator device name' |
| 33 | + required: false |
| 34 | + type: string |
| 35 | + default: 'iPhone 16' |
| 36 | + run_tests: |
| 37 | + description: 'Run Appium tests after deployment' |
| 38 | + required: false |
| 39 | + type: boolean |
| 40 | + default: true |
| 41 | + show_logs: |
| 42 | + description: 'Show app logs during deployment' |
| 43 | + required: false |
| 44 | + type: boolean |
| 45 | + default: false |
| 46 | + |
| 47 | +jobs: |
| 48 | + expo-build-and-test-ios: |
| 49 | + name: Expo Build and Test iOS App |
| 50 | + runs-on: macos-latest |
| 51 | + timeout-minutes: 90 |
| 52 | + |
| 53 | + steps: |
| 54 | + - name: Checkout code |
| 55 | + uses: actions/checkout@v4 |
| 56 | + |
| 57 | + - name: Setup Node.js |
| 58 | + uses: actions/setup-node@v4 |
| 59 | + with: |
| 60 | + node-version: '20' |
| 61 | + cache: 'npm' |
| 62 | + cache-dependency-path: 'app/package-lock.json' |
| 63 | + |
| 64 | + - name: Install Node.js dependencies |
| 65 | + working-directory: ./app |
| 66 | + run: npm ci |
| 67 | + |
| 68 | + # Deploy fresh app using the deploy-ios.sh script |
| 69 | + - name: Expo Build and Deploy iOS App |
| 70 | + id: expo-deploy-ios |
| 71 | + run: | |
| 72 | + echo "🚀 Starting iOS Expo build and deployment using deploy-ios.sh..." |
| 73 | + |
| 74 | + # Set deployment parameters |
| 75 | + DEPLOY_ARGS="" |
| 76 | + DEPLOY_ARGS="$DEPLOY_ARGS --client-id '${{ inputs.client_id }}'" |
| 77 | + DEPLOY_ARGS="$DEPLOY_ARGS --simulator '${{ inputs.device_name || 'iPhone 16' }}'" |
| 78 | + |
| 79 | + if [ "${{ inputs.build_mode }}" = "release" ]; then |
| 80 | + DEPLOY_ARGS="$DEPLOY_ARGS --release" |
| 81 | + fi |
| 82 | + |
| 83 | + if [ "${{ inputs.show_logs }}" = "true" ]; then |
| 84 | + DEPLOY_ARGS="$DEPLOY_ARGS --logs" |
| 85 | + fi |
| 86 | + |
| 87 | + # Run deployment with verbose output for CI |
| 88 | + eval "./scripts/deploy-ios.sh $DEPLOY_ARGS --verbose" |
| 89 | + |
| 90 | + echo "✅ iOS app built and deployed successfully with Expo" |
| 91 | + |
| 92 | + # Get the deployed simulator details for testing |
| 93 | + SIMULATOR_ID=$(xcrun simctl list devices | grep "${{ inputs.device_name || 'iPhone 16' }}" | grep "Booted" | head -1 | grep -E -o '\([A-F0-9\-]+\)' | tr -d '()') |
| 94 | + echo "device_udid=$SIMULATOR_ID" >> $GITHUB_OUTPUT |
| 95 | + echo "bundle_id=com.softwareone.marketplaceMobile" >> $GITHUB_OUTPUT |
| 96 | + |
| 97 | + echo "📱 Deployed to simulator: ${{ inputs.device_name || 'iPhone 16' }} ($SIMULATOR_ID)" |
| 98 | + |
| 99 | + # Wait for app to be fully ready |
| 100 | + - name: Wait for App Startup |
| 101 | + run: | |
| 102 | + echo "⏳ Waiting for app to fully initialize..." |
| 103 | + sleep 10 |
| 104 | + |
| 105 | + # Verify app is installed and running |
| 106 | + SIMULATOR_ID="${{ steps.expo-deploy-ios.outputs.device_udid }}" |
| 107 | + BUNDLE_ID="${{ steps.expo-deploy-ios.outputs.bundle_id }}" |
| 108 | + |
| 109 | + echo "🔍 Verifying app installation..." |
| 110 | + xcrun simctl listapps "$SIMULATOR_ID" | grep -q "$BUNDLE_ID" && echo "✅ App is installed" || echo "❌ App not found" |
| 111 | + |
| 112 | + echo "🔍 Checking app state..." |
| 113 | + xcrun simctl spawn "$SIMULATOR_ID" launchctl list | grep -q "$BUNDLE_ID" && echo "✅ App is running" || echo "⚠️ App may not be running" |
| 114 | + |
| 115 | + # Run tests using our existing ios-test action (optional) |
| 116 | + - name: Run Appium Tests |
| 117 | + if: ${{ inputs.run_tests == true }} |
| 118 | + uses: ./.github/actions/ios-test |
| 119 | + with: |
| 120 | + device_uuid: ${{ steps.expo-deploy-ios.outputs.device_udid }} |
| 121 | + ios_version: ${{ inputs.ios_version || '26.0' }} |
| 122 | + device_name: ${{ inputs.device_name || 'iPhone 16' }} |
| 123 | + node_version: '20' |
| 124 | + appium_version: '3.1.1' |
| 125 | + app_bundle_id: ${{ steps.expo-deploy-ios.outputs.bundle_id }} |
| 126 | + appium_host: 'localhost' |
| 127 | + appium_port: '4723' |
| 128 | + |
| 129 | + # Alternative: Run specific test suite manually |
| 130 | + - name: Run Custom Test Suite |
| 131 | + if: ${{ inputs.run_tests == true }} |
| 132 | + working-directory: ./app |
| 133 | + env: |
| 134 | + DEVICE_UDID: ${{ steps.expo-deploy-ios.outputs.device_udid }} |
| 135 | + DEVICE_NAME: ${{ inputs.device_name || 'iPhone 16' }} |
| 136 | + PLATFORM_VERSION: ${{ inputs.ios_version || '26.0' }} |
| 137 | + APP_BUNDLE_ID: ${{ steps.expo-deploy-ios.outputs.bundle_id }} |
| 138 | + APPIUM_HOST: 'localhost' |
| 139 | + APPIUM_PORT: '4723' |
| 140 | + run: | |
| 141 | + echo "🧪 Running custom test suite with deployed app..." |
| 142 | + |
| 143 | + # Start Appium server |
| 144 | + echo "🚀 Starting Appium server..." |
| 145 | + npx appium --log-level warn > /tmp/appium.log 2>&1 & |
| 146 | + APPIUM_PID=$! |
| 147 | + echo "Appium PID: $APPIUM_PID" |
| 148 | + |
| 149 | + # Wait for Appium to start |
| 150 | + for i in {1..30}; do |
| 151 | + if curl -s http://localhost:4723/status > /dev/null 2>&1; then |
| 152 | + echo "✅ Appium server is ready!" |
| 153 | + break |
| 154 | + fi |
| 155 | + if [ $i -eq 30 ]; then |
| 156 | + echo "❌ Appium failed to start" |
| 157 | + cat /tmp/appium.log |
| 158 | + exit 1 |
| 159 | + fi |
| 160 | + sleep 1 |
| 161 | + done |
| 162 | + |
| 163 | + # Run WebDriverIO tests |
| 164 | + echo "🧪 Running WebDriverIO test suite..." |
| 165 | + npx wdio run wdio.conf.js --suite welcome |
| 166 | + |
| 167 | + # Cleanup |
| 168 | + echo "🛑 Stopping Appium server..." |
| 169 | + kill $APPIUM_PID 2>/dev/null || true |
| 170 | + |
| 171 | + # Collect logs and artifacts |
| 172 | + - name: Collect App Logs |
| 173 | + if: always() |
| 174 | + run: | |
| 175 | + echo "📋 Collecting app logs and system information..." |
| 176 | + |
| 177 | + SIMULATOR_ID="${{ steps.expo-deploy-ios.outputs.device_udid }}" |
| 178 | + |
| 179 | + echo "=== iOS Simulator Information ===" >> deployment_logs.txt |
| 180 | + xcrun simctl list devices | grep -A 5 -B 5 "$SIMULATOR_ID" >> deployment_logs.txt |
| 181 | + |
| 182 | + echo -e "\n=== App Installation Status ===" >> deployment_logs.txt |
| 183 | + xcrun simctl listapps "$SIMULATOR_ID" | grep -A 3 -B 3 "com.softwareone" >> deployment_logs.txt || echo "No app info found" >> deployment_logs.txt |
| 184 | + |
| 185 | + echo -e "\n=== Recent App Logs ===" >> deployment_logs.txt |
| 186 | + xcrun simctl spawn "$SIMULATOR_ID" log show --predicate 'subsystem contains "com.softwareone"' --last 5m >> deployment_logs.txt 2>&1 || echo "No recent logs found" >> deployment_logs.txt |
| 187 | + |
| 188 | + - name: Upload Deployment Logs |
| 189 | + if: always() |
| 190 | + uses: actions/upload-artifact@v4 |
| 191 | + with: |
| 192 | + name: ios-deployment-logs-${{ github.run_id }} |
| 193 | + path: | |
| 194 | + deployment_logs.txt |
| 195 | + /tmp/appium.log |
| 196 | + retention-days: 7 |
| 197 | + |
| 198 | + # Screenshots from failed tests (if any) |
| 199 | + - name: Upload Test Screenshots |
| 200 | + if: failure() && inputs.run_tests == true |
| 201 | + uses: actions/upload-artifact@v4 |
| 202 | + with: |
| 203 | + name: test-screenshots-${{ github.run_id }} |
| 204 | + path: app/screenshots/ |
| 205 | + retention-days: 7 |
| 206 | + if-no-files-found: ignore |
0 commit comments