From 776af51750b7cf22208a0b5724bae02386ea7101 Mon Sep 17 00:00:00 2001 From: wafflesvsfrankie <92288602+burtonemily@users.noreply.github.com> Date: Mon, 7 Apr 2025 15:10:20 +1000 Subject: [PATCH 1/3] chore: wip --- .env.sample | 24 +++++++------- .github/workflows/ios-regression.yml | 29 +++++++++-------- run/test/specs/utils/capabilities_ios.ts | 24 +++++++------- run/test/specs/utils/test_setup.ts | 4 +-- scripts/ci.sh | 41 ++++++------------------ 5 files changed, 51 insertions(+), 71 deletions(-) diff --git a/.env.sample b/.env.sample index 4ab7264..dc58e4a 100644 --- a/.env.sample +++ b/.env.sample @@ -7,15 +7,15 @@ export AVD_MANAGER_FULL_PATH=/home/yougotthis/Android/Sdk/cmdline-tools/latest/b export EMULATOR_FULL_PATH=/home/yougotthis/Android/Sdk/emulator/emulator export ANDROID_SYSTEM_IMAGE="system-images;android-35;google_atd;x86_64" export IOS_APP_PATH_PREFIX=just_not_empty -export IOS_FIRST_SIMULATOR=just_not_empty -export IOS_SECOND_SIMULATOR=just_not_empty -export IOS_THIRD_SIMULATOR=just_not_empty -export IOS_FOURTH_SIMULATOR=just_not_empty -export IOS_FIFTH_SIMULATOR=just_not_empty -export IOS_SIXTH_SIMULATOR=just_not_empty -export IOS_SEVENTH_SIMULATOR=just_not_empty -export IOS_EIGHTH_SIMULATOR=just_not_empty -export IOS_NINTH_SIMULATOR=just_not_empty -export IOS_TENTH_SIMULATOR=just_not_empty -export IOS_ELEVENTH_SIMULATOR=just_not_empty -export IOS_TWELFTH_SIMULATOR=just_not_empty +export IOS_1_SIMULATOR=just_not_empty +export IOS_2_SIMULATOR=just_not_empty +export IOS_3_SIMULATOR=just_not_empty +export IOS_4_SIMULATOR=just_not_empty +export IOS_5_SIMULATOR=just_not_empty +export IOS_6_SIMULATOR=just_not_empty +export IOS_7_SIMULATOR=just_not_empty +export IOS_8_SIMULATOR=just_not_empty +export IOS_9_SIMULATOR=just_not_empty +export IOS_10_SIMULATOR=just_not_empty +export IOS_11_SIMULATOR=just_not_empty +export IOS_12_SIMULATOR=just_not_empty diff --git a/.github/workflows/ios-regression.yml b/.github/workflows/ios-regression.yml index 7fb3c9d..36178a0 100644 --- a/.github/workflows/ios-regression.yml +++ b/.github/workflows/ios-regression.yml @@ -8,7 +8,7 @@ on: description: 'ipa url to test' required: true type: string - default: https://oxen.rocks/session-foundation/session-ios/master/session-ios-20250122T233019Z-55779b062-sim.tar.xz + default: https://oxen.rocks/session-foundation/session-ios/dev/session-ios-20250403T021527Z-c1d2ffbc4-sim.tar.xz RISK: description: 'risks to target' @@ -34,7 +34,7 @@ on: description: 'branch to checkout' required: true type: string - default: ci-ios + default: kick-member-test # SHARD_NUMBER: # description: 'shard number' @@ -113,18 +113,18 @@ jobs: AVD_MANAGER_FULL_PATH: '/Users/emilyburton/Library/Android/sdk/cmdline-tools/latest/bin/avdmanager' ANDROID_SYSTEM_IMAGE: 'system-images;android-35;google_atd;x86_64' EMULATOR_FULL_PATH: '/Users/emilyburton/Library/Android/sdk/emulator/emulator' - IOS_FIRST_SIMULATOR: '49651A15-3E14-4BAF-8B8E-0C630C35B8DD' - IOS_SECOND_SIMULATOR: '7CA21E47-56AC-4B76-82A4-1D5199515F38' - IOS_THIRD_SIMULATOR: 'FE1DEDC7-D530-41E7-9B38-86ED2DDB97CD' - IOS_FOURTH_SIMULATOR: '561C621C-2CEF-4FCC-87B7-E6221718D15C' - IOS_FIFTH_SIMULATOR: '5AA87E03-5831-4209-87A0-21E5ECDC490F' - IOS_SIXTH_SIMULATOR: '6FB10AF3-3970-46BA-B414-1206AA4E726D' - IOS_SEVENTH_SIMULATOR: '0BDA36C0-83F4-46DF-ADC9-FF30E969D4BD' - IOS_EIGHTH_SIMULATOR: '1C61A0B6-3085-46B6-9B2E-6E9A1B594944' - IOS_NINTH_SIMULATOR: '7C69D129-BD40-4BC0-9A0D-6A7E990F23E8' - IOS_TENTH_SIMULATOR: '275E0C5B-2458-4490-831D-4CE86C8EC704' - IOS_ELEVENTH_SIMULATOR: 'EA5C5BCB-1E3E-4FFC-88BB-8D1DE354BC3B' - IOS_TWELFTH_SIMULATOR: '41514F87-DC49-4C81-B60C-03D1F8653A42' + IOS_1_SIMULATOR: '4A75A0E1-9EDE-4169-93C3-DCE0F0C7664F' + IOS_2_SIMULATOR: 'ACB6A587-8556-4EA0-87CF-4326A9A22051' + IOS_3_SIMULATOR: 'D90B2AE2-FF30-49BE-9370-B789BAEED3BB' + IOS_4_SIMULATOR: '59BD1CA4-7A8D-40FB-BAC7-CC99500644E0' + IOS_5_SIMULATOR: '064F4F80-B81C-4B72-9715-43CD18975139' + IOS_6_SIMULATOR: '56D8BA2F-BA0C-4D8F-8E5B-FD928E2C7C66' + IOS_7_SIMULATOR: '012D6656-D6DE-4932-A460-72F5629EB2E0' + IOS_8_SIMULATOR: 'D66CBD9C-7550-4055-8504-95F0AE700617' + IOS_9_SIMULATOR: '84884861-F8EF-4481-A001-B403F2649FCF' + IOS_10_SIMULATOR: 'C0EE6A21-044D-4B6E-B9A5-7AB977ADF305' + IOS_11_SIMULATOR: 'B8E78B21-1432-41F3-A398-DE4FF8CF9DED' + IOS_12_SIMULATOR: '8214A3A2-D4E1-4AA8-BB0F-394E3A49BCFA' # echo "SHARD_NUMBER ${{ github.event.inputs.SHARD_NUMBER }}" # echo "SHARD_COUNT ${{ github.event.inputs.SHARD_COUNT }}" @@ -203,6 +203,7 @@ jobs: shell: bash run: | source ./scripts/ci.sh + stop_simulators_from_env_iOS start_simulators_from_env_iOS - name: List all tests run: | diff --git a/run/test/specs/utils/capabilities_ios.ts b/run/test/specs/utils/capabilities_ios.ts index c4c3368..f35b740 100644 --- a/run/test/specs/utils/capabilities_ios.ts +++ b/run/test/specs/utils/capabilities_ios.ts @@ -33,18 +33,18 @@ const sharediOSCapabilities: AppiumXCUITestCapabilities = { } as AppiumXCUITestCapabilities; const envVars = [ - 'IOS_FIRST_SIMULATOR', - 'IOS_SECOND_SIMULATOR', - 'IOS_THIRD_SIMULATOR', - 'IOS_FOURTH_SIMULATOR', - 'IOS_FIFTH_SIMULATOR', - 'IOS_SIXTH_SIMULATOR', - 'IOS_SEVENTH_SIMULATOR', - 'IOS_EIGHTH_SIMULATOR', - 'IOS_NINTH_SIMULATOR', - 'IOS_TENTH_SIMULATOR', - 'IOS_ELEVENTH_SIMULATOR', - 'IOS_TWELFTH_SIMULATOR', + 'IOS_1_SIMULATOR', + 'IOS_2_SIMULATOR', + 'IOS_3_SIMULATOR', + 'IOS_4_SIMULATOR', + 'IOS_5_SIMULATOR', + 'IOS_6_SIMULATOR', + 'IOS_7_SIMULATOR', + 'IOS_8_SIMULATOR', + 'IOS_9_SIMULATOR', + 'IOS_10_SIMULATOR', + 'IOS_11_SIMULATOR', + 'IOS_12_SIMULATOR', ] as const; function getIOSSimulatorUUIDFromEnv(index: CapabilitiesIndexType): string { diff --git a/run/test/specs/utils/test_setup.ts b/run/test/specs/utils/test_setup.ts index 2c3c41c..97af4b9 100644 --- a/run/test/specs/utils/test_setup.ts +++ b/run/test/specs/utils/test_setup.ts @@ -21,8 +21,8 @@ cd ~/Library/Android/sdk ./emulator/emulator -avd Pixel_4_API_30_2 IOS -open -a simulator --args -IOS_FIRST_SIMULATOR -no-boot-anim -open -a simulator --args -IOS_SECOND_SIMULATOR -no-boot-anim +open -a simulator --args -IOS_1_SIMULATOR -no-boot-anim +open -a simulator --args -IOS_2_SIMULATOR -no-boot-anim run branch on emulator one run branch on emulator two diff --git a/scripts/ci.sh b/scripts/ci.sh index 7649ba7..f06721d 100644 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash - +set -x # Android functions ARCH="x86_64" @@ -103,40 +103,20 @@ function start_with_snapshots() { SIMULATOR_DEVICE="iPhone 15 Pro Max" SIMULATOR_OS="18.2" -# Define an array of uppercase words for simulator names -NUMBER_WORDS=("FIRST" "SECOND" "THIRD" "FOURTH" "FIFTH" "SIXTH" "SEVENTH" "EIGHTH" "NINTH" "TENTH" "ELEVENTH" "TWELFTH") - # Function to boot simulators from environment variables function start_simulators_from_env_iOS() { echo "Starting iOS simulators from environment variables" - set -x for i in {1..12}; do - simulator_label=${NUMBER_WORDS[$((i - 1))]} + simulator_label=$i env_var="IOS_${simulator_label}_SIMULATOR" simulator_udid=$(printenv "$env_var") echo "Iteration $i: Label: $simulator_label, Env var: $env_var, UDID: $simulator_udid" if [[ -n "$simulator_udid" ]]; then - # Check if the simulator is already booted - booted=$(xcrun simctl list devices booted | grep "$simulator_udid") - echo "Current booted status for $simulator_udid: $booted" - - if [[ -n "$booted" ]]; then - echo "$simulator_label simulator ($simulator_udid) is already booted. Attempting shutdown..." - shutdown_output=$(xcrun simctl shutdown "$simulator_udid" 2>&1) - shutdown_status=$? - echo "Shutdown command output: $shutdown_output" - echo "Shutdown command exit code: $shutdown_status" - if [[ $shutdown_status -ne 0 ]]; then - echo "Error: Shutdown command failed for $simulator_udid" - exit 100 - fi - sleep 5 - fi - + echo "Booting $simulator_label simulator: $simulator_udid" boot_output=$(xcrun simctl boot "$simulator_udid" 2>&1) boot_status=$? @@ -144,7 +124,7 @@ function start_simulators_from_env_iOS() { echo "Boot command exit code: $boot_status" if [[ $boot_status -ne 0 ]]; then echo "Error: Boot command failed for $simulator_udid" - exit 101 + return 101 fi sleep 5 @@ -152,18 +132,17 @@ function start_simulators_from_env_iOS() { echo "Post-boot status for $simulator_udid: $booted" if [[ -z "$booted" ]]; then echo "Error: Simulator $simulator_udid did not boot successfully." - exit 102 + return 102 fi else echo "Error: $simulator_label simulator (env var $env_var) is not set" - exit 104 + return 104 fi done echo "Opening iOS Simulator app..." open -a Simulator - set +x } @@ -173,7 +152,7 @@ function start_simulators_from_env_iOS() { # Function to start the Appium server function start_appium_server() { echo "Starting Appium server..." - cd forked-session-appium || exit 110 + cd forked-session-appium || return 110 start-server } @@ -182,7 +161,7 @@ function stop_simulators_from_env_iOS() { echo "Stopping iOS simulators from environment variables..." for i in {1..12}; do - simulator_label=${NUMBER_WORDS[$((i - 1))]} + simulator_label=$i env_var="IOS_${simulator_label}_SIMULATOR" simulator_udid=$(printenv "$env_var") @@ -192,11 +171,11 @@ function stop_simulators_from_env_iOS() { echo "Stopping $simulator_label simulator: $simulator_udid" xcrun simctl shutdown "$simulator_udid" else - echo "$simulator_label simulator is not running or does not exist." - exit 120 + echo "$simulator_label simulator is not running or does not exist... skipping" fi else echo "Skipping $simulator_label simulator (not set)" + return 120 fi done } \ No newline at end of file From 4009ec06e79342fe600f12ed1a79bf0b04b6485a Mon Sep 17 00:00:00 2001 From: The Debuggernaut Date: Tue, 8 Apr 2025 18:05:42 +1000 Subject: [PATCH 2/3] chore: move scripts to be ts files --- scripts/ci.sh | 22 +++------------- scripts/ios_shared.ts | 32 +++++++++++++++++++++++ scripts/shared.ts | 3 +++ scripts/start_ios.ts | 59 +++++++++++++++++++++++++++++++++++++++++++ scripts/stop_ios.ts | 18 +++++++++++++ 5 files changed, 115 insertions(+), 19 deletions(-) mode change 100644 => 100755 scripts/ci.sh create mode 100644 scripts/ios_shared.ts create mode 100644 scripts/shared.ts create mode 100755 scripts/start_ios.ts create mode 100755 scripts/stop_ios.ts diff --git a/scripts/ci.sh b/scripts/ci.sh old mode 100644 new mode 100755 index f06721d..bdb5369 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -159,23 +159,7 @@ function start_appium_server() { # Function to stop running simulators function stop_simulators_from_env_iOS() { echo "Stopping iOS simulators from environment variables..." + xcrun simctl shutdown "all" +} - for i in {1..12}; do - simulator_label=$i - env_var="IOS_${simulator_label}_SIMULATOR" - simulator_udid=$(printenv "$env_var") - - if [[ -n "$simulator_udid" ]]; then - # Check if the simulator is running - if xcrun simctl list devices booted | grep -q "$simulator_udid"; then - echo "Stopping $simulator_label simulator: $simulator_udid" - xcrun simctl shutdown "$simulator_udid" - else - echo "$simulator_label simulator is not running or does not exist... skipping" - fi - else - echo "Skipping $simulator_label simulator (not set)" - return 120 - fi - done -} \ No newline at end of file +set +x diff --git a/scripts/ios_shared.ts b/scripts/ios_shared.ts new file mode 100644 index 0000000..0f6bc47 --- /dev/null +++ b/scripts/ios_shared.ts @@ -0,0 +1,32 @@ + +import { execSync } from 'child_process'; + + +export function getSimulatorUDID(index: number) { + const envVar = `IOS_${index}_SIMULATOR`; + return process.env[envVar]; +} + + + +export function isSimulatorBooted(udid: string) { + try { + const result = execSync(`xcrun simctl list devices booted`).toString(); + return result.includes(udid); + } catch (error: any) { + console.error("Error checking booted devices", error.message); + return false; + } +} + + + +export function isAnySimulatorBooted() { + try { + const result = execSync(`xcrun simctl list devices booted`).toString(); + return result.includes("Booted"); + } catch (error: any) { + console.error("Error checking booted devices", error.message); + return false; + } +} diff --git a/scripts/shared.ts b/scripts/shared.ts new file mode 100644 index 0000000..d1f0f89 --- /dev/null +++ b/scripts/shared.ts @@ -0,0 +1,3 @@ +export async function sleep(ms: number) { + return new Promise(resolve => setTimeout(resolve, ms)); + } \ No newline at end of file diff --git a/scripts/start_ios.ts b/scripts/start_ios.ts new file mode 100755 index 0000000..ba710c5 --- /dev/null +++ b/scripts/start_ios.ts @@ -0,0 +1,59 @@ +import { execSync, spawnSync } from 'child_process'; +import { getSimulatorUDID, isSimulatorBooted } from './ios_shared'; +import { sleep } from './shared'; + +const START_CHUNK = 6; +const MAX_SIMULATORS = 12; + +function bootSimulator(udid: string, label: number) { + try { + console.log(`Booting simulator ${label}: ${udid}`); + const result = execSync(`xcrun simctl boot ${udid}`, { stdio: 'pipe' }).toString(); + console.log(`Boot command output: ${result}`); + } catch (error: any) { + console.error(`Error: Boot command failed for ${udid}`); + console.error(error.stderr?.toString() || error.message); + return false; + } + + return true; +} + +async function startSimulatorsFromEnvIOS() { + console.log("Starting iOS simulators from environment variables..."); + + const simulators = []; + for (let i = 1; i <= MAX_SIMULATORS; i++) { + const udid = getSimulatorUDID(i); + if (!udid) { + throw new Error(`Error: Simulator ${i} (IOS_${i}_SIMULATOR) is not set`); + } + simulators.push({ label: i, udid }); + } + + for (let i = 0; i < simulators.length; i += START_CHUNK) { + const chunk = simulators.slice(i, i + START_CHUNK); + + for (const sim of chunk) { + const success = bootSimulator(sim.udid, sim.label); + if (!success) throw new Error(`Failed to boot simulator with parameters: ${sim.udid}:${sim.label}`); + } + + // Wait for simulators to boot + await sleep(5000); + + for (const sim of chunk) { + const booted = isSimulatorBooted(sim.udid); + console.log(`Post-boot status for ${sim.udid}: ${booted ? 'Booted' : 'Not booted'}`); + if (!booted) { + console.error(`Error: Simulator ${sim.udid} did not boot successfully.`); + return; + } + } + } + + console.log("Opening iOS Simulator app..."); + spawnSync('open', ['-a', 'Simulator']); +} + +startSimulatorsFromEnvIOS(); diff --git a/scripts/stop_ios.ts b/scripts/stop_ios.ts new file mode 100755 index 0000000..71d192f --- /dev/null +++ b/scripts/stop_ios.ts @@ -0,0 +1,18 @@ +import { execSync } from 'child_process'; +import { isAnySimulatorBooted } from './ios_shared'; + + +async function stopSimulatorsFromEnvIOS() { + console.log("Stopping all iOS simulators"); + execSync(`xcrun simctl shutdown "all"`).toString(); + if (isAnySimulatorBooted()) { + execSync(`xcrun simctl shutdown "all"`).toString(); + } + if (isAnySimulatorBooted()) { + throw new Error("Failed to kill all running simulators") + } + + console.log("All iOS simulators closed..."); +} + +stopSimulatorsFromEnvIOS(); From 3a8fb4c7e04a0959b0891ce5c6dd075200c8e49f Mon Sep 17 00:00:00 2001 From: The Debuggernaut Date: Tue, 8 Apr 2025 18:07:25 +1000 Subject: [PATCH 3/3] fix: updated workflow to use ts files --- .github/workflows/ios-regression.yml | 8 ++-- scripts/ci.sh | 61 ---------------------------- 2 files changed, 3 insertions(+), 66 deletions(-) diff --git a/.github/workflows/ios-regression.yml b/.github/workflows/ios-regression.yml index 36178a0..e773d71 100644 --- a/.github/workflows/ios-regression.yml +++ b/.github/workflows/ios-regression.yml @@ -202,9 +202,8 @@ jobs: - name: Start simulators shell: bash run: | - source ./scripts/ci.sh - stop_simulators_from_env_iOS - start_simulators_from_env_iOS + yarn tsc scripts/stop_ios.ts && node scripts/stop_ios.js + yarn tsc scripts/start_ios.ts && node scripts/start_ios.js - name: List all tests run: | cd forked-session-appium @@ -221,5 +220,4 @@ jobs: continue-on-error: true # just so we don't fail shell: bash run: | - source ./scripts/ci.sh - stop_simulators_from_env_iOS + yarn tsc scripts/stop_ios.ts && node scripts/stop_ios.js diff --git a/scripts/ci.sh b/scripts/ci.sh index bdb5369..5a1446c 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -98,68 +98,7 @@ function start_with_snapshots() { done } -# iOS functions - -SIMULATOR_DEVICE="iPhone 15 Pro Max" -SIMULATOR_OS="18.2" - -# Function to boot simulators from environment variables -function start_simulators_from_env_iOS() { - echo "Starting iOS simulators from environment variables" - - - for i in {1..12}; do - simulator_label=$i - env_var="IOS_${simulator_label}_SIMULATOR" - simulator_udid=$(printenv "$env_var") - - echo "Iteration $i: Label: $simulator_label, Env var: $env_var, UDID: $simulator_udid" - - if [[ -n "$simulator_udid" ]]; then - - echo "Booting $simulator_label simulator: $simulator_udid" - boot_output=$(xcrun simctl boot "$simulator_udid" 2>&1) - boot_status=$? - echo "Boot command output: $boot_output" - echo "Boot command exit code: $boot_status" - if [[ $boot_status -ne 0 ]]; then - echo "Error: Boot command failed for $simulator_udid" - return 101 - fi - sleep 5 - - booted=$(xcrun simctl list devices booted | grep "$simulator_udid") - echo "Post-boot status for $simulator_udid: $booted" - if [[ -z "$booted" ]]; then - echo "Error: Simulator $simulator_udid did not boot successfully." - return 102 - fi - else - echo "Error: $simulator_label simulator (env var $env_var) is not set" - return 104 - fi - done - - echo "Opening iOS Simulator app..." - open -a Simulator - -} - - -# Function to start the Appium server -function start_appium_server() { - echo "Starting Appium server..." - cd forked-session-appium || return 110 - start-server -} - -# Function to stop running simulators -function stop_simulators_from_env_iOS() { - echo "Stopping iOS simulators from environment variables..." - xcrun simctl shutdown "all" -} - set +x