From bd599828c51357c8fa939b842e00e387f06ce6bb Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Thu, 30 Jan 2025 09:23:25 +0530 Subject: [PATCH 01/98] init --- .github/workflows/e2e-android-detox.yml | 58 ++++++++++++++++++-- detox/README.md | 39 +++++++++----- detox/inject-detox-settings.js | 72 ------------------------- detox/package.json | 1 - 4 files changed, 79 insertions(+), 91 deletions(-) delete mode 100644 detox/inject-detox-settings.js diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 4544f364698..a2477fd7087 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -4,6 +4,7 @@ on: pull_request: branches: - main + - test_android_e2e types: - labeled @@ -13,7 +14,7 @@ concurrency: jobs: build-android-apk: - if: github.event.label.name == 'E2E Android tests for PR' + # if: github.event.label.name == 'E2E Android tests for PR' runs-on: ubuntu-latest-8-cores env: ORG_GRADLE_PROJECT_jvmargs: -Xmx8g @@ -54,10 +55,10 @@ jobs: - name: Inject Detox settings run: cd detox && npm run e2e:android-inject-settings - - name: Update minSdkVersion for react-native-image-picker - run: | - sed -i 's/minSdkVersion 21/minSdkVersion 23/' ./node_modules/react-native-image-picker/android/build.gradle - cat ./node_modules/react-native-image-picker/android/build.gradle | grep minSdkVersion + # - name: Update minSdkVersion for react-native-image-picker + # run: | + # sed -i 's/minSdkVersion 21/minSdkVersion 23/' ./node_modules/react-native-image-picker/android/build.gradle + # cat ./node_modules/react-native-image-picker/android/build.gradle | grep minSdkVersion - name: Detox build run: | @@ -71,3 +72,50 @@ jobs: with: name: android-build-apk-${{ github.run_id }} path: "android/app/build/outputs/apk/**/app-*.apk" + + run-android-tests: + # if: github.event.label.name == 'E2E Android tests for PR' + needs: build-android-apk + runs-on: ubuntu-latest-8-cores + steps: + - name: ci/checkout-repo + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Download APK artifact + uses: actions/download-artifact@v4 + with: + name: android-build-apk-${{ github.run_id }} + path: android/app/build/outputs/apk/ + + - name: Install Dependencies + run: sudo apt-get clean && sudo apt-get update && sudo apt-get install -y default-jdk + + - name: Cache Gradle dependencies + uses: actions/cache@v4 + with: + path: ~/.gradle/caches/modules-2/ + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: ${{ runner.os }}-gradle- + + - name: Set up Android SDK + uses: android-actions/setup-android@v3 + + - name: Start Android Emulator + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: 31 # Matches the API level in your Detox configuration + arch: x86_64 # Architecture of the emulator + profile: pixel_4_xl # Matches the device profile in your Detox configuration + avd-name: detox_pixel_4_xl_api_31 # Matches the avdName in your Detox configuration + script: | + adb devices + echo "Emulator started and ready for testing." + + - name: Run Detox tests + run: | + cd detox + npm install + npm install -g detox-cli + npm run e2e:android-test -- about.e2e.ts diff --git a/detox/README.md b/detox/README.md index a52a925cb37..ec0edeee406 100644 --- a/detox/README.md +++ b/detox/README.md @@ -1,36 +1,49 @@ # How to Run Detox Tests -## Android +This guide will help you set up and run Detox tests for your project. -### Install Dependencies +## Install Dependencies -From the root directory, run the following command to install the necessary dependencies: +First, navigate to the root directory of your project and install the necessary dependencies by running: ```sh npm install ``` -### Inject Detox Settings +navigate to the `detox` folder and run `npm install` + +## Android + +### Build Detox Android App -To inject the Detox settings into your project, navigate to the `detox` directory and run the following command: +To build the Detox Android app, navigate to the `detox` folder and run: ```sh -npm run inject-detox-settings +npm run e2e:android-build ``` -### Update `minSdkVersion` for `react-native-image-picker` +### Run Detox Android Tests -On macOS machines, update the `minSdkVersion` of `react-native-image-picker` to 23 by running the following command from the root directory. -This is required for Detox to build the test apk targeting android API 31 or higher. +To execute the Detox tests on Android, navigate to the `detox` folder and run: ```sh -sed -i '' 's/minSdkVersion 21/minSdkVersion 23/' ./node_modules/react-native-image-picker/android/build.gradle +npm run e2e:android-test ``` -### Build detox android app +## iOS + +### Build iOS Simulator -From the `detox` folder run: +To build the iOS simulator for Detox, navigate to the `detox` folder and run: +```sh +npm run e2e:ios-build ``` -npm run e2e:android-build + +### Run iOS Tests + +To execute the Detox tests on iOS, navigate to the `detox` folder and run: + +```sh +npm run e2e:ios-test ``` \ No newline at end of file diff --git a/detox/inject-detox-settings.js b/detox/inject-detox-settings.js deleted file mode 100644 index 8ba2db574dc..00000000000 --- a/detox/inject-detox-settings.js +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. -/* eslint-disable no-console */ -const fs = require('fs'); -const path = require('path'); - -// Paths to files -const androidManifestPath = path.resolve( - __dirname, - '../android/app/src/debug/AndroidManifest.xml', -); -const settingsGradlePath = path.resolve(__dirname, '../android/settings.gradle'); - -// Detox code to add to settings.gradle -const detoxSettings = ` -include ':detox' -project(':detox').projectDir = new File(rootProject.projectDir, '../detox/node_modules/detox/android') -`; - -// Updated AndroidManifest.xml content -const updatedManifest = ` - - - - - - - -`; - -// Update AndroidManifest.xml -function updateAndroidManifest() { - try { - fs.writeFileSync(androidManifestPath, updatedManifest, 'utf-8'); - console.log('AndroidManifest.xml updated successfully.'); - } catch (err) { - console.error(`Failed to update AndroidManifest.xml: ${err.message}`); - } -} - -// Update settings.gradle -function updateSettingsGradle() { - try { - const content = fs.readFileSync(settingsGradlePath, 'utf-8'); - if (content.includes("include ':detox'")) { - console.log('Detox settings already present in settings.gradle.'); - return; - } - fs.writeFileSync(settingsGradlePath, content + detoxSettings, 'utf-8'); - console.log('settings.gradle updated successfully.'); - } catch (err) { - console.error(`Failed to update settings.gradle: ${err.message}`); - } -} - -// Run updates -updateAndroidManifest(); -updateSettingsGradle(); diff --git a/detox/package.json b/detox/package.json index 662c8fd7ab4..b3fbbf7ca58 100644 --- a/detox/package.json +++ b/detox/package.json @@ -42,7 +42,6 @@ "xml2js": "0.6.2" }, "scripts": { - "e2e:android-inject-settings": "node inject-detox-settings.js", "e2e:android-create-emulator": "./create_android_emulator.sh", "e2e:android-build": "detox build -c android.emu.debug", "e2e:android-test": "detox test -c android.emu.debug", From 4cad4c237c585cd51cf694cb3200eb6a5f9d15cc Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Thu, 30 Jan 2025 09:33:31 +0530 Subject: [PATCH 02/98] test-1 --- .github/workflows/e2e-android-detox.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index a2477fd7087..f0f29acd832 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -49,11 +49,11 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: ${{ runner.os }}-gradle- - - name: Validate Gradle wrapper - uses: gradle/actions/wrapper-validation@v3 + # - name: Validate Gradle wrapper + # uses: gradle/actions/wrapper-validation@v3 - - name: Inject Detox settings - run: cd detox && npm run e2e:android-inject-settings + # - name: Inject Detox settings + # run: cd detox && npm run e2e:android-inject-settings # - name: Update minSdkVersion for react-native-image-picker # run: | From 6bdfe5d193de6388586b8a2fa0690ea52d1f9052 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Thu, 30 Jan 2025 09:49:50 +0530 Subject: [PATCH 03/98] test-2 --- .github/workflows/e2e-android-detox.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index f0f29acd832..c06eb2e21e4 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -1,6 +1,9 @@ name: Detox E2E Android Tests PR on: + push: + branches: + - test_android_e2e pull_request: branches: - main From 16e7618df32090446c62d6c67b420c5a64956e7b Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Thu, 30 Jan 2025 10:38:46 +0530 Subject: [PATCH 04/98] test-3 --- .github/workflows/e2e-android-detox.yml | 56 ++++++++++++++++++++----- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index c06eb2e21e4..12fc4a2362b 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -86,14 +86,47 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} - - name: Download APK artifact - uses: actions/download-artifact@v4 - with: - name: android-build-apk-${{ github.run_id }} - path: android/app/build/outputs/apk/ + # - name: Download APK artifact + # uses: actions/download-artifact@v4 + # with: + # name: android-build-apk-${{ github.run_id }} + # path: android/app/build/outputs/apk/ + + # ***************************************************** + + + - name: Download artifact + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + curl -L -H "Authorization: token $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/mattermost/mattermost-mobile/actions/artifacts/2508537192/zip \ + --output android/app/build/outputs/apk/artifact.zip + + - name: Unzip artifact + run: unzip android/app/build/outputs/apk/artifact.zip -d android/app/build/outputs/apk + + - name: List unzipped files + run: ls -la android/app/build/outputs/apk + + - name: Cleanup + run: | + find android/app/build -type f + rm android/app/build/outputs/apk/artifact.zip + + # ***************************************************** - name: Install Dependencies - run: sudo apt-get clean && sudo apt-get update && sudo apt-get install -y default-jdk + run: | + sudo apt-get clean + sudo apt-get update + sudo apt-get install -y default-jdk + + - name: Install Emulator Dependencies + run: | + sudo apt-get update + sudo apt-get install -y libpulse0 libnss3 libxcomposite1 libxcursor1 libxi6 libxtst6 libasound2 libatk1.0-0 libgtk-3-0 - name: Cache Gradle dependencies uses: actions/cache@v4 @@ -108,10 +141,13 @@ jobs: - name: Start Android Emulator uses: reactivecircus/android-emulator-runner@v2 with: - api-level: 31 # Matches the API level in your Detox configuration - arch: x86_64 # Architecture of the emulator - profile: pixel_4_xl # Matches the device profile in your Detox configuration - avd-name: detox_pixel_4_xl_api_31 # Matches the avdName in your Detox configuration + api-level: 31 + arch: x86_64 + profile: pixel_4_xl + avd-name: detox_pixel_4_xl_api_31 + emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -accel off + disable-animations: true + emulator-boot-timeout: 600 script: | adb devices echo "Emulator started and ready for testing." From 92aa98404c4f0f9195353fb49da67fde86ebf3db Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Thu, 30 Jan 2025 10:44:59 +0530 Subject: [PATCH 05/98] test-4 --- .github/workflows/e2e-android-detox.yml | 118 ++++++++++++------------ 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 12fc4a2362b..ebf39d0d2ed 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -16,69 +16,69 @@ concurrency: cancel-in-progress: true jobs: - build-android-apk: - # if: github.event.label.name == 'E2E Android tests for PR' - runs-on: ubuntu-latest-8-cores - env: - ORG_GRADLE_PROJECT_jvmargs: -Xmx8g - steps: - - name: Prune Docker to free up space - run: docker system prune -af - - - name: Remove npm Temporary Files - run: | - rm -rf ~/.npm/_cacache - - - name: ci/checkout-repo - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - with: - ref: ${{ github.event.pull_request.head.sha }} - - - name: ci/prepare-android-build - uses: ./.github/actions/prepare-android-build - env: - STORE_FILE: "${{ secrets.MM_MOBILE_STORE_FILE }}" - STORE_ALIAS: "${{ secrets.MM_MOBILE_STORE_ALIAS }}" - STORE_PASSWORD: "${{ secrets.MM_MOBILE_STORE_PASSWORD }}" - MATTERMOST_BUILD_GH_TOKEN: "${{ secrets.MATTERMOST_BUILD_GH_TOKEN }}" - - - name: Install Dependencies - run: sudo apt-get clean && sudo apt-get update && sudo apt-get install -y default-jdk + # build-android-apk: + # # if: github.event.label.name == 'E2E Android tests for PR' + # runs-on: ubuntu-latest-8-cores + # env: + # ORG_GRADLE_PROJECT_jvmargs: -Xmx8g + # steps: + # - name: Prune Docker to free up space + # run: docker system prune -af + + # - name: Remove npm Temporary Files + # run: | + # rm -rf ~/.npm/_cacache + + # - name: ci/checkout-repo + # uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + # with: + # ref: ${{ github.event.pull_request.head.sha }} + + # - name: ci/prepare-android-build + # uses: ./.github/actions/prepare-android-build + # env: + # STORE_FILE: "${{ secrets.MM_MOBILE_STORE_FILE }}" + # STORE_ALIAS: "${{ secrets.MM_MOBILE_STORE_ALIAS }}" + # STORE_PASSWORD: "${{ secrets.MM_MOBILE_STORE_PASSWORD }}" + # MATTERMOST_BUILD_GH_TOKEN: "${{ secrets.MATTERMOST_BUILD_GH_TOKEN }}" + + # - name: Install Dependencies + # run: sudo apt-get clean && sudo apt-get update && sudo apt-get install -y default-jdk - - name: Cache Gradle dependencies - uses: actions/cache@v4 - with: - path: ~/.gradle/caches/modules-2/ - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: ${{ runner.os }}-gradle- - - # - name: Validate Gradle wrapper - # uses: gradle/actions/wrapper-validation@v3 - - # - name: Inject Detox settings - # run: cd detox && npm run e2e:android-inject-settings - - # - name: Update minSdkVersion for react-native-image-picker - # run: | - # sed -i 's/minSdkVersion 21/minSdkVersion 23/' ./node_modules/react-native-image-picker/android/build.gradle - # cat ./node_modules/react-native-image-picker/android/build.gradle | grep minSdkVersion - - - name: Detox build - run: | - cd detox - npm install - npm install -g detox-cli - npm run e2e:android-build - - - name: ci/upload-android-pr-build - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - name: android-build-apk-${{ github.run_id }} - path: "android/app/build/outputs/apk/**/app-*.apk" + # - name: Cache Gradle dependencies + # uses: actions/cache@v4 + # with: + # path: ~/.gradle/caches/modules-2/ + # key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + # restore-keys: ${{ runner.os }}-gradle- + + # # - name: Validate Gradle wrapper + # # uses: gradle/actions/wrapper-validation@v3 + + # # - name: Inject Detox settings + # # run: cd detox && npm run e2e:android-inject-settings + + # # - name: Update minSdkVersion for react-native-image-picker + # # run: | + # # sed -i 's/minSdkVersion 21/minSdkVersion 23/' ./node_modules/react-native-image-picker/android/build.gradle + # # cat ./node_modules/react-native-image-picker/android/build.gradle | grep minSdkVersion + + # - name: Detox build + # run: | + # cd detox + # npm install + # npm install -g detox-cli + # npm run e2e:android-build + + # - name: ci/upload-android-pr-build + # uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 + # with: + # name: android-build-apk-${{ github.run_id }} + # path: "android/app/build/outputs/apk/**/app-*.apk" run-android-tests: # if: github.event.label.name == 'E2E Android tests for PR' - needs: build-android-apk + # needs: build-android-apk runs-on: ubuntu-latest-8-cores steps: - name: ci/checkout-repo From fd40f4f9427506ee565e5882a249b762fd5e6179 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Thu, 30 Jan 2025 10:46:05 +0530 Subject: [PATCH 06/98] Revert "test-4" This reverts commit 92aa98404c4f0f9195353fb49da67fde86ebf3db. --- .github/workflows/e2e-android-detox.yml | 118 ++++++++++++------------ 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index ebf39d0d2ed..12fc4a2362b 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -16,69 +16,69 @@ concurrency: cancel-in-progress: true jobs: - # build-android-apk: - # # if: github.event.label.name == 'E2E Android tests for PR' - # runs-on: ubuntu-latest-8-cores - # env: - # ORG_GRADLE_PROJECT_jvmargs: -Xmx8g - # steps: - # - name: Prune Docker to free up space - # run: docker system prune -af - - # - name: Remove npm Temporary Files - # run: | - # rm -rf ~/.npm/_cacache - - # - name: ci/checkout-repo - # uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - # with: - # ref: ${{ github.event.pull_request.head.sha }} - - # - name: ci/prepare-android-build - # uses: ./.github/actions/prepare-android-build - # env: - # STORE_FILE: "${{ secrets.MM_MOBILE_STORE_FILE }}" - # STORE_ALIAS: "${{ secrets.MM_MOBILE_STORE_ALIAS }}" - # STORE_PASSWORD: "${{ secrets.MM_MOBILE_STORE_PASSWORD }}" - # MATTERMOST_BUILD_GH_TOKEN: "${{ secrets.MATTERMOST_BUILD_GH_TOKEN }}" - - # - name: Install Dependencies - # run: sudo apt-get clean && sudo apt-get update && sudo apt-get install -y default-jdk + build-android-apk: + # if: github.event.label.name == 'E2E Android tests for PR' + runs-on: ubuntu-latest-8-cores + env: + ORG_GRADLE_PROJECT_jvmargs: -Xmx8g + steps: + - name: Prune Docker to free up space + run: docker system prune -af + + - name: Remove npm Temporary Files + run: | + rm -rf ~/.npm/_cacache + + - name: ci/checkout-repo + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: ci/prepare-android-build + uses: ./.github/actions/prepare-android-build + env: + STORE_FILE: "${{ secrets.MM_MOBILE_STORE_FILE }}" + STORE_ALIAS: "${{ secrets.MM_MOBILE_STORE_ALIAS }}" + STORE_PASSWORD: "${{ secrets.MM_MOBILE_STORE_PASSWORD }}" + MATTERMOST_BUILD_GH_TOKEN: "${{ secrets.MATTERMOST_BUILD_GH_TOKEN }}" + + - name: Install Dependencies + run: sudo apt-get clean && sudo apt-get update && sudo apt-get install -y default-jdk - # - name: Cache Gradle dependencies - # uses: actions/cache@v4 - # with: - # path: ~/.gradle/caches/modules-2/ - # key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - # restore-keys: ${{ runner.os }}-gradle- - - # # - name: Validate Gradle wrapper - # # uses: gradle/actions/wrapper-validation@v3 - - # # - name: Inject Detox settings - # # run: cd detox && npm run e2e:android-inject-settings - - # # - name: Update minSdkVersion for react-native-image-picker - # # run: | - # # sed -i 's/minSdkVersion 21/minSdkVersion 23/' ./node_modules/react-native-image-picker/android/build.gradle - # # cat ./node_modules/react-native-image-picker/android/build.gradle | grep minSdkVersion - - # - name: Detox build - # run: | - # cd detox - # npm install - # npm install -g detox-cli - # npm run e2e:android-build - - # - name: ci/upload-android-pr-build - # uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - # with: - # name: android-build-apk-${{ github.run_id }} - # path: "android/app/build/outputs/apk/**/app-*.apk" + - name: Cache Gradle dependencies + uses: actions/cache@v4 + with: + path: ~/.gradle/caches/modules-2/ + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: ${{ runner.os }}-gradle- + + # - name: Validate Gradle wrapper + # uses: gradle/actions/wrapper-validation@v3 + + # - name: Inject Detox settings + # run: cd detox && npm run e2e:android-inject-settings + + # - name: Update minSdkVersion for react-native-image-picker + # run: | + # sed -i 's/minSdkVersion 21/minSdkVersion 23/' ./node_modules/react-native-image-picker/android/build.gradle + # cat ./node_modules/react-native-image-picker/android/build.gradle | grep minSdkVersion + + - name: Detox build + run: | + cd detox + npm install + npm install -g detox-cli + npm run e2e:android-build + + - name: ci/upload-android-pr-build + uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 + with: + name: android-build-apk-${{ github.run_id }} + path: "android/app/build/outputs/apk/**/app-*.apk" run-android-tests: # if: github.event.label.name == 'E2E Android tests for PR' - # needs: build-android-apk + needs: build-android-apk runs-on: ubuntu-latest-8-cores steps: - name: ci/checkout-repo From 062d702d2676bfab72d03880a2361d7bfd7c8229 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Thu, 30 Jan 2025 10:46:54 +0530 Subject: [PATCH 07/98] test-5 --- .github/workflows/e2e-android-detox.yml | 46 +++---------------------- 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 12fc4a2362b..e6e202f0d0f 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -52,17 +52,6 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: ${{ runner.os }}-gradle- - # - name: Validate Gradle wrapper - # uses: gradle/actions/wrapper-validation@v3 - - # - name: Inject Detox settings - # run: cd detox && npm run e2e:android-inject-settings - - # - name: Update minSdkVersion for react-native-image-picker - # run: | - # sed -i 's/minSdkVersion 21/minSdkVersion 23/' ./node_modules/react-native-image-picker/android/build.gradle - # cat ./node_modules/react-native-image-picker/android/build.gradle | grep minSdkVersion - - name: Detox build run: | cd detox @@ -86,36 +75,11 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} - # - name: Download APK artifact - # uses: actions/download-artifact@v4 - # with: - # name: android-build-apk-${{ github.run_id }} - # path: android/app/build/outputs/apk/ - - # ***************************************************** - - - - name: Download artifact - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - curl -L -H "Authorization: token $GITHUB_TOKEN" \ - -H "Accept: application/vnd.github.v3+json" \ - https://api.github.com/repos/mattermost/mattermost-mobile/actions/artifacts/2508537192/zip \ - --output android/app/build/outputs/apk/artifact.zip - - - name: Unzip artifact - run: unzip android/app/build/outputs/apk/artifact.zip -d android/app/build/outputs/apk - - - name: List unzipped files - run: ls -la android/app/build/outputs/apk - - - name: Cleanup - run: | - find android/app/build -type f - rm android/app/build/outputs/apk/artifact.zip - - # ***************************************************** + - name: Download APK artifact + uses: actions/download-artifact@v4 + with: + name: android-build-apk-${{ github.run_id }} + path: android/app/build/outputs/apk/ - name: Install Dependencies run: | From 6196ef222df16d7b586ae31bf0d482173d8aa75a Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Thu, 30 Jan 2025 11:08:11 +0530 Subject: [PATCH 08/98] test-6 --- .github/workflows/e2e-android-detox.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index e6e202f0d0f..94576858145 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -90,7 +90,7 @@ jobs: - name: Install Emulator Dependencies run: | sudo apt-get update - sudo apt-get install -y libpulse0 libnss3 libxcomposite1 libxcursor1 libxi6 libxtst6 libasound2 libatk1.0-0 libgtk-3-0 + sudo apt-get install -y libpulse0 libnss3 libxcomposite1 libxcursor1 libxi6 libxtst6 libasound2t64 libatk1.0-0 libgtk-3-0 - name: Cache Gradle dependencies uses: actions/cache@v4 From 5fd5de9eead5f1519de7f64a79fc7bf4528649fd Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Thu, 30 Jan 2025 15:31:11 +0530 Subject: [PATCH 09/98] test-7 --- .github/workflows/e2e-android-detox.yml | 59 +++++++++++++++++-------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 94576858145..966c68c9961 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -17,7 +17,7 @@ concurrency: jobs: build-android-apk: - # if: github.event.label.name == 'E2E Android tests for PR' + if: github.event.label.name == 'E2E Android tests for PR' && false runs-on: ubuntu-latest-8-cores env: ORG_GRADLE_PROJECT_jvmargs: -Xmx8g @@ -67,30 +67,53 @@ jobs: run-android-tests: # if: github.event.label.name == 'E2E Android tests for PR' - needs: build-android-apk - runs-on: ubuntu-latest-8-cores + # needs: build-android-apk + runs-on: macos-14 steps: - name: ci/checkout-repo uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: ref: ${{ github.event.pull_request.head.sha }} - - name: Download APK artifact - uses: actions/download-artifact@v4 - with: - name: android-build-apk-${{ github.run_id }} - path: android/app/build/outputs/apk/ + # - name: Download APK artifact + # uses: actions/download-artifact@v4 + # with: + # name: android-build-apk-13046110009 + # path: android/app/build/outputs/apk/ + + - name: Create destination path + run: mkdir -p android/app/build/outputs/apk - - name: Install Dependencies + - name: Download artifact + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - sudo apt-get clean - sudo apt-get update - sudo apt-get install -y default-jdk + curl -L -H "Authorization: token $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/mattermost/mattermost-mobile/actions/artifacts/2508660502/zip \ + --output android/app/build/outputs/apk/artifact.zip + + - name: Unzip artifact + run: unzip android/app/build/outputs/apk/artifact.zip -d android/app/build/outputs/apk - - name: Install Emulator Dependencies + - name: List unzipped files + run: ls -la android/app/build/outputs/apk + + - name: Cleanup run: | - sudo apt-get update - sudo apt-get install -y libpulse0 libnss3 libxcomposite1 libxcursor1 libxi6 libxtst6 libasound2t64 libatk1.0-0 libgtk-3-0 + find android/app/build -type f + rm android/app/build/outputs/apk/artifact.zip + + # - name: Install Dependencies + # run: | + # sudo apt-get clean + # sudo apt-get update + # sudo apt-get install -y default-jdk + + # - name: Install Emulator Dependencies + # run: | + # sudo apt-get update + # sudo apt-get install -y libpulse0 libnss3 libxcomposite1 libxcursor1 libxi6 libxtst6 libasound2t64 libatk1.0-0 libgtk-3-0 - name: Cache Gradle dependencies uses: actions/cache@v4 @@ -101,7 +124,7 @@ jobs: - name: Set up Android SDK uses: android-actions/setup-android@v3 - + - name: Start Android Emulator uses: reactivecircus/android-emulator-runner@v2 with: @@ -109,13 +132,13 @@ jobs: arch: x86_64 profile: pixel_4_xl avd-name: detox_pixel_4_xl_api_31 - emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -accel off + emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim disable-animations: true emulator-boot-timeout: 600 script: | adb devices echo "Emulator started and ready for testing." - + - name: Run Detox tests run: | cd detox From 2277b3f189052025e5470f757d7aa48c6f5970d0 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Thu, 30 Jan 2025 15:42:23 +0530 Subject: [PATCH 10/98] test-8 --- .github/workflows/e2e-android-detox.yml | 43 ++++++++++++++++--------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 966c68c9961..0adf6d1e0e7 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -122,23 +122,34 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: ${{ runner.os }}-gradle- - - name: Set up Android SDK - uses: android-actions/setup-android@v3 - - - name: Start Android Emulator - uses: reactivecircus/android-emulator-runner@v2 + - name: Install Node.js + uses: actions/setup-node@v3 with: - api-level: 31 - arch: x86_64 - profile: pixel_4_xl - avd-name: detox_pixel_4_xl_api_31 - emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim - disable-animations: true - emulator-boot-timeout: 600 - script: | - adb devices - echo "Emulator started and ready for testing." - + node-version: '16' + + - name: Install Android SDK + uses: android-actions/setup-android@v3 + + - name: Accept licenses + run: yes | sdkmanager --licenses + + - name: Install required SDK components + run: | + sdkmanager "platform-tools" "platforms;android-31" "build-tools;31.0.0" "emulator" "system-images;android-31;default;x86_64" + + - name: Create AVD + run: | + echo "no" | avdmanager create avd --force --name detox_pixel_4_xl_api_31 --package "system-images;android-31;default;x86_64" --device "pixel_4_xl" + + - name: Start emulator + run: | + emulator -avd detox_pixel_4_xl_api_31 -no-window -no-audio -no-boot-anim -gpu swiftshader_indirect & + adb wait-for-device + while [[ "$(adb shell getprop sys.boot_completed)" != "1" ]]; do + sleep 2 + done + echo "Emulator is ready." + - name: Run Detox tests run: | cd detox From 57e63455289d652b7da6f4ccb4f771bf3c8e9b5c Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Thu, 30 Jan 2025 16:33:13 +0530 Subject: [PATCH 11/98] test-9 --- .github/workflows/e2e-android-detox.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 0adf6d1e0e7..c8617299053 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -135,11 +135,11 @@ jobs: - name: Install required SDK components run: | - sdkmanager "platform-tools" "platforms;android-31" "build-tools;31.0.0" "emulator" "system-images;android-31;default;x86_64" + sdkmanager "platform-tools" "platforms;android-31" "build-tools;31.0.0" "emulator" "system-images;android-31;google_apis;x86_64" - name: Create AVD run: | - echo "no" | avdmanager create avd --force --name detox_pixel_4_xl_api_31 --package "system-images;android-31;default;x86_64" --device "pixel_4_xl" + echo "no" | avdmanager create avd --force --name detox_pixel_4_xl_api_31 --package "system-images;android-31;google_apis;x86_64" --device "pixel_4_xl" - name: Start emulator run: | From f39a66551020d020f3824e0b0cc613f1a604ef6a Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 09:09:11 +0530 Subject: [PATCH 12/98] test-10 --- .github/workflows/e2e-android-detox.yml | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index c8617299053..14d6397c706 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -104,17 +104,6 @@ jobs: find android/app/build -type f rm android/app/build/outputs/apk/artifact.zip - # - name: Install Dependencies - # run: | - # sudo apt-get clean - # sudo apt-get update - # sudo apt-get install -y default-jdk - - # - name: Install Emulator Dependencies - # run: | - # sudo apt-get update - # sudo apt-get install -y libpulse0 libnss3 libxcomposite1 libxcursor1 libxi6 libxtst6 libasound2t64 libatk1.0-0 libgtk-3-0 - - name: Cache Gradle dependencies uses: actions/cache@v4 with: @@ -135,15 +124,20 @@ jobs: - name: Install required SDK components run: | - sdkmanager "platform-tools" "platforms;android-31" "build-tools;31.0.0" "emulator" "system-images;android-31;google_apis;x86_64" + sdkmanager "platform-tools" "platforms;android-31" "build-tools;31.0.0" "emulator" "system-images;android-31;default;arm64-v8a" + + - name: Install Emulator Separately + run: | + sdkmanager "emulator" + echo "Emulator installed successfully." - name: Create AVD run: | - echo "no" | avdmanager create avd --force --name detox_pixel_4_xl_api_31 --package "system-images;android-31;google_apis;x86_64" --device "pixel_4_xl" + echo "no" | avdmanager create avd --force --name detox_pixel_4_xl_api_31 --package "system-images;android-31;default;arm64-v8a" --device "pixel_4_xl" - name: Start emulator run: | - emulator -avd detox_pixel_4_xl_api_31 -no-window -no-audio -no-boot-anim -gpu swiftshader_indirect & + emulator -avd detox_pixel_4_xl_api_31 -no-window -no-audio -no-boot-anim -gpu swiftshader_indirect -no-snapshot & adb wait-for-device while [[ "$(adb shell getprop sys.boot_completed)" != "1" ]]; do sleep 2 From 92ee7bd1173cceab3c78fe2b73176f54a7a96e67 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 09:22:03 +0530 Subject: [PATCH 13/98] Manually Install Emulator Dependencies --- .github/workflows/e2e-android-detox.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 14d6397c706..7ef06d729d6 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -126,6 +126,12 @@ jobs: run: | sdkmanager "platform-tools" "platforms;android-31" "build-tools;31.0.0" "emulator" "system-images;android-31;default;arm64-v8a" + - name: Manually Install Emulator Dependencies + run: | + sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer + brew install qt + echo "QT_PATH=$(brew --prefix qt)" >> $GITHUB_ENV + - name: Install Emulator Separately run: | sdkmanager "emulator" From 811157ce2509d42611fe78a443b3ac1a3a00c7a5 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 09:27:07 +0530 Subject: [PATCH 14/98] Use preinstalled emulator and change the archi to armv8 --- .github/workflows/e2e-android-detox.yml | 35 +++++++++++-------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 7ef06d729d6..4b7b17872e0 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -119,31 +119,28 @@ jobs: - name: Install Android SDK uses: android-actions/setup-android@v3 - - name: Accept licenses + - name: Accept Android Licenses run: yes | sdkmanager --licenses - - name: Install required SDK components + - name: Use Pre-installed SDK & Emulator run: | - sdkmanager "platform-tools" "platforms;android-31" "build-tools;31.0.0" "emulator" "system-images;android-31;default;arm64-v8a" + echo "Using pre-installed Android SDK at: $ANDROID_HOME" + sdkmanager --list | grep "installed" - - name: Manually Install Emulator Dependencies + - name: Create AVD (if not exists) run: | - sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer - brew install qt - echo "QT_PATH=$(brew --prefix qt)" >> $GITHUB_ENV - - - name: Install Emulator Separately - run: | - sdkmanager "emulator" - echo "Emulator installed successfully." - - - name: Create AVD - run: | - echo "no" | avdmanager create avd --force --name detox_pixel_4_xl_api_31 --package "system-images;android-31;default;arm64-v8a" --device "pixel_4_xl" - - - name: Start emulator + AVD_NAME="detox_pixel_4_xl_api_31" + if ! emulator -list-avds | grep -q "$AVD_NAME"; then + echo "Creating new AVD..." + echo "no" | avdmanager create avd --force --name "$AVD_NAME" --package "system-images;android-31;default;arm64-v8a" --device "pixel_4_xl" + else + echo "AVD already exists." + fi + + - name: Start Emulator run: | - emulator -avd detox_pixel_4_xl_api_31 -no-window -no-audio -no-boot-anim -gpu swiftshader_indirect -no-snapshot & + AVD_NAME="detox_pixel_4_xl_api_31" + emulator -avd "$AVD_NAME" -no-window -no-audio -no-boot-anim -gpu swiftshader_indirect -no-snapshot & adb wait-for-device while [[ "$(adb shell getprop sys.boot_completed)" != "1" ]]; do sleep 2 From d1a416fc83ef225f1baf03b8dd86dca95c2faa89 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 09:38:30 +0530 Subject: [PATCH 15/98] use v8 archi emulator --- .github/workflows/e2e-android-detox.yml | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 4b7b17872e0..a81c7de330d 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -122,25 +122,17 @@ jobs: - name: Accept Android Licenses run: yes | sdkmanager --licenses - - name: Use Pre-installed SDK & Emulator + - name: Install required SDK components run: | - echo "Using pre-installed Android SDK at: $ANDROID_HOME" - sdkmanager --list | grep "installed" + sdkmanager "platform-tools" "platforms;android-31" "build-tools;31.0.0" "emulator" "system-images;android-31;google_apis;arm64-v8a" - - name: Create AVD (if not exists) + - name: Create AVD run: | - AVD_NAME="detox_pixel_4_xl_api_31" - if ! emulator -list-avds | grep -q "$AVD_NAME"; then - echo "Creating new AVD..." - echo "no" | avdmanager create avd --force --name "$AVD_NAME" --package "system-images;android-31;default;arm64-v8a" --device "pixel_4_xl" - else - echo "AVD already exists." - fi - - - name: Start Emulator + echo "no" | avdmanager create avd --force --name detox_pixel_4_xl_api_31_arm --package "system-images;android-31;google_apis;arm64-v8a" --device "pixel_4_xl" + + - name: Start emulator run: | - AVD_NAME="detox_pixel_4_xl_api_31" - emulator -avd "$AVD_NAME" -no-window -no-audio -no-boot-anim -gpu swiftshader_indirect -no-snapshot & + emulator -avd detox_pixel_4_xl_api_31_arm -no-window -no-audio -no-boot-anim -gpu swiftshader_indirect -no-snapshot & adb wait-for-device while [[ "$(adb shell getprop sys.boot_completed)" != "1" ]]; do sleep 2 From b9d9d4bf5a92efa406cdaa3689feee4e4fc18233 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 09:52:14 +0530 Subject: [PATCH 16/98] use macos-14-arm --- .github/workflows/e2e-android-detox.yml | 27 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index a81c7de330d..62caf0d6b8c 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -68,7 +68,7 @@ jobs: run-android-tests: # if: github.event.label.name == 'E2E Android tests for PR' # needs: build-android-apk - runs-on: macos-14 + runs-on: macos-14-arm64 steps: - name: ci/checkout-repo uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 @@ -122,17 +122,24 @@ jobs: - name: Accept Android Licenses run: yes | sdkmanager --licenses - - name: Install required SDK components + - name: Create AVD (if not exists) run: | - sdkmanager "platform-tools" "platforms;android-31" "build-tools;31.0.0" "emulator" "system-images;android-31;google_apis;arm64-v8a" - - - name: Create AVD - run: | - echo "no" | avdmanager create avd --force --name detox_pixel_4_xl_api_31_arm --package "system-images;android-31;google_apis;arm64-v8a" --device "pixel_4_xl" - - - name: Start emulator + AVD_NAME="detox_pixel_4_xl_api_31" + if ! emulator -list-avds | grep -q "$AVD_NAME"; then + echo "Creating new AVD..." + echo "no" | avdmanager create avd --force --name "$AVD_NAME" --package "system-images;android-31;default;arm64-v8a" --device "pixel_4_xl" + else + echo "AVD already exists." + fi + + - name: Start Emulator with Correct Binary run: | - emulator -avd detox_pixel_4_xl_api_31_arm -no-window -no-audio -no-boot-anim -gpu swiftshader_indirect -no-snapshot & + AVD_NAME="detox_pixel_4_xl_api_31" + EMULATOR_PATH="$ANDROID_HOME/emulator/emulator" + + echo "Starting emulator with binary: $EMULATOR_PATH" + "$EMULATOR_PATH" -avd "$AVD_NAME" -no-window -no-audio -no-boot-anim -gpu swiftshader_indirect -no-snapshot & + adb wait-for-device while [[ "$(adb shell getprop sys.boot_completed)" != "1" ]]; do sleep 2 From 205196ce0cdd4b46b2657a00c2755b5be38d4668 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 10:04:14 +0530 Subject: [PATCH 17/98] use macos-14-arm --- .github/workflows/e2e-android-detox.yml | 35 +++++++++++-------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 62caf0d6b8c..d7988101855 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -68,7 +68,7 @@ jobs: run-android-tests: # if: github.event.label.name == 'E2E Android tests for PR' # needs: build-android-apk - runs-on: macos-14-arm64 + runs-on: macos-14 steps: - name: ci/checkout-repo uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 @@ -114,32 +114,27 @@ jobs: - name: Install Node.js uses: actions/setup-node@v3 with: - node-version: '16' + node-version: '18' - - name: Install Android SDK - uses: android-actions/setup-android@v3 + - name: Set up Android environment + run: | + echo "ANDROID_HOME=$ANDROID_HOME" >> $GITHUB_ENV + echo "PATH=$ANDROID_HOME/emulator:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH" >> $GITHUB_ENV - - name: Accept Android Licenses + - name: Accept licenses run: yes | sdkmanager --licenses - - name: Create AVD (if not exists) - run: | - AVD_NAME="detox_pixel_4_xl_api_31" - if ! emulator -list-avds | grep -q "$AVD_NAME"; then - echo "Creating new AVD..." - echo "no" | avdmanager create avd --force --name "$AVD_NAME" --package "system-images;android-31;default;arm64-v8a" --device "pixel_4_xl" - else - echo "AVD already exists." - fi - - - name: Start Emulator with Correct Binary + - name: Install required SDK components run: | - AVD_NAME="detox_pixel_4_xl_api_31" - EMULATOR_PATH="$ANDROID_HOME/emulator/emulator" + sdkmanager "system-images;android-34;google_apis;arm64-v8a" - echo "Starting emulator with binary: $EMULATOR_PATH" - "$EMULATOR_PATH" -avd "$AVD_NAME" -no-window -no-audio -no-boot-anim -gpu swiftshader_indirect -no-snapshot & + - name: Create AVD + run: | + echo "no" | avdmanager create avd --force --name detox_pixel_4_xl_api_34_arm --package "system-images;android-34;google_apis;arm64-v8a" --device "pixel_4_xl" + - name: Start emulator + run: | + emulator -avd detox_pixel_4_xl_api_34_arm -no-window -no-audio -no-boot-anim -gpu swiftshader_indirect -no-snapshot & adb wait-for-device while [[ "$(adb shell getprop sys.boot_completed)" != "1" ]]; do sleep 2 From d807e43c791b367f69ef46ba63f069e8b0b2dea5 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 10:07:52 +0530 Subject: [PATCH 18/98] Java 8 --- .github/workflows/e2e-android-detox.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index d7988101855..4479edaf8e6 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -75,6 +75,12 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} + - name: Set up JDK 8 + uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'adopt' + # - name: Download APK artifact # uses: actions/download-artifact@v4 # with: From 7598bd3fd599169295888e4621e79cf6b3516bf1 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 10:09:29 +0530 Subject: [PATCH 19/98] Java 8 zulu distribution --- .github/workflows/e2e-android-detox.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 4479edaf8e6..a28548dca81 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -79,7 +79,7 @@ jobs: uses: actions/setup-java@v3 with: java-version: '8' - distribution: 'adopt' + distribution: 'zulu' # - name: Download APK artifact # uses: actions/download-artifact@v4 From 170fc1664919e3934e4845f1a756d44d0bc2d681 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 10:43:11 +0530 Subject: [PATCH 20/98] use asop --- .github/workflows/e2e-android-detox.yml | 38 +++++++++++-------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index a28548dca81..fca3c2ceb04 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -69,6 +69,12 @@ jobs: # if: github.event.label.name == 'E2E Android tests for PR' # needs: build-android-apk runs-on: macos-14 + + env: + SDK_VERSION: 31 + AVD_NAME: "detox_pixel_4_xl_api_31" + ARCH: "x86_64" + steps: - name: ci/checkout-repo uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 @@ -122,30 +128,20 @@ jobs: with: node-version: '18' - - name: Set up Android environment - run: | - echo "ANDROID_HOME=$ANDROID_HOME" >> $GITHUB_ENV - echo "PATH=$ANDROID_HOME/emulator:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH" >> $GITHUB_ENV - - - name: Accept licenses - run: yes | sdkmanager --licenses - - - name: Install required SDK components - run: | - sdkmanager "system-images;android-34;google_apis;arm64-v8a" - - - name: Create AVD + - name: Install Android SDK and AOSP Emulator run: | - echo "no" | avdmanager create avd --force --name detox_pixel_4_xl_api_34_arm --package "system-images;android-34;google_apis;arm64-v8a" --device "pixel_4_xl" + echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --install emulator + echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager "system-images;android-${SDK_VERSION};default;${ARCH}" + echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --licenses + $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager create avd -n ${AVD_NAME} -d pixel --package "system-images;android-${SDK_VERSION};default;${ARCH}" - - name: Start emulator + - name: Start AOSP Emulator run: | - emulator -avd detox_pixel_4_xl_api_34_arm -no-window -no-audio -no-boot-anim -gpu swiftshader_indirect -no-snapshot & - adb wait-for-device - while [[ "$(adb shell getprop sys.boot_completed)" != "1" ]]; do - sleep 2 - done - echo "Emulator is ready." + nohup $ANDROID_HOME/emulator/emulator -avd ${AVD_NAME} -no-audio -no-window -no-snapshot > /dev/null 2>&1 & + adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;' + adb shell settings put global window_animation_scale 0 + adb shell settings put global transition_animation_scale 0 + adb shell settings put global animator_duration_scale 0 - name: Run Detox tests run: | From 8e66c481b5e8c1f60d9a5ee50100a1dfc075b75b Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 10:45:28 +0530 Subject: [PATCH 21/98] java 11 and asop --- .github/workflows/e2e-android-detox.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index fca3c2ceb04..cbc89756b4c 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -128,6 +128,12 @@ jobs: with: node-version: '18' + - name: Set up Java 11 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '11' + - name: Install Android SDK and AOSP Emulator run: | echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --install emulator From 196c32d309dcdd39f0b26a9ed54fb91d22c4bc25 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 10:47:30 +0530 Subject: [PATCH 22/98] java 17 and asop --- .github/workflows/e2e-android-detox.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index cbc89756b4c..5a9a567029e 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -132,7 +132,7 @@ jobs: uses: actions/setup-java@v4 with: distribution: 'temurin' - java-version: '11' + java-version: '17' - name: Install Android SDK and AOSP Emulator run: | From 16e8e974716b4e9d13310498330582d60674302b Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 10:54:56 +0530 Subject: [PATCH 23/98] wait for emulator --- .github/workflows/e2e-android-detox.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 5a9a567029e..ca84eaaf1f8 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -143,7 +143,19 @@ jobs: - name: Start AOSP Emulator run: | - nohup $ANDROID_HOME/emulator/emulator -avd ${AVD_NAME} -no-audio -no-window -no-snapshot > /dev/null 2>&1 & + nohup $ANDROID_HOME/emulator/emulator -avd ${AVD_NAME} -no-audio -no-window -no-snapshot -gpu swiftshader_indirect -verbose > emulator.log 2>&1 & + echo "Waiting for emulator to start..." + timeout=600 # 10 minutes timeout + while [[ $(adb devices | grep emulator | wc -l) -eq 0 ]]; do + sleep 5 + timeout=$((timeout - 5)) + if [[ $timeout -le 0 ]]; then + echo "Emulator failed to start within time limit." + cat emulator.log + exit 1 + fi + done + echo "Emulator is up and running." adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;' adb shell settings put global window_animation_scale 0 adb shell settings put global transition_animation_scale 0 From ae09543e030e98062f588bff957536142ee250ed Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 10:58:22 +0530 Subject: [PATCH 24/98] with google_apis --- .github/workflows/e2e-android-detox.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index ca84eaaf1f8..112c8bd8bdf 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -137,13 +137,13 @@ jobs: - name: Install Android SDK and AOSP Emulator run: | echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --install emulator - echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager "system-images;android-${SDK_VERSION};default;${ARCH}" + echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager "system-images;android-${SDK_VERSION};google_apis;${ARCH}" echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --licenses - $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager create avd -n ${AVD_NAME} -d pixel --package "system-images;android-${SDK_VERSION};default;${ARCH}" + $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager create avd -n ${AVD_NAME} -d pixel --package "system-images;android-${SDK_VERSION};google_apis;${ARCH}" - name: Start AOSP Emulator run: | - nohup $ANDROID_HOME/emulator/emulator -avd ${AVD_NAME} -no-audio -no-window -no-snapshot -gpu swiftshader_indirect -verbose > emulator.log 2>&1 & + nohup $ANDROID_HOME/emulator/emulator -avd ${AVD_NAME} -no-audio -no-snapshot -gpu swiftshader_indirect -verbose > emulator.log 2>&1 & echo "Waiting for emulator to start..." timeout=600 # 10 minutes timeout while [[ $(adb devices | grep emulator | wc -l) -eq 0 ]]; do @@ -160,7 +160,7 @@ jobs: adb shell settings put global window_animation_scale 0 adb shell settings put global transition_animation_scale 0 adb shell settings put global animator_duration_scale 0 - + - name: Run Detox tests run: | cd detox From f978fcbbcf3b4f81ff309eb6dd5bf8eb9c1331f6 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 11:14:10 +0530 Subject: [PATCH 25/98] with google_apis_playstore --- .github/workflows/e2e-android-detox.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 112c8bd8bdf..139ad853a69 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -73,7 +73,7 @@ jobs: env: SDK_VERSION: 31 AVD_NAME: "detox_pixel_4_xl_api_31" - ARCH: "x86_64" + ARCH: "arm64-v8a" steps: - name: ci/checkout-repo @@ -137,15 +137,15 @@ jobs: - name: Install Android SDK and AOSP Emulator run: | echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --install emulator - echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager "system-images;android-${SDK_VERSION};google_apis;${ARCH}" + echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager "system-images;android-${SDK_VERSION};google_apis_playstore;${ARCH}" echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --licenses - $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager create avd -n ${AVD_NAME} -d pixel --package "system-images;android-${SDK_VERSION};google_apis;${ARCH}" + $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager create avd -n ${AVD_NAME} -d pixel --package "system-images;android-${SDK_VERSION};google_apis_playstore;${ARCH}" - name: Start AOSP Emulator run: | - nohup $ANDROID_HOME/emulator/emulator -avd ${AVD_NAME} -no-audio -no-snapshot -gpu swiftshader_indirect -verbose > emulator.log 2>&1 & + nohup $ANDROID_HOME/emulator/emulator -avd ${AVD_NAME} -no-audio -no-window -no-snapshot -gpu swiftshader_indirect -verbose > emulator.log 2>&1 & echo "Waiting for emulator to start..." - timeout=600 # 10 minutes timeout + timeout=300 # 5 minutes timeout while [[ $(adb devices | grep emulator | wc -l) -eq 0 ]]; do sleep 5 timeout=$((timeout - 5)) @@ -160,7 +160,7 @@ jobs: adb shell settings put global window_animation_scale 0 adb shell settings put global transition_animation_scale 0 adb shell settings put global animator_duration_scale 0 - + - name: Run Detox tests run: | cd detox From 421efef06d2b470a95e4b16f6696d752581969f0 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 11:26:33 +0530 Subject: [PATCH 26/98] with accel off --- .github/workflows/e2e-android-detox.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 139ad853a69..ccd722952aa 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -143,7 +143,7 @@ jobs: - name: Start AOSP Emulator run: | - nohup $ANDROID_HOME/emulator/emulator -avd ${AVD_NAME} -no-audio -no-window -no-snapshot -gpu swiftshader_indirect -verbose > emulator.log 2>&1 & + nohup $ANDROID_HOME/emulator/emulator -avd ${AVD_NAME} -no-audio -no-window -no-snapshot -gpu swiftshader_indirect -accel off -verbose > emulator.log 2>&1 & echo "Waiting for emulator to start..." timeout=300 # 5 minutes timeout while [[ $(adb devices | grep emulator | wc -l) -eq 0 ]]; do From 569944c658e1f128def36978bc8cef318b9d8010 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 11:39:24 +0530 Subject: [PATCH 27/98] with hvf --- .github/workflows/e2e-android-detox.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index ccd722952aa..7babf649417 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -143,9 +143,12 @@ jobs: - name: Start AOSP Emulator run: | - nohup $ANDROID_HOME/emulator/emulator -avd ${AVD_NAME} -no-audio -no-window -no-snapshot -gpu swiftshader_indirect -accel off -verbose > emulator.log 2>&1 & + nohup $ANDROID_HOME/emulator/emulator -avd ${AVD_NAME} \ + -no-audio -no-window -no-snapshot -gpu swiftshader_indirect \ + -qemu -accel tcg -verbose > emulator.log 2>&1 & + echo "Waiting for emulator to start..." - timeout=300 # 5 minutes timeout + timeout=600 # Increased timeout to 10 minutes while [[ $(adb devices | grep emulator | wc -l) -eq 0 ]]; do sleep 5 timeout=$((timeout - 5)) From c666be8cb061ba3484fe31ef79e813d14a9eeac9 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 12:38:29 +0530 Subject: [PATCH 28/98] set 2 cores --- .github/workflows/e2e-android-detox.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 7babf649417..8311d4fc86e 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -144,8 +144,8 @@ jobs: - name: Start AOSP Emulator run: | nohup $ANDROID_HOME/emulator/emulator -avd ${AVD_NAME} \ - -no-audio -no-window -no-snapshot -gpu swiftshader_indirect \ - -qemu -accel tcg -verbose > emulator.log 2>&1 & + -no-audio -no-window -no-snapshot -gpu off \ + -cores 2 -accel off > emulator.log 2>&1 & echo "Waiting for emulator to start..." timeout=600 # Increased timeout to 10 minutes From 8b8344a21280f6481a767282f395fb0c7d658d27 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 13:00:41 +0530 Subject: [PATCH 29/98] accel off --- .github/workflows/e2e-android-detox.yml | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 8311d4fc86e..f3961f497c1 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -73,7 +73,7 @@ jobs: env: SDK_VERSION: 31 AVD_NAME: "detox_pixel_4_xl_api_31" - ARCH: "arm64-v8a" + ARCH: "x86_64" steps: - name: ci/checkout-repo @@ -81,12 +81,6 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} - - name: Set up JDK 8 - uses: actions/setup-java@v3 - with: - java-version: '8' - distribution: 'zulu' - # - name: Download APK artifact # uses: actions/download-artifact@v4 # with: @@ -137,15 +131,15 @@ jobs: - name: Install Android SDK and AOSP Emulator run: | echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --install emulator - echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager "system-images;android-${SDK_VERSION};google_apis_playstore;${ARCH}" + echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager "system-images;android-${SDK_VERSION};google_apis;x86_64" echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --licenses - $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager create avd -n ${AVD_NAME} -d pixel --package "system-images;android-${SDK_VERSION};google_apis_playstore;${ARCH}" + $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager create avd -n ${AVD_NAME} -d pixel --package "system-images;android-${SDK_VERSION};google_apis;x86_64" - name: Start AOSP Emulator run: | nohup $ANDROID_HOME/emulator/emulator -avd ${AVD_NAME} \ - -no-audio -no-window -no-snapshot -gpu off \ - -cores 2 -accel off > emulator.log 2>&1 & + -no-audio -no-window -no-snapshot -gpu off -accel off \ + -cores 2 > emulator.log 2>&1 & echo "Waiting for emulator to start..." timeout=600 # Increased timeout to 10 minutes From 380857b128700d03fa2210cdf68ed699ed1cbf96 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 13:31:30 +0530 Subject: [PATCH 30/98] macos-13 --- .github/workflows/e2e-android-detox.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index f3961f497c1..b182d2f48c6 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -68,7 +68,7 @@ jobs: run-android-tests: # if: github.event.label.name == 'E2E Android tests for PR' # needs: build-android-apk - runs-on: macos-14 + runs-on: macos-13 env: SDK_VERSION: 31 @@ -138,8 +138,7 @@ jobs: - name: Start AOSP Emulator run: | nohup $ANDROID_HOME/emulator/emulator -avd ${AVD_NAME} \ - -no-audio -no-window -no-snapshot -gpu off -accel off \ - -cores 2 > emulator.log 2>&1 & + -no-audio -no-window -no-snapshot -gpu off -accel off -cores 2 > emulator.log 2>&1 & echo "Waiting for emulator to start..." timeout=600 # Increased timeout to 10 minutes From 7b67af05512b9e4fbe0da5860aaff30b45873eaf Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 22:07:06 +0530 Subject: [PATCH 31/98] restart adb server --- .github/workflows/e2e-android-detox.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index b182d2f48c6..227753718a0 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -128,6 +128,12 @@ jobs: distribution: 'temurin' java-version: '17' + - name: Restart ADB + run: | + adb kill-server + adb start-server + adb devices + - name: Install Android SDK and AOSP Emulator run: | echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --install emulator From 821a0cd400531fdf1671fbcf6192a5fb54802600 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 22:11:53 +0530 Subject: [PATCH 32/98] use reactivecircus/android-emulator-runner@v2 --- .github/workflows/e2e-android-detox.yml | 46 +++++++++++-------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 227753718a0..f869fcffb43 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -128,40 +128,36 @@ jobs: distribution: 'temurin' java-version: '17' - - name: Restart ADB + - name: Install Android Dependencies run: | - adb kill-server - adb start-server - adb devices + echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install "platform-tools" "platforms;android-31" "emulator" - - name: Install Android SDK and AOSP Emulator - run: | - echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --install emulator - echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager "system-images;android-${SDK_VERSION};google_apis;x86_64" - echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --licenses - $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager create avd -n ${AVD_NAME} -d pixel --package "system-images;android-${SDK_VERSION};google_apis;x86_64" - - - name: Start AOSP Emulator + - name: Start Android Emulator + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: 31 + target: google_apis + arch: x86_64 + profile: pixel_4 + disable-animations: true + avd-name: ${{ env.AVD_NAME }} + script: echo "Emulator is ready" + + - name: Verify Emulator is Running + run: adb devices + + - name: Wait for Emulator to Fully Boot run: | - nohup $ANDROID_HOME/emulator/emulator -avd ${AVD_NAME} \ - -no-audio -no-window -no-snapshot -gpu off -accel off -cores 2 > emulator.log 2>&1 & - - echo "Waiting for emulator to start..." - timeout=600 # Increased timeout to 10 minutes - while [[ $(adb devices | grep emulator | wc -l) -eq 0 ]]; do + timeout=300 # 5 minutes max + while [[ -z $(adb shell getprop sys.boot_completed) ]]; do sleep 5 timeout=$((timeout - 5)) if [[ $timeout -le 0 ]]; then - echo "Emulator failed to start within time limit." - cat emulator.log + echo "Emulator failed to boot within time limit." exit 1 fi done - echo "Emulator is up and running." - adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;' - adb shell settings put global window_animation_scale 0 - adb shell settings put global transition_animation_scale 0 - adb shell settings put global animator_duration_scale 0 + echo "Emulator fully booted." - name: Run Detox tests run: | From 22c608724c6639d36e47264e5d277714ab6d596c Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Fri, 31 Jan 2025 23:50:13 +0530 Subject: [PATCH 33/98] use reactivecircus/android-emulator-runner@v2 with no snapshot --- .github/workflows/e2e-android-detox.yml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index f869fcffb43..7eddd590de9 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -141,24 +141,12 @@ jobs: profile: pixel_4 disable-animations: true avd-name: ${{ env.AVD_NAME }} + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none script: echo "Emulator is ready" - name: Verify Emulator is Running run: adb devices - - name: Wait for Emulator to Fully Boot - run: | - timeout=300 # 5 minutes max - while [[ -z $(adb shell getprop sys.boot_completed) ]]; do - sleep 5 - timeout=$((timeout - 5)) - if [[ $timeout -le 0 ]]; then - echo "Emulator failed to boot within time limit." - exit 1 - fi - done - echo "Emulator fully booted." - - name: Run Detox tests run: | cd detox From d7a12797c0cbcfbca387d90d736a0b656020ad93 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sat, 1 Feb 2025 00:08:54 +0530 Subject: [PATCH 34/98] remove reactivecircus --- .github/workflows/e2e-android-detox.yml | 40 ++++++++++++++++++------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 7eddd590de9..cf8686b0ebd 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -131,18 +131,38 @@ jobs: - name: Install Android Dependencies run: | echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install "platform-tools" "platforms;android-31" "emulator" + echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "system-images;android-31;google_apis;x86_64" + echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses + + - name: Create Android Emulator + run: | + $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd \ + -n ${{ env.AVD_NAME }} \ + -k "system-images;android-31;google_apis;x86_64" \ + -d pixel - name: Start Android Emulator - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: 31 - target: google_apis - arch: x86_64 - profile: pixel_4 - disable-animations: true - avd-name: ${{ env.AVD_NAME }} - emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none - script: echo "Emulator is ready" + run: | + nohup $ANDROID_HOME/emulator/emulator -avd ${{ env.AVD_NAME }} \ + -no-audio -no-window -no-snapshot -gpu swiftshader_indirect \ + -cores 2 -accel off > emulator.log 2>&1 & + + echo "Waiting for emulator to start..." + timeout=600 # 10 minutes timeout + while [[ $(adb devices | grep emulator | wc -l) -eq 0 ]]; do + sleep 5 + timeout=$((timeout - 5)) + if [[ $timeout -le 0 ]]; then + echo "Emulator failed to start within time limit." + cat emulator.log + exit 1 + fi + done + echo "Emulator is up and running." + adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;' + adb shell settings put global window_animation_scale 0 + adb shell settings put global transition_animation_scale 0 + adb shell settings put global animator_duration_scale 0 - name: Verify Emulator is Running run: adb devices From f3befdef1a74b3839f91a97be493a3ae0a37d685 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sat, 1 Feb 2025 05:05:46 +0530 Subject: [PATCH 35/98] try reactivecircus again with options --- .github/workflows/e2e-android-detox.yml | 90 ++++++++++++------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index cf8686b0ebd..9b0d472c989 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -128,48 +128,48 @@ jobs: distribution: 'temurin' java-version: '17' - - name: Install Android Dependencies - run: | - echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install "platform-tools" "platforms;android-31" "emulator" - echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "system-images;android-31;google_apis;x86_64" - echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses - - - name: Create Android Emulator - run: | - $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd \ - -n ${{ env.AVD_NAME }} \ - -k "system-images;android-31;google_apis;x86_64" \ - -d pixel - - - name: Start Android Emulator - run: | - nohup $ANDROID_HOME/emulator/emulator -avd ${{ env.AVD_NAME }} \ - -no-audio -no-window -no-snapshot -gpu swiftshader_indirect \ - -cores 2 -accel off > emulator.log 2>&1 & - - echo "Waiting for emulator to start..." - timeout=600 # 10 minutes timeout - while [[ $(adb devices | grep emulator | wc -l) -eq 0 ]]; do - sleep 5 - timeout=$((timeout - 5)) - if [[ $timeout -le 0 ]]; then - echo "Emulator failed to start within time limit." - cat emulator.log - exit 1 - fi - done - echo "Emulator is up and running." - adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;' - adb shell settings put global window_animation_scale 0 - adb shell settings put global transition_animation_scale 0 - adb shell settings put global animator_duration_scale 0 - - - name: Verify Emulator is Running - run: adb devices - - - name: Run Detox tests - run: | - cd detox - npm install - npm install -g detox-cli - npm run e2e:android-test -- about.e2e.ts + - name: Create AVD and generate snapshot for caching + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: 31 + target: google_apis + arch: x86_64 + profile: Nexus 6 + cores: 2 + ram-size: 4096M + heap-size: 2048M + disk-size: 4096M + script: echo "Created AVD snapshot." + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -camera-front none + disable-animations: true + avd-name: ${{ env.AVD_NAME }} + + - name: Run Detox Tests + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: 31 + target: google_apis + arch: x86_64 + profile: Nexus 6 + cores: 2 + ram-size: 4096M + heap-size: 2048M + disk-size: 4096M + script: | + adb shell settings put global window_animation_scale 0 + adb shell settings put global transition_animation_scale 0 + adb shell settings put global animator_duration_scale 0 + cd detox + npm install + npm install -g detox-cli + npm run e2e:android-test -- about.e2e.ts + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -camera-front none + disable-animations: true + avd-name: ${{ env.AVD_NAME }} + + # - name: Run Detox tests + # run: | + # cd detox + # npm install + # npm install -g detox-cli + # npm run e2e:android-test -- about.e2e.ts From 4419d7238268fc8597574f8334cefdc1b90d8529 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sat, 1 Feb 2025 05:28:51 +0530 Subject: [PATCH 36/98] add prepare-android-build step --- .github/workflows/e2e-android-detox.yml | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 9b0d472c989..3c9784c4890 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -81,6 +81,14 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} + - name: ci/prepare-android-build + uses: ./.github/actions/prepare-android-build + env: + STORE_FILE: "${{ secrets.MM_MOBILE_STORE_FILE }}" + STORE_ALIAS: "${{ secrets.MM_MOBILE_STORE_ALIAS }}" + STORE_PASSWORD: "${{ secrets.MM_MOBILE_STORE_PASSWORD }}" + MATTERMOST_BUILD_GH_TOKEN: "${{ secrets.MATTERMOST_BUILD_GH_TOKEN }}" + # - name: Download APK artifact # uses: actions/download-artifact@v4 # with: @@ -117,17 +125,6 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: ${{ runner.os }}-gradle- - - name: Install Node.js - uses: actions/setup-node@v3 - with: - node-version: '18' - - - name: Set up Java 11 - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '17' - - name: Create AVD and generate snapshot for caching uses: reactivecircus/android-emulator-runner@v2 with: From 1e245110aede4343f8b9ee459093a233851731e4 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sat, 1 Feb 2025 06:00:16 +0530 Subject: [PATCH 37/98] custom avd creation --- .github/workflows/e2e-android-detox.yml | 124 ++++++++++++++++-------- 1 file changed, 86 insertions(+), 38 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 3c9784c4890..f91b80b7403 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -125,44 +125,92 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: ${{ runner.os }}-gradle- - - name: Create AVD and generate snapshot for caching - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: 31 - target: google_apis - arch: x86_64 - profile: Nexus 6 - cores: 2 - ram-size: 4096M - heap-size: 2048M - disk-size: 4096M - script: echo "Created AVD snapshot." - emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -camera-front none - disable-animations: true - avd-name: ${{ env.AVD_NAME }} - - - name: Run Detox Tests - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: 31 - target: google_apis - arch: x86_64 - profile: Nexus 6 - cores: 2 - ram-size: 4096M - heap-size: 2048M - disk-size: 4096M - script: | - adb shell settings put global window_animation_scale 0 - adb shell settings put global transition_animation_scale 0 - adb shell settings put global animator_duration_scale 0 - cd detox - npm install - npm install -g detox-cli - npm run e2e:android-test -- about.e2e.ts - emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -camera-front none - disable-animations: true - avd-name: ${{ env.AVD_NAME }} + - name: Setup Android SDK + run: | + # Accept licenses first + yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses + + # Install required packages + echo "Installing system image..." + $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install \ + "system-images;android-31;google_apis;x86_64" \ + "platform-tools" \ + "platforms;android-31" \ + "emulator" + + # Kill any existing ADB server + $ANDROID_HOME/platform-tools/adb kill-server || true + + # Start ADB server as root + sudo $ANDROID_HOME/platform-tools/adb start-server + + - name: Create and start emulator + run: | + # Create AVD + echo "no" | $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd \ + -n ${{ env.AVD_NAME }} \ + -k "system-images;android-31;google_apis;x86_64" \ + --force \ + --device "pixel_2" + + # Start ADB server first + $ANDROID_HOME/platform-tools/adb start-server + + # Export required environment variables + export QEMU_AUDIO_DRV=none + export ANDROID_SDK_ROOT=$ANDROID_HOME + + # Start emulator with specific configurations + $ANDROID_HOME/emulator/emulator \ + -avd ${{ env.AVD_NAME }} \ + -no-window \ + -no-snapshot \ + -no-audio \ + -no-boot-anim \ + -camera-back none \ + -camera-front none \ + -gpu swiftshader_indirect \ + -memory 4096 \ + -accel off \ + -cores 2 & + + # Wait for device to be available first + adb wait-for-device + + # More robust boot completion check + BOOT_COMPLETE=false + for i in {1..60}; do + if adb shell getprop sys.boot_completed 2>&1 | grep -q '1'; then + BOOT_COMPLETE=true + break + fi + + # Check ADB server status and restart if needed + if ! adb get-state 1>/dev/null 2>&1; then + echo "ADB server not responding, restarting..." + adb kill-server + adb start-server + fi + + echo "Waiting for boot complete... ($i/60)" + sleep 5 + done + + if [ "$BOOT_COMPLETE" = false ]; then + echo "Failed to boot emulator" + adb logcat -d + exit 1 + fi + + # Additional device setup + adb shell settings put global window_animation_scale 0 + adb shell settings put global transition_animation_scale 0 + adb shell settings put global animator_duration_scale 0 + + # Run tests + cd detox + npm install + npm run e2e:android-test -- about.e2e.ts # - name: Run Detox tests # run: | From 065d6e48b391c58d2151db52d1803853e6dbea0a Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sat, 1 Feb 2025 06:24:37 +0530 Subject: [PATCH 38/98] custom avd creation --- .github/workflows/e2e-android-detox.yml | 35 ++++++++++++++++--------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index f91b80b7403..b7a9aca427d 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -152,16 +152,16 @@ jobs: -k "system-images;android-31;google_apis;x86_64" \ --force \ --device "pixel_2" - + # Start ADB server first $ANDROID_HOME/platform-tools/adb start-server - + # Export required environment variables export QEMU_AUDIO_DRV=none export ANDROID_SDK_ROOT=$ANDROID_HOME # Start emulator with specific configurations - $ANDROID_HOME/emulator/emulator \ + nohup $ANDROID_HOME/emulator/emulator \ -avd ${{ env.AVD_NAME }} \ -no-window \ -no-snapshot \ @@ -172,11 +172,22 @@ jobs: -gpu swiftshader_indirect \ -memory 4096 \ -accel off \ - -cores 2 & - + -cores 2 > emulator.log 2>&1 & + # Wait for device to be available first - adb wait-for-device - + echo "Waiting for emulator to start..." + timeout=600 # 10 minutes timeout + while [[ $(adb devices | grep emulator | wc -l) -eq 0 ]]; do + sleep 5 + timeout=$((timeout - 5)) + if [[ $timeout -le 0 ]]; then + echo "Emulator failed to start within time limit." + cat emulator.log + exit 1 + fi + done + echo "Emulator is up and running." + # More robust boot completion check BOOT_COMPLETE=false for i in {1..60}; do @@ -184,34 +195,32 @@ jobs: BOOT_COMPLETE=true break fi - + # Check ADB server status and restart if needed if ! adb get-state 1>/dev/null 2>&1; then echo "ADB server not responding, restarting..." adb kill-server adb start-server fi - + echo "Waiting for boot complete... ($i/60)" sleep 5 done - + if [ "$BOOT_COMPLETE" = false ]; then echo "Failed to boot emulator" adb logcat -d exit 1 fi - + # Additional device setup adb shell settings put global window_animation_scale 0 adb shell settings put global transition_animation_scale 0 adb shell settings put global animator_duration_scale 0 - # Run tests cd detox npm install npm run e2e:android-test -- about.e2e.ts - # - name: Run Detox tests # run: | # cd detox From 736663a7fc96c9410b2d03bd1eedc41fc2ead625 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sat, 1 Feb 2025 06:40:51 +0530 Subject: [PATCH 39/98] custom avd creation --- .github/workflows/e2e-android-detox.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index b7a9aca427d..d72ce720494 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -138,9 +138,10 @@ jobs: "platforms;android-31" \ "emulator" - # Kill any existing ADB server + # Kill any existing ADB server and free port 5037 $ANDROID_HOME/platform-tools/adb kill-server || true - + lsof -ti:5037 | xargs kill -9 || true + # Start ADB server as root sudo $ANDROID_HOME/platform-tools/adb start-server From 07882e611c4e0521f5d0416a8d48368d5f728ab0 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sat, 1 Feb 2025 07:00:04 +0530 Subject: [PATCH 40/98] kill and start adb server --- .github/workflows/e2e-android-detox.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index d72ce720494..ac92df36c18 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -125,11 +125,17 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: ${{ runner.os }}-gradle- + - name: Kill Existing ADB Processes + run: | + adb kill-server || true + lsof -ti:5037 | xargs kill -9 || true + sleep 10 # Give some time for the port to free up + - name: Setup Android SDK run: | # Accept licenses first yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses - + # Install required packages echo "Installing system image..." $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install \ @@ -221,10 +227,4 @@ jobs: cd detox npm install - npm run e2e:android-test -- about.e2e.ts - # - name: Run Detox tests - # run: | - # cd detox - # npm install - # npm install -g detox-cli - # npm run e2e:android-test -- about.e2e.ts + npm run e2e:android-test -- about.e2e.ts \ No newline at end of file From ad141f25031227b28969493d14e72cc8f573c8f3 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sat, 1 Feb 2025 07:19:26 +0530 Subject: [PATCH 41/98] agressive adb clean up --- .github/workflows/e2e-android-detox.yml | 82 ++++++++++++++++--------- 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index ac92df36c18..3ac0cdc5202 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -125,13 +125,7 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: ${{ runner.os }}-gradle- - - name: Kill Existing ADB Processes - run: | - adb kill-server || true - lsof -ti:5037 | xargs kill -9 || true - sleep 10 # Give some time for the port to free up - - - name: Setup Android SDK + - name: Setup Android SDK and ADB run: | # Accept licenses first yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses @@ -144,13 +138,24 @@ jobs: "platforms;android-31" \ "emulator" - # Kill any existing ADB server and free port 5037 - $ANDROID_HOME/platform-tools/adb kill-server || true + # More aggressive cleanup of ADB and port 5037 + echo "Cleaning up ADB processes..." + ps aux | grep adb | grep -v grep | awk '{print $2}' | xargs kill -9 || true lsof -ti:5037 | xargs kill -9 || true - # Start ADB server as root + # Remove ADB server files + rm -f $HOME/.android/adb.pid + rm -f $HOME/.android/adb.log + + # Wait for port to be fully released + sleep 5 + + # Start fresh ADB server sudo $ANDROID_HOME/platform-tools/adb start-server + # Verify ADB is running properly + $ANDROID_HOME/platform-tools/adb devices + - name: Create and start emulator run: | # Create AVD @@ -160,14 +165,18 @@ jobs: --force \ --device "pixel_2" - # Start ADB server first - $ANDROID_HOME/platform-tools/adb start-server + # Double check ADB server status + echo "Ensuring ADB server is running properly..." + $ANDROID_HOME/platform-tools/adb kill-server || true + sleep 2 + sudo $ANDROID_HOME/platform-tools/adb start-server # Export required environment variables export QEMU_AUDIO_DRV=none export ANDROID_SDK_ROOT=$ANDROID_HOME # Start emulator with specific configurations + echo "Starting emulator..." nohup $ANDROID_HOME/emulator/emulator \ -avd ${{ env.AVD_NAME }} \ -no-window \ @@ -181,50 +190,67 @@ jobs: -accel off \ -cores 2 > emulator.log 2>&1 & - # Wait for device to be available first + # Initial wait for emulator process + sleep 5 + + # Wait for device to be available echo "Waiting for emulator to start..." timeout=600 # 10 minutes timeout - while [[ $(adb devices | grep emulator | wc -l) -eq 0 ]]; do - sleep 5 + while true; do + if [[ $(adb devices | grep -w "device" | wc -l) -gt 0 ]]; then + echo "Emulator detected!" + break + fi + timeout=$((timeout - 5)) if [[ $timeout -le 0 ]]; then echo "Emulator failed to start within time limit." + echo "Emulator log:" cat emulator.log + echo "ADB devices output:" + adb devices + echo "Process list:" + ps aux | grep emulator exit 1 fi + + # Check if adb server is still running + if ! pgrep -f "adb" > /dev/null; then + echo "ADB server died, restarting..." + sudo $ANDROID_HOME/platform-tools/adb start-server + fi + + sleep 5 + echo "Still waiting... ($timeout seconds remaining)" done - echo "Emulator is up and running." - # More robust boot completion check + # Boot completion check + echo "Checking boot completion..." BOOT_COMPLETE=false for i in {1..60}; do if adb shell getprop sys.boot_completed 2>&1 | grep -q '1'; then BOOT_COMPLETE=true break fi - - # Check ADB server status and restart if needed - if ! adb get-state 1>/dev/null 2>&1; then - echo "ADB server not responding, restarting..." - adb kill-server - adb start-server - fi - + echo "Waiting for boot complete... ($i/60)" sleep 5 done - + if [ "$BOOT_COMPLETE" = false ]; then echo "Failed to boot emulator" + echo "Emulator log:" + cat emulator.log + echo "System log:" adb logcat -d exit 1 fi - + # Additional device setup adb shell settings put global window_animation_scale 0 adb shell settings put global transition_animation_scale 0 adb shell settings put global animator_duration_scale 0 - + cd detox npm install npm run e2e:android-test -- about.e2e.ts \ No newline at end of file From b1bcf1e554af08d791ad2fea9c14f8beb8b38ff4 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sat, 1 Feb 2025 13:02:39 +0530 Subject: [PATCH 42/98] try linux --- .github/workflows/e2e-android-detox.yml | 165 ++++++------------------ 1 file changed, 38 insertions(+), 127 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 3ac0cdc5202..18967be592b 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -68,13 +68,18 @@ jobs: run-android-tests: # if: github.event.label.name == 'E2E Android tests for PR' # needs: build-android-apk - runs-on: macos-13 + runs-on: ubuntu-latest-8-cores env: SDK_VERSION: 31 AVD_NAME: "detox_pixel_4_xl_api_31" ARCH: "x86_64" - + ANDROID_HOME: /usr/local/lib/android/sdk + ANDROID_SDK_ROOT: /usr/local/lib/android/sdk + ANDROID_NDK_ROOT: /usr/local/lib/android/sdk/ndk/27.2.12479018 + ADB_INSTALL_TIMEOUT: 10 + DETOX_LOGLEVEL: trace + steps: - name: ci/checkout-repo uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 @@ -118,139 +123,45 @@ jobs: find android/app/build -type f rm android/app/build/outputs/apk/artifact.zip - - name: Cache Gradle dependencies - uses: actions/cache@v4 - with: - path: ~/.gradle/caches/modules-2/ - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: ${{ runner.os }}-gradle- - - - name: Setup Android SDK and ADB + - name: Start Server run: | - # Accept licenses first - yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses - - # Install required packages - echo "Installing system image..." - $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install \ - "system-images;android-31;google_apis;x86_64" \ - "platform-tools" \ - "platforms;android-31" \ - "emulator" - - # More aggressive cleanup of ADB and port 5037 - echo "Cleaning up ADB processes..." - ps aux | grep adb | grep -v grep | awk '{print $2}' | xargs kill -9 || true - lsof -ti:5037 | xargs kill -9 || true - - # Remove ADB server files - rm -f $HOME/.android/adb.pid - rm -f $HOME/.android/adb.log + npm run start & - # Wait for port to be fully released - sleep 5 - - # Start fresh ADB server - sudo $ANDROID_HOME/platform-tools/adb start-server - - # Verify ADB is running properly - $ANDROID_HOME/platform-tools/adb devices - - - name: Create and start emulator + - name: Install Dependencies run: | - # Create AVD - echo "no" | $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd \ - -n ${{ env.AVD_NAME }} \ - -k "system-images;android-31;google_apis;x86_64" \ - --force \ - --device "pixel_2" + cd detox + npm install - # Double check ADB server status - echo "Ensuring ADB server is running properly..." - $ANDROID_HOME/platform-tools/adb kill-server || true - sleep 2 - sudo $ANDROID_HOME/platform-tools/adb start-server + - name: Create & Start Android Emulator + run: | + echo "Creating AVD..." + $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd -n $AVD_NAME -k "system-images;android-34;google_apis;x86_64" --device "pixel_6" --force - # Export required environment variables - export QEMU_AUDIO_DRV=none - export ANDROID_SDK_ROOT=$ANDROID_HOME - - # Start emulator with specific configurations echo "Starting emulator..." - nohup $ANDROID_HOME/emulator/emulator \ - -avd ${{ env.AVD_NAME }} \ - -no-window \ - -no-snapshot \ - -no-audio \ - -no-boot-anim \ - -camera-back none \ - -camera-front none \ - -gpu swiftshader_indirect \ - -memory 4096 \ - -accel off \ - -cores 2 > emulator.log 2>&1 & - - # Initial wait for emulator process - sleep 5 + nohup $ANDROID_HOME/emulator/emulator -avd $AVD_NAME -no-audio -no-boot-anim -no-window -gpu swiftshader_indirect -camera-back none -camera-front none -timezone UTC > emulator.log 2>&1 & - # Wait for device to be available echo "Waiting for emulator to start..." - timeout=600 # 10 minutes timeout - while true; do - if [[ $(adb devices | grep -w "device" | wc -l) -gt 0 ]]; then - echo "Emulator detected!" - break - fi - - timeout=$((timeout - 5)) - if [[ $timeout -le 0 ]]; then - echo "Emulator failed to start within time limit." - echo "Emulator log:" - cat emulator.log - echo "ADB devices output:" - adb devices - echo "Process list:" - ps aux | grep emulator - exit 1 - fi + adb wait-for-device shell 'timeout 300 sh -c "while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;"' - # Check if adb server is still running - if ! pgrep -f "adb" > /dev/null; then - echo "ADB server died, restarting..." - sudo $ANDROID_HOME/platform-tools/adb start-server - fi + echo "Emulator started successfully!" - sleep 5 - echo "Still waiting... ($timeout seconds remaining)" - done - - # Boot completion check - echo "Checking boot completion..." - BOOT_COMPLETE=false - for i in {1..60}; do - if adb shell getprop sys.boot_completed 2>&1 | grep -q '1'; then - BOOT_COMPLETE=true - break - fi - - echo "Waiting for boot complete... ($i/60)" - sleep 5 - done - - if [ "$BOOT_COMPLETE" = false ]; then - echo "Failed to boot emulator" - echo "Emulator log:" - cat emulator.log - echo "System log:" - adb logcat -d - exit 1 - fi - - # Additional device setup - adb shell settings put global window_animation_scale 0 - adb shell settings put global transition_animation_scale 0 - adb shell settings put global animator_duration_scale 0 - + - name: Run Detox E2E Tests + run: | cd detox - npm install - npm run e2e:android-test -- about.e2e.ts \ No newline at end of file + npm run e2e:android -- about.e2e.ts + + - name: Capture Logs on Failure + if: failure() + run: | + echo "Emulator Logs:" + cat emulator.log + echo "ADB Logcat Output:" + adb logcat -d > logcat_output.txt + cat logcat_output.txt + + - name: Upload Logs on Failure + if: failure() + uses: actions/upload-artifact@v4 + with: + name: detox-logs + path: logcat_output.txt From 1c84479ba487ed95d2fb4fa4d042a640920426bb Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sat, 1 Feb 2025 13:27:27 +0530 Subject: [PATCH 43/98] try linux --- .github/workflows/e2e-android-detox.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 18967be592b..5162748e9ad 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -71,7 +71,7 @@ jobs: runs-on: ubuntu-latest-8-cores env: - SDK_VERSION: 31 + SDK_VERSION: 34 AVD_NAME: "detox_pixel_4_xl_api_31" ARCH: "x86_64" ANDROID_HOME: /usr/local/lib/android/sdk @@ -123,6 +123,12 @@ jobs: find android/app/build -type f rm android/app/build/outputs/apk/artifact.zip + - name: Install Required Android System Image + run: | + echo "Installing Android System Image..." + sdkmanager --install "system-images;android-34;google_apis;x86_64" --sdk_root=$ANDROID_HOME + sdkmanager --licenses --sdk_root=$ANDROID_HOME + - name: Start Server run: | npm run start & From e907a4a9804850eb059fd667d24e35273e7a5966 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sat, 1 Feb 2025 13:31:32 +0530 Subject: [PATCH 44/98] install sdk --- .github/workflows/e2e-android-detox.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 5162748e9ad..26d145e858d 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -126,9 +126,9 @@ jobs: - name: Install Required Android System Image run: | echo "Installing Android System Image..." - sdkmanager --install "system-images;android-34;google_apis;x86_64" --sdk_root=$ANDROID_HOME - sdkmanager --licenses --sdk_root=$ANDROID_HOME - + /usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --install "system-images;android-34;google_apis;x86_64" --sdk_root=$ANDROID_HOME + /usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --licenses --sdk_root=$ANDROID_HOME + - name: Start Server run: | npm run start & From e2a584fd4dbe6e95481d3aeeaeb0e2a622733085 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sat, 1 Feb 2025 13:38:43 +0530 Subject: [PATCH 45/98] fix adb path --- .github/workflows/e2e-android-detox.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 26d145e858d..a507b406b08 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -129,6 +129,12 @@ jobs: /usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --install "system-images;android-34;google_apis;x86_64" --sdk_root=$ANDROID_HOME /usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --licenses --sdk_root=$ANDROID_HOME + - name: Add ADB to PATH + run: | + echo "Adding ADB to PATH..." + echo "$ANDROID_HOME/platform-tools" >> $GITHUB_PATH + echo "PATH updated: $PATH" + - name: Start Server run: | npm run start & @@ -147,7 +153,7 @@ jobs: nohup $ANDROID_HOME/emulator/emulator -avd $AVD_NAME -no-audio -no-boot-anim -no-window -gpu swiftshader_indirect -camera-back none -camera-front none -timezone UTC > emulator.log 2>&1 & echo "Waiting for emulator to start..." - adb wait-for-device shell 'timeout 300 sh -c "while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;"' + /usr/local/lib/android/sdk/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;' echo "Emulator started successfully!" From 6bb15906620cc994ceb351c1acf59901a81584b9 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sat, 1 Feb 2025 13:43:41 +0530 Subject: [PATCH 46/98] fix adb path --- .github/workflows/e2e-android-detox.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index a507b406b08..3e0b590a415 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -127,6 +127,7 @@ jobs: run: | echo "Installing Android System Image..." /usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --install "system-images;android-34;google_apis;x86_64" --sdk_root=$ANDROID_HOME + /usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --install "platform-tools" --sdk_root=$ANDROID_HOME /usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --licenses --sdk_root=$ANDROID_HOME - name: Add ADB to PATH @@ -135,6 +136,11 @@ jobs: echo "$ANDROID_HOME/platform-tools" >> $GITHUB_PATH echo "PATH updated: $PATH" + - name: Verify ADB Installation + run: | + ls -la /usr/local/lib/android/sdk/platform-tools/ + /usr/local/lib/android/sdk/platform-tools/adb version + - name: Start Server run: | npm run start & From 938bd11946ed0f6ce1613e805f34b734873e59a2 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sat, 1 Feb 2025 13:49:25 +0530 Subject: [PATCH 47/98] wait 5m for emulator to boot and run tests --- .github/workflows/e2e-android-detox.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 3e0b590a415..2433532eb64 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -159,15 +159,18 @@ jobs: nohup $ANDROID_HOME/emulator/emulator -avd $AVD_NAME -no-audio -no-boot-anim -no-window -gpu swiftshader_indirect -camera-back none -camera-front none -timezone UTC > emulator.log 2>&1 & echo "Waiting for emulator to start..." - /usr/local/lib/android/sdk/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;' + timeout 300 /usr/local/lib/android/sdk/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;' echo "Emulator started successfully!" - - name: Run Detox E2E Tests - run: | cd detox npm run e2e:android -- about.e2e.ts + # - name: Run Detox E2E Tests + # run: | + # cd detox + # npm run e2e:android -- about.e2e.ts + - name: Capture Logs on Failure if: failure() run: | From c61464008117f2102661325797aae08ded13b26a Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sat, 1 Feb 2025 14:13:45 +0530 Subject: [PATCH 48/98] wait 5m for emulator to boot and run tests --- .github/workflows/e2e-android-detox.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 2433532eb64..a26e9386ca8 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -153,10 +153,19 @@ jobs: - name: Create & Start Android Emulator run: | echo "Creating AVD..." - $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd -n $AVD_NAME -k "system-images;android-34;google_apis;x86_64" --device "pixel_6" --force + export ANDROID_AVD_HOME=$HOME/.android/avd + + # Ensure system image is installed + /usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --install "system-images;android-34;google_apis;x86_64" --sdk_root=$ANDROID_HOME + + # Create the AVD if it doesn't exist + echo no | $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd -n ${{ env.AVD_NAME }} -k "system-images;android-34;google_apis;x86_64" --device "pixel_6" --force + + # List available AVDs for debugging + $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager list avd echo "Starting emulator..." - nohup $ANDROID_HOME/emulator/emulator -avd $AVD_NAME -no-audio -no-boot-anim -no-window -gpu swiftshader_indirect -camera-back none -camera-front none -timezone UTC > emulator.log 2>&1 & + nohup $ANDROID_HOME/emulator/emulator -avd ${{ env.AVD_NAME }} -no-audio -no-boot-anim -no-window -gpu swiftshader_indirect -camera-back none -camera-front none -timezone UTC > emulator.log 2>&1 & echo "Waiting for emulator to start..." timeout 300 /usr/local/lib/android/sdk/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;' From d961056df5c0897e6e95e7bce51c1820b74bbd38 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 08:40:17 +0530 Subject: [PATCH 49/98] run on macos-latest --- .github/workflows/e2e-android-detox.yml | 96 ++++++++++++++++++------- detox/create_android_emulator.sh | 9 +++ 2 files changed, 80 insertions(+), 25 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index a26e9386ca8..d5ba3a0b182 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -66,7 +66,7 @@ jobs: path: "android/app/build/outputs/apk/**/app-*.apk" run-android-tests: - # if: github.event.label.name == 'E2E Android tests for PR' + if: github.event.label.name == 'E2E Android tests for PR' && false # needs: build-android-apk runs-on: ubuntu-latest-8-cores @@ -100,6 +100,15 @@ jobs: # name: android-build-apk-13046110009 # path: android/app/build/outputs/apk/ + - name: Start Server + run: | + npm run start & + + - name: Install Dependencies + run: | + cd detox + npm install + - name: Create destination path run: mkdir -p android/app/build/outputs/apk @@ -115,20 +124,10 @@ jobs: - name: Unzip artifact run: unzip android/app/build/outputs/apk/artifact.zip -d android/app/build/outputs/apk - - name: List unzipped files - run: ls -la android/app/build/outputs/apk - - name: Cleanup run: | find android/app/build -type f rm android/app/build/outputs/apk/artifact.zip - - - name: Install Required Android System Image - run: | - echo "Installing Android System Image..." - /usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --install "system-images;android-34;google_apis;x86_64" --sdk_root=$ANDROID_HOME - /usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --install "platform-tools" --sdk_root=$ANDROID_HOME - /usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --licenses --sdk_root=$ANDROID_HOME - name: Add ADB to PATH run: | @@ -141,15 +140,6 @@ jobs: ls -la /usr/local/lib/android/sdk/platform-tools/ /usr/local/lib/android/sdk/platform-tools/adb version - - name: Start Server - run: | - npm run start & - - - name: Install Dependencies - run: | - cd detox - npm install - - name: Create & Start Android Emulator run: | echo "Creating AVD..." @@ -175,11 +165,6 @@ jobs: cd detox npm run e2e:android -- about.e2e.ts - # - name: Run Detox E2E Tests - # run: | - # cd detox - # npm run e2e:android -- about.e2e.ts - - name: Capture Logs on Failure if: failure() run: | @@ -195,3 +180,64 @@ jobs: with: name: detox-logs path: logcat_output.txt + + detox-android-e2e: + runs-on: macos-latest # Best runner for Android emulator on macOS (M1 supported) + + steps: + - name: ci/checkout-repo + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: ci/prepare-android-build + uses: ./.github/actions/prepare-android-build + env: + STORE_FILE: "${{ secrets.MM_MOBILE_STORE_FILE }}" + STORE_ALIAS: "${{ secrets.MM_MOBILE_STORE_ALIAS }}" + STORE_PASSWORD: "${{ secrets.MM_MOBILE_STORE_PASSWORD }}" + MATTERMOST_BUILD_GH_TOKEN: "${{ secrets.MATTERMOST_BUILD_GH_TOKEN }}" + + - name: Start Server + run: | + npm run start & + + - name: Install Dependencies + run: | + cd detox + npm install + + - name: Create destination path + run: mkdir -p android/app/build/outputs/apk + + - name: Download artifact + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + curl -L -H "Authorization: token $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/mattermost/mattermost-mobile/actions/artifacts/2508660502/zip \ + --output android/app/build/outputs/apk/artifact.zip + + - name: Unzip artifact + run: unzip android/app/build/outputs/apk/artifact.zip -d android/app/build/outputs/apk + + - name: Cleanup + run: | + find android/app/build -type f + rm android/app/build/outputs/apk/artifact.zip + + + - name: Accept Android licenses + run: | + yes | sdkmanager --licenses + + - name: Create and start Android emulator + run: | + chmod +x ./create_emulator.sh + ./create_emulator.sh + + - name: Stop Android emulator + if: always() # Ensure the emulator is stopped even if the tests fail + run: | + adb emu kill \ No newline at end of file diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index 18ef420e420..c1fd927eb1c 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -37,3 +37,12 @@ else echo "Android virtual device successfully created: ${NAME}" fi + +# Start the emulator +echo "Starting the emulator..." +emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu off -verbose -qemu -vnc :0 + + +# Run tests +cd detox +npm run e2e:android-test -- about.e2e.ts \ No newline at end of file From d66ae095c9dae3184e955927021ad5618ab41958 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 08:46:44 +0530 Subject: [PATCH 50/98] fix path on macos-latest --- .github/workflows/e2e-android-detox.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index d5ba3a0b182..ddb2f69843c 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -226,11 +226,17 @@ jobs: run: | find android/app/build -type f rm android/app/build/outputs/apk/artifact.zip - + + - name: Set up Android SDK + run: | + export ANDROID_HOME=$HOME/Library/Android/sdk + export PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/emulator:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH + echo "ANDROID_HOME=$ANDROID_HOME" >> $GITHUB_ENV + echo "PATH=$PATH" >> $GITHUB_ENV - name: Accept Android licenses run: | - yes | sdkmanager --licenses + yes | sdkmanager --licenses || true - name: Create and start Android emulator run: | From 290f7c79c65a717bfdcc0993e47032112b3fb09e Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 08:50:43 +0530 Subject: [PATCH 51/98] fix path on macos-latest --- .github/workflows/e2e-android-detox.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index ddb2f69843c..c708a01f629 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -240,8 +240,8 @@ jobs: - name: Create and start Android emulator run: | - chmod +x ./create_emulator.sh - ./create_emulator.sh + chmod +x ./detox/create_emulator.sh + ./detox/create_emulator.sh - name: Stop Android emulator if: always() # Ensure the emulator is stopped even if the tests fail From 6909b0d39a6c50e1b620a8114570adbe83773d0e Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 08:55:02 +0530 Subject: [PATCH 52/98] fix path on macos-latest --- .github/workflows/e2e-android-detox.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index c708a01f629..7f287e7bc77 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -240,8 +240,8 @@ jobs: - name: Create and start Android emulator run: | - chmod +x ./detox/create_emulator.sh - ./detox/create_emulator.sh + chmod +x ./detox/create_android_emulator.sh + ./detox/create_android_emulator.sh - name: Stop Android emulator if: always() # Ensure the emulator is stopped even if the tests fail From d53954579fa060824bc8180654807ab3bda1edc3 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 09:01:00 +0530 Subject: [PATCH 53/98] fix path on macos-latest --- .github/workflows/e2e-android-detox.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 7f287e7bc77..1e85c67be3c 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -238,10 +238,16 @@ jobs: run: | yes | sdkmanager --licenses || true + - name: Install Android system image + run: | + sdkmanager "system-images;android-31;default;arm64-v8a" + sdkmanager "platform-tools" "emulator" + - name: Create and start Android emulator run: | - chmod +x ./detox/create_android_emulator.sh - ./detox/create_android_emulator.sh + cd detox + chmod +x ./create_android_emulator.sh + ./create_android_emulator.sh - name: Stop Android emulator if: always() # Ensure the emulator is stopped even if the tests fail From 6481e2af3dae60cf880b19156ee1dc74e1d30ddb Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 09:06:04 +0530 Subject: [PATCH 54/98] fix path on macos-latest --- detox/create_android_emulator.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index c1fd927eb1c..cde5c40fde8 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -44,5 +44,4 @@ emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu off -ve # Run tests -cd detox npm run e2e:android-test -- about.e2e.ts \ No newline at end of file From aec065c350f1c60c79854fd91a71ada747748a3d Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 09:31:54 +0530 Subject: [PATCH 55/98] use ubuntu 8 cores --- .github/workflows/e2e-android-detox.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 1e85c67be3c..bb25c65406f 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -182,7 +182,7 @@ jobs: path: logcat_output.txt detox-android-e2e: - runs-on: macos-latest # Best runner for Android emulator on macOS (M1 supported) + runs-on: ubuntu-latest-8-cores steps: - name: ci/checkout-repo @@ -190,6 +190,12 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} + - name: Enable KVM + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + - name: ci/prepare-android-build uses: ./.github/actions/prepare-android-build env: From 2b1db9f78d9ee074aab21c83cf4894d4d6012837 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 09:41:53 +0530 Subject: [PATCH 56/98] enable KVM --- .github/workflows/e2e-android-detox.yml | 4 ++-- detox/create_android_emulator.sh | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index bb25c65406f..61dc227ee0c 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -235,7 +235,7 @@ jobs: - name: Set up Android SDK run: | - export ANDROID_HOME=$HOME/Library/Android/sdk + export ANDROID_HOME=/usr/local/lib/android/sdk export PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/emulator:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH echo "ANDROID_HOME=$ANDROID_HOME" >> $GITHUB_ENV echo "PATH=$PATH" >> $GITHUB_ENV @@ -246,7 +246,7 @@ jobs: - name: Install Android system image run: | - sdkmanager "system-images;android-31;default;arm64-v8a" + sdkmanager "system-images;android-31;default;x86_64" # Use x86_64 for KVM sdkmanager "platform-tools" "emulator" - name: Create and start Android emulator diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index cde5c40fde8..6f661180d34 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -40,8 +40,13 @@ fi # Start the emulator echo "Starting the emulator..." -emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu off -verbose -qemu -vnc :0 +if [[ "$CI" == "true" || "$(uname -s)" == "Linux" ]]; then + echo "Starting the emulator with KVM..." + emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu auto -accel on -qemu -m 2048 -cores 4 +else + emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu off -verbose -qemu -vnc :0 +fi # Run tests npm run e2e:android-test -- about.e2e.ts \ No newline at end of file From b73a9b537364afdaa02370d628b1a9380809f486 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 09:53:27 +0530 Subject: [PATCH 57/98] add sdkmanager in path --- .github/workflows/e2e-android-detox.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 61dc227ee0c..557b1fc2669 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -183,6 +183,10 @@ jobs: detox-android-e2e: runs-on: ubuntu-latest-8-cores + env: + ANDROID_HOME: /usr/local/lib/android/sdk + ANDROID_SDK_ROOT: /usr/local/lib/android/sdk + PATH: /usr/local/lib/android/sdk/platform-tools:/usr/local/lib/android/sdk/emulator:/usr/local/lib/android/sdk/cmdline-tools/latest/bin:$PATH steps: - name: ci/checkout-repo From 7c272c357f2f6ea31b603777ac0914c004efd57f Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 10:00:51 +0530 Subject: [PATCH 58/98] add sdkmanager in path --- .github/workflows/e2e-android-detox.yml | 131 ++---------------------- 1 file changed, 10 insertions(+), 121 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 557b1fc2669..e5b1bbda457 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -65,135 +65,24 @@ jobs: name: android-build-apk-${{ github.run_id }} path: "android/app/build/outputs/apk/**/app-*.apk" - run-android-tests: - if: github.event.label.name == 'E2E Android tests for PR' && false - # needs: build-android-apk - runs-on: ubuntu-latest-8-cores - - env: - SDK_VERSION: 34 - AVD_NAME: "detox_pixel_4_xl_api_31" - ARCH: "x86_64" - ANDROID_HOME: /usr/local/lib/android/sdk - ANDROID_SDK_ROOT: /usr/local/lib/android/sdk - ANDROID_NDK_ROOT: /usr/local/lib/android/sdk/ndk/27.2.12479018 - ADB_INSTALL_TIMEOUT: 10 - DETOX_LOGLEVEL: trace - - steps: - - name: ci/checkout-repo - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - with: - ref: ${{ github.event.pull_request.head.sha }} - - - name: ci/prepare-android-build - uses: ./.github/actions/prepare-android-build - env: - STORE_FILE: "${{ secrets.MM_MOBILE_STORE_FILE }}" - STORE_ALIAS: "${{ secrets.MM_MOBILE_STORE_ALIAS }}" - STORE_PASSWORD: "${{ secrets.MM_MOBILE_STORE_PASSWORD }}" - MATTERMOST_BUILD_GH_TOKEN: "${{ secrets.MATTERMOST_BUILD_GH_TOKEN }}" - - # - name: Download APK artifact - # uses: actions/download-artifact@v4 - # with: - # name: android-build-apk-13046110009 - # path: android/app/build/outputs/apk/ - - - name: Start Server - run: | - npm run start & - - - name: Install Dependencies - run: | - cd detox - npm install - - - name: Create destination path - run: mkdir -p android/app/build/outputs/apk - - - name: Download artifact - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - curl -L -H "Authorization: token $GITHUB_TOKEN" \ - -H "Accept: application/vnd.github.v3+json" \ - https://api.github.com/repos/mattermost/mattermost-mobile/actions/artifacts/2508660502/zip \ - --output android/app/build/outputs/apk/artifact.zip - - - name: Unzip artifact - run: unzip android/app/build/outputs/apk/artifact.zip -d android/app/build/outputs/apk - - - name: Cleanup - run: | - find android/app/build -type f - rm android/app/build/outputs/apk/artifact.zip - - - name: Add ADB to PATH - run: | - echo "Adding ADB to PATH..." - echo "$ANDROID_HOME/platform-tools" >> $GITHUB_PATH - echo "PATH updated: $PATH" - - - name: Verify ADB Installation - run: | - ls -la /usr/local/lib/android/sdk/platform-tools/ - /usr/local/lib/android/sdk/platform-tools/adb version - - - name: Create & Start Android Emulator - run: | - echo "Creating AVD..." - export ANDROID_AVD_HOME=$HOME/.android/avd - - # Ensure system image is installed - /usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --install "system-images;android-34;google_apis;x86_64" --sdk_root=$ANDROID_HOME - - # Create the AVD if it doesn't exist - echo no | $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd -n ${{ env.AVD_NAME }} -k "system-images;android-34;google_apis;x86_64" --device "pixel_6" --force - - # List available AVDs for debugging - $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager list avd - - echo "Starting emulator..." - nohup $ANDROID_HOME/emulator/emulator -avd ${{ env.AVD_NAME }} -no-audio -no-boot-anim -no-window -gpu swiftshader_indirect -camera-back none -camera-front none -timezone UTC > emulator.log 2>&1 & - - echo "Waiting for emulator to start..." - timeout 300 /usr/local/lib/android/sdk/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;' - - echo "Emulator started successfully!" - - cd detox - npm run e2e:android -- about.e2e.ts - - - name: Capture Logs on Failure - if: failure() - run: | - echo "Emulator Logs:" - cat emulator.log - echo "ADB Logcat Output:" - adb logcat -d > logcat_output.txt - cat logcat_output.txt - - - name: Upload Logs on Failure - if: failure() - uses: actions/upload-artifact@v4 - with: - name: detox-logs - path: logcat_output.txt - detox-android-e2e: runs-on: ubuntu-latest-8-cores - env: - ANDROID_HOME: /usr/local/lib/android/sdk - ANDROID_SDK_ROOT: /usr/local/lib/android/sdk - PATH: /usr/local/lib/android/sdk/platform-tools:/usr/local/lib/android/sdk/emulator:/usr/local/lib/android/sdk/cmdline-tools/latest/bin:$PATH - steps: - name: ci/checkout-repo uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: ref: ${{ github.event.pull_request.head.sha }} + - name: Set up Android SDK paths + run: | + echo "/usr/local/lib/android/sdk/platform-tools" >> $GITHUB_PATH + echo "/usr/local/lib/android/sdk/emulator" >> $GITHUB_PATH + echo "/usr/local/lib/android/sdk/cmdline-tools/latest/bin" >> $GITHUB_PATH + echo "*********" + echo $GITHUB_PATH + echo "*********" + echo $PATH + - name: Enable KVM run: | echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules From bb14689ddd913c3bfb7680d4dedd90b6e73e6ec6 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 10:07:52 +0530 Subject: [PATCH 59/98] fix avd home location --- .github/workflows/e2e-android-detox.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index e5b1bbda457..9e116725c34 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -67,21 +67,22 @@ jobs: detox-android-e2e: runs-on: ubuntu-latest-8-cores + env: + ANDROID_HOME: /usr/local/lib/android/sdk + ANDROID_SDK_ROOT: /usr/local/lib/android/sdk + ANDROID_AVD_HOME: /home/runner/.android/avd + PATH: /usr/local/lib/android/sdk/platform-tools:/usr/local/lib/android/sdk/emulator:/usr/local/lib/android/sdk/cmdline-tools/latest/bin:$PATH + steps: - name: ci/checkout-repo uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: ref: ${{ github.event.pull_request.head.sha }} - - name: Set up Android SDK paths + - name: Debug AVD Location run: | - echo "/usr/local/lib/android/sdk/platform-tools" >> $GITHUB_PATH - echo "/usr/local/lib/android/sdk/emulator" >> $GITHUB_PATH - echo "/usr/local/lib/android/sdk/cmdline-tools/latest/bin" >> $GITHUB_PATH - echo "*********" - echo $GITHUB_PATH - echo "*********" - echo $PATH + ls -la $ANDROID_AVD_HOME + ls -la /home/runner/.android/avd - name: Enable KVM run: | From 222d392c3ad5bd89a17f2764d97391a99f9527d2 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 10:11:05 +0530 Subject: [PATCH 60/98] fix avd home location --- .github/workflows/e2e-android-detox.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 9e116725c34..ad0992a383a 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -71,7 +71,6 @@ jobs: ANDROID_HOME: /usr/local/lib/android/sdk ANDROID_SDK_ROOT: /usr/local/lib/android/sdk ANDROID_AVD_HOME: /home/runner/.android/avd - PATH: /usr/local/lib/android/sdk/platform-tools:/usr/local/lib/android/sdk/emulator:/usr/local/lib/android/sdk/cmdline-tools/latest/bin:$PATH steps: - name: ci/checkout-repo From 2e2c5cbcdad152b9b27cbee67dc51dcc949f4668 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 10:19:31 +0530 Subject: [PATCH 61/98] fix avd home location --- .github/workflows/e2e-android-detox.yml | 5 ++--- detox/create_android_emulator.sh | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index ad0992a383a..fc244e0c054 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -78,10 +78,9 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} - - name: Debug AVD Location + - name: Create AVD Location run: | - ls -la $ANDROID_AVD_HOME - ls -la /home/runner/.android/avd + mkdir -p $ANDROID_AVD_HOME - name: Enable KVM run: | diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index 6f661180d34..086e94aadef 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -38,6 +38,11 @@ else echo "Android virtual device successfully created: ${NAME}" fi +echo "*********************" +ls -la $ANDROID_AVD_HOME +ls -la /home/runner/.android/avd +echo "*********************" + # Start the emulator echo "Starting the emulator..." From e49af402af475a6442e9ec910d93ee99444aee64 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 10:26:11 +0530 Subject: [PATCH 62/98] install linux dependencies --- .github/workflows/e2e-android-detox.yml | 3 +++ detox/create_android_emulator.sh | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index fc244e0c054..8ab6ce9482f 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -82,6 +82,9 @@ jobs: run: | mkdir -p $ANDROID_AVD_HOME + - name: Install Dependencies + run: sudo apt-get update && sudo apt-get install -y libpulse0 + - name: Enable KVM run: | echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index 086e94aadef..9c0a0ebaac1 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -39,8 +39,8 @@ else fi echo "*********************" -ls -la $ANDROID_AVD_HOME -ls -la /home/runner/.android/avd +file /usr/local/lib/android/sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64 +ldd /usr/local/lib/android/sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64 echo "*********************" # Start the emulator @@ -48,7 +48,7 @@ echo "Starting the emulator..." if [[ "$CI" == "true" || "$(uname -s)" == "Linux" ]]; then echo "Starting the emulator with KVM..." - emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu auto -accel on -qemu -m 2048 -cores 4 + emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu auto -accel on -qemu -m 4096 else emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu off -verbose -qemu -vnc :0 fi From 8ae8e34c62d6c2a12d200de3850c69b4a335ba37 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 10:40:18 +0530 Subject: [PATCH 63/98] wait for emulator boot --- .github/workflows/e2e-android-detox.yml | 5 ---- detox/create_android_emulator.sh | 35 ++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 8ab6ce9482f..3913d95e5b8 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -70,7 +70,6 @@ jobs: env: ANDROID_HOME: /usr/local/lib/android/sdk ANDROID_SDK_ROOT: /usr/local/lib/android/sdk - ANDROID_AVD_HOME: /home/runner/.android/avd steps: - name: ci/checkout-repo @@ -78,10 +77,6 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} - - name: Create AVD Location - run: | - mkdir -p $ANDROID_AVD_HOME - - name: Install Dependencies run: sudo apt-get update && sudo apt-get install -y libpulse0 diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index 9c0a0ebaac1..90c7a65c651 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -10,6 +10,10 @@ set -o pipefail SDK_VERSION=31 NAME="detox_pixel_4_xl_api_${SDK_VERSION}" +# Set ANDROID_AVD_HOME to the current directory +export ANDROID_AVD_HOME=$(pwd)/.android/avd +mkdir -p $ANDROID_AVD_HOME + if emulator -list-avds | grep -q $NAME; then echo "'${NAME}' Android virtual device already exists." else @@ -35,13 +39,20 @@ else sed -i -e "s|image.sysdir.1 = change_to_image_sysdir/|image.sysdir.1 = system-images/android-${SDK_VERSION}/default/${CPU_ARCH_FAMILY}/|g" $NAME/config.ini sed -i -e "s|skin.path = change_to_absolute_path/pixel_4_xl_skin|skin.path = $(pwd)/${NAME}/pixel_4_xl_skin|g" $NAME/config.ini + # Move AVD configuration files to ANDROID_AVD_HOME + mv $NAME.ini $ANDROID_AVD_HOME/ + mv $NAME.avd $ANDROID_AVD_HOME/ + echo "Android virtual device successfully created: ${NAME}" fi -echo "*********************" -file /usr/local/lib/android/sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64 -ldd /usr/local/lib/android/sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64 -echo "*********************" +# Kill existing ADB server +echo "Killing existing ADB server..." +adb kill-server + +# Start ADB server +echo "Starting ADB server..." +adb start-server # Start the emulator echo "Starting the emulator..." @@ -53,5 +64,21 @@ else emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu off -verbose -qemu -vnc :0 fi +# Wait for the emulator to boot +echo "Waiting for the emulator to boot..." +adb wait-for-device + +# Check if the emulator is fully booted +echo "Checking if the emulator is fully booted..." +while true; do + boot_completed=$(adb shell getprop sys.boot_completed | tr -d '\r') + if [[ "$boot_completed" == "1" ]]; then + echo "Emulator is fully booted." + break + fi + echo "Waiting for emulator to boot..." + sleep 10 +done + # Run tests npm run e2e:android-test -- about.e2e.ts \ No newline at end of file From d3eafe12ee0d5ce7d93349f97fed3fec0d245012 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 11:11:02 +0530 Subject: [PATCH 64/98] wait for emulator boot --- detox/create_android_emulator.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index 90c7a65c651..c675316d02c 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -39,10 +39,6 @@ else sed -i -e "s|image.sysdir.1 = change_to_image_sysdir/|image.sysdir.1 = system-images/android-${SDK_VERSION}/default/${CPU_ARCH_FAMILY}/|g" $NAME/config.ini sed -i -e "s|skin.path = change_to_absolute_path/pixel_4_xl_skin|skin.path = $(pwd)/${NAME}/pixel_4_xl_skin|g" $NAME/config.ini - # Move AVD configuration files to ANDROID_AVD_HOME - mv $NAME.ini $ANDROID_AVD_HOME/ - mv $NAME.avd $ANDROID_AVD_HOME/ - echo "Android virtual device successfully created: ${NAME}" fi @@ -59,9 +55,9 @@ echo "Starting the emulator..." if [[ "$CI" == "true" || "$(uname -s)" == "Linux" ]]; then echo "Starting the emulator with KVM..." - emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu auto -accel on -qemu -m 4096 + emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu auto -accel on -qemu -m 4096 & else - emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu off -verbose -qemu -vnc :0 + emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu off -verbose -qemu -vnc :0 & fi # Wait for the emulator to boot @@ -81,4 +77,5 @@ while true; do done # Run tests +echo "Running tests..." npm run e2e:android-test -- about.e2e.ts \ No newline at end of file From a50a7469053aa4bc56044513cb306597819721a3 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 11:24:11 +0530 Subject: [PATCH 65/98] upload report --- .github/workflows/e2e-android-detox.yml | 10 +++++++++- detox/create_android_emulator.sh | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 3913d95e5b8..a3cb201c6f8 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -97,6 +97,7 @@ jobs: - name: Start Server run: | npm run start & + sleep 120 - name: Install Dependencies run: | @@ -148,4 +149,11 @@ jobs: - name: Stop Android emulator if: always() # Ensure the emulator is stopped even if the tests fail run: | - adb emu kill \ No newline at end of file + adb emu kill + + - name: Upload android Test Report + if: always() + uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 + with: + name: android-results-${{ github.run_id }} + path: detox/artifacts/ diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index c675316d02c..820ff6c6e1b 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -57,7 +57,7 @@ if [[ "$CI" == "true" || "$(uname -s)" == "Linux" ]]; then echo "Starting the emulator with KVM..." emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu auto -accel on -qemu -m 4096 & else - emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu off -verbose -qemu -vnc :0 & + emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu auto -verbose -qemu -vnc :0 & fi # Wait for the emulator to boot From 0a243bae3b73de655d7b696e46af1c20af0432ca Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 11:37:39 +0530 Subject: [PATCH 66/98] upload report --- .github/workflows/e2e-android-detox.yml | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index a3cb201c6f8..479f604ea9f 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -131,6 +131,14 @@ jobs: echo "ANDROID_HOME=$ANDROID_HOME" >> $GITHUB_ENV echo "PATH=$PATH" >> $GITHUB_ENV + - name: Install scrot and ffmpeg + run: sudo apt-get install -y scrot ffmpeg + + - name: Start Video Recording + run: | + ffmpeg -video_size 1920x1080 -framerate 25 -f x11grab -i :0.0 -codec:v libx264 -preset ultrafast -qp 0 screen_recording.mp4 & + echo $! > ffmpeg_pid.txt + - name: Accept Android licenses run: | yes | sdkmanager --licenses || true @@ -146,6 +154,28 @@ jobs: chmod +x ./create_android_emulator.sh ./create_android_emulator.sh + - name: Take Screenshot on Failure + if: failure() + run: scrot failure_screenshot.png + + - name: Stop Video Recording + run: | + kill $(cat ffmpeg_pid.txt) + rm ffmpeg_pid.txt + + - name: Upload Screenshot on Failure + if: failure() + uses: actions/upload-artifact@v4 + with: + name: failure-screenshot + path: failure_screenshot.png + + - name: Upload Video Recording + uses: actions/upload-artifact@v4 + with: + name: screen-recording + path: screen_recording.mp4 + - name: Stop Android emulator if: always() # Ensure the emulator is stopped even if the tests fail run: | From 7e1e7e3fe1d14ee68e43c58fc834aef0848ed191 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 11:52:01 +0530 Subject: [PATCH 67/98] upload report --- .github/workflows/e2e-android-detox.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 479f604ea9f..99deb665b11 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -131,12 +131,18 @@ jobs: echo "ANDROID_HOME=$ANDROID_HOME" >> $GITHUB_ENV echo "PATH=$PATH" >> $GITHUB_ENV - - name: Install scrot and ffmpeg - run: sudo apt-get install -y scrot ffmpeg + - name: Install scrot, ffmpeg, and Xvfb + run: sudo apt-get install -y scrot ffmpeg xvfb + + - name: Start Xvfb + run: | + Xvfb :99 -screen 0 1920x1080x24 & + export DISPLAY=:99 + echo "DISPLAY=:99" >> $GITHUB_ENV - name: Start Video Recording run: | - ffmpeg -video_size 1920x1080 -framerate 25 -f x11grab -i :0.0 -codec:v libx264 -preset ultrafast -qp 0 screen_recording.mp4 & + ffmpeg -video_size 1920x1080 -framerate 25 -f x11grab -i :99.0 -codec:v libx264 -preset ultrafast -qp 0 screen_recording.mp4 & echo $! > ffmpeg_pid.txt - name: Accept Android licenses From d45e2399df893523ab39a95c80d3a04dccd30ea4 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 11:56:33 +0530 Subject: [PATCH 68/98] increase wait time for server --- .github/workflows/e2e-android-detox.yml | 3 ++- detox/e2e/test/account/about.e2e.ts | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 99deb665b11..fe0c9f36d5d 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -97,7 +97,7 @@ jobs: - name: Start Server run: | npm run start & - sleep 120 + sleep 240 - name: Install Dependencies run: | @@ -165,6 +165,7 @@ jobs: run: scrot failure_screenshot.png - name: Stop Video Recording + if: failure() run: | kill $(cat ffmpeg_pid.txt) rm ffmpeg_pid.txt diff --git a/detox/e2e/test/account/about.e2e.ts b/detox/e2e/test/account/about.e2e.ts index 4944fdc9e08..8bc85572f94 100644 --- a/detox/e2e/test/account/about.e2e.ts +++ b/detox/e2e/test/account/about.e2e.ts @@ -28,6 +28,8 @@ describe('Account - Settings - About', () => { let testUser: any; beforeAll(async () => { + // eslint-disable-next-line no-console + console.log('-----------------------siteOneUrl ', siteOneUrl); const {license} = await System.apiGetClientLicense(siteOneUrl); isLicensed = license.IsLicensed === 'true'; const {user} = await Setup.apiInit(siteOneUrl); From 305df44e6e9ab90e9b8a7e68214d3604fbd2c2f2 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 12:37:27 +0530 Subject: [PATCH 69/98] Add env variables in the android job --- .github/workflows/e2e-android-detox.yml | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index fe0c9f36d5d..724f5d98d29 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -11,6 +11,30 @@ on: types: - labeled +env: + AWS_REGION: "us-east-1" + ADMIN_EMAIL: ${{ secrets.MM_MOBILE_E2E_ADMIN_EMAIL }} + ADMIN_USERNAME: ${{ secrets.MM_MOBILE_E2E_ADMIN_USERNAME }} + ADMIN_PASSWORD: ${{ secrets.MM_MOBILE_E2E_ADMIN_PASSWORD }} + BRANCH: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} + COMMIT_HASH: ${{ github.sha }} + DEVICE_NAME: ${{ inputs.ios_device_name }} + DEVICE_OS_VERSION: ${{ inputs.ios_device_os_name }} + DETOX_AWS_S3_BUCKET: "mattermost-detox-report" + HEADLESS: "true" + TYPE: ${{ inputs.run-type }} + PULL_REQUEST: "https://github.com/mattermost/mattermost-mobile/pull/${{ github.event.number }}" + SITE_1_URL: ${{ inputs.MM_TEST_SERVER_URL || 'https://mobile-e2e-site-1.test.mattermost.cloud' }} + SITE_2_URL: "https://mobile-e2e-site-2.test.mattermost.cloud" + SITE_3_URL: "https://mobile-e2e-site-3.test.mattermost.cloud" + ZEPHYR_ENABLE: ${{ inputs.record_tests_in_zephyr }} + JIRA_PROJECT_KEY: "MM" + ZEPHYR_API_KEY: ${{ secrets.MM_MOBILE_E2E_ZEPHYR_API_KEY }} + ZEPHYR_FOLDER_ID: "3233873" + TEST_CYCLE_LINK_PREFIX: ${{ secrets.MM_MOBILE_E2E_TEST_CYCLE_LINK_PREFIX }} + WEBHOOK_URL: ${{ secrets.MM_MOBILE_E2E_WEBHOOK_URL }} + FAILURE_MESSAGE: "Something has failed" + concurrency: group: "${{ github.workflow }}-${{ github.event.pull_request.number }}-${{ github.event.label.name }}" cancel-in-progress: true @@ -160,6 +184,27 @@ jobs: chmod +x ./create_android_emulator.sh ./create_android_emulator.sh + - name: Generate Report Path + id: s3 + run: | + path="${{ github.run_id }}/${{ github.sha }}" + echo "path=$(echo "${path}" | sed 's/\./-/g')" >> ${GITHUB_OUTPUT} + + - name: Save report Detox Dependencies + id: report-link + run: | + cd detox + npm run e2e:save-report + env: + DETOX_AWS_ACCESS_KEY_ID: ${{ secrets.MM_MOBILE_DETOX_AWS_ACCESS_KEY_ID }} + DETOX_AWS_SECRET_ACCESS_KEY: ${{ secrets.MM_MOBILE_DETOX_AWS_SECRET_ACCESS_KEY }} + IOS: false + BUILD_ID: ${{ github.run_id }} + REPORT_PATH: ${{ steps.s3.outputs.path }} + ## These are needed for the MM Webhook report + COMMIT_HASH: ${{ github.sha }} + BRANCH: ${{ github.ref }} + - name: Take Screenshot on Failure if: failure() run: scrot failure_screenshot.png From 1318f4c979fe3c7425cd7e4a3e720812a872a7ae Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 13:20:26 +0530 Subject: [PATCH 70/98] Start server from the script --- .github/workflows/e2e-android-detox.yml | 19 +------------------ detox/create_android_emulator.sh | 6 ++++++ detox/e2e/test/account/about.e2e.ts | 2 -- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 724f5d98d29..3dc149067f4 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -118,11 +118,6 @@ jobs: STORE_PASSWORD: "${{ secrets.MM_MOBILE_STORE_PASSWORD }}" MATTERMOST_BUILD_GH_TOKEN: "${{ secrets.MATTERMOST_BUILD_GH_TOKEN }}" - - name: Start Server - run: | - npm run start & - sleep 240 - - name: Install Dependencies run: | cd detox @@ -204,17 +199,11 @@ jobs: ## These are needed for the MM Webhook report COMMIT_HASH: ${{ github.sha }} BRANCH: ${{ github.ref }} - + - name: Take Screenshot on Failure if: failure() run: scrot failure_screenshot.png - - name: Stop Video Recording - if: failure() - run: | - kill $(cat ffmpeg_pid.txt) - rm ffmpeg_pid.txt - - name: Upload Screenshot on Failure if: failure() uses: actions/upload-artifact@v4 @@ -222,12 +211,6 @@ jobs: name: failure-screenshot path: failure_screenshot.png - - name: Upload Video Recording - uses: actions/upload-artifact@v4 - with: - name: screen-recording - path: screen_recording.mp4 - - name: Stop Android emulator if: always() # Ensure the emulator is stopped even if the tests fail run: | diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index 820ff6c6e1b..798293d0686 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -76,6 +76,12 @@ while true; do sleep 10 done +# Start the server +cd .. +npm run start & +sleep 120 + # Run tests echo "Running tests..." +cd detox npm run e2e:android-test -- about.e2e.ts \ No newline at end of file diff --git a/detox/e2e/test/account/about.e2e.ts b/detox/e2e/test/account/about.e2e.ts index 8bc85572f94..4944fdc9e08 100644 --- a/detox/e2e/test/account/about.e2e.ts +++ b/detox/e2e/test/account/about.e2e.ts @@ -28,8 +28,6 @@ describe('Account - Settings - About', () => { let testUser: any; beforeAll(async () => { - // eslint-disable-next-line no-console - console.log('-----------------------siteOneUrl ', siteOneUrl); const {license} = await System.apiGetClientLicense(siteOneUrl); isLicensed = license.IsLicensed === 'true'; const {user} = await Setup.apiInit(siteOneUrl); From 712be8b942fe497e87e7ed91a488487a01c990fc Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 16:23:28 +0530 Subject: [PATCH 71/98] Run all tests --- detox/create_android_emulator.sh | 46 +++++++++++++++++--------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index 798293d0686..5ae620253a4 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -11,8 +11,10 @@ SDK_VERSION=31 NAME="detox_pixel_4_xl_api_${SDK_VERSION}" # Set ANDROID_AVD_HOME to the current directory -export ANDROID_AVD_HOME=$(pwd)/.android/avd -mkdir -p $ANDROID_AVD_HOME +if [[ "$CI" == "true" ]]; then + export ANDROID_AVD_HOME=$(pwd)/.android/avd + mkdir -p $ANDROID_AVD_HOME +fi if emulator -list-avds | grep -q $NAME; then echo "'${NAME}' Android virtual device already exists." @@ -55,33 +57,35 @@ echo "Starting the emulator..." if [[ "$CI" == "true" || "$(uname -s)" == "Linux" ]]; then echo "Starting the emulator with KVM..." - emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu auto -accel on -qemu -m 4096 & + emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu swiftshader_indirect -accel on -qemu -m 4096 & else - emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu auto -verbose -qemu -vnc :0 & + emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu guest -verbose -qemu -vnc :0 fi -# Wait for the emulator to boot -echo "Waiting for the emulator to boot..." -adb wait-for-device - -# Check if the emulator is fully booted -echo "Checking if the emulator is fully booted..." -while true; do - boot_completed=$(adb shell getprop sys.boot_completed | tr -d '\r') - if [[ "$boot_completed" == "1" ]]; then - echo "Emulator is fully booted." - break - fi - echo "Waiting for emulator to boot..." - sleep 10 -done +if [[ "$CI" == "true" ]]; then + # Wait for the emulator to boot + echo "Waiting for the emulator to boot..." + adb wait-for-device + + # Check if the emulator is fully booted + echo "Checking if the emulator is fully booted..." + while true; do + boot_completed=$(adb shell getprop sys.boot_completed | tr -d '\r') + if [[ "$boot_completed" == "1" ]]; then + echo "Emulator is fully booted." + break + fi + echo "Waiting for emulator to boot..." + sleep 10 + done +fi # Start the server cd .. npm run start & -sleep 120 +sleep 180 # Run tests echo "Running tests..." cd detox -npm run e2e:android-test -- about.e2e.ts \ No newline at end of file +npm run e2e:android-test \ No newline at end of file From 5cb7ca12f9cbf51520e15b581ad84912c33613ba Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 17:13:28 +0530 Subject: [PATCH 72/98] increase time out --- detox/e2e/config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/detox/e2e/config.js b/detox/e2e/config.js index 574fb3a9a3b..ef2f0194b2d 100644 --- a/detox/e2e/config.js +++ b/detox/e2e/config.js @@ -3,12 +3,13 @@ const platform = process.env.IOS === 'true' ? 'ios' : 'android'; const shard = process.env.CI_NODE_INDEX ? process.env.CI_NODE_INDEX : ''; +const testTimeout = process.env.CI ? 300000 : 120000; module.exports = { setupFilesAfterEnv: ['./test/setup.ts'], maxWorkers: 1, testSequencer: './custom_sequencer.js', - testTimeout: 120000, + testTimeout, rootDir: '.', testMatch: ['/test/**/*.e2e.ts'], transform: { From 2dcffd58b6166f0ca5d583656f6d5e35a9a6ff2e Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 17:40:40 +0530 Subject: [PATCH 73/98] Run for api 33 --- .github/workflows/e2e-android-detox.yml | 2 +- detox/create_android_emulator.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 3dc149067f4..c87fad642c4 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -170,7 +170,7 @@ jobs: - name: Install Android system image run: | - sdkmanager "system-images;android-31;default;x86_64" # Use x86_64 for KVM + sdkmanager "system-images;android-33;default;x86_64" # Use x86_64 for KVM sdkmanager "platform-tools" "emulator" - name: Create and start Android emulator diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index 5ae620253a4..07d24bbee2d 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -7,7 +7,7 @@ set -ex set -o pipefail -SDK_VERSION=31 +SDK_VERSION=33 NAME="detox_pixel_4_xl_api_${SDK_VERSION}" # Set ANDROID_AVD_HOME to the current directory @@ -57,7 +57,7 @@ echo "Starting the emulator..." if [[ "$CI" == "true" || "$(uname -s)" == "Linux" ]]; then echo "Starting the emulator with KVM..." - emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu swiftshader_indirect -accel on -qemu -m 4096 & + emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu swiftshader_indirect -accel on -qemu -m 4096 -cores 5 & else emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu guest -verbose -qemu -vnc :0 fi @@ -88,4 +88,4 @@ sleep 180 # Run tests echo "Running tests..." cd detox -npm run e2e:android-test \ No newline at end of file +npm run e2e:android-test -- about.e2e.ts From d65b70435eb66629094dfa4ca2b803c2cbcae8b2 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 17:55:09 +0530 Subject: [PATCH 74/98] set cores 5 --- detox/create_android_emulator.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index 07d24bbee2d..fc1eca0961e 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -1,5 +1,4 @@ #!/bin/bash - # Reference: Download Android (AOSP) Emulators - https://github.com/wix/Detox/blob/master/docs/guide/android-dev-env.md#android-aosp-emulators # sdkmanager "system-images;android-31;default;arm64-v8a" # sdkmanager --licenses @@ -41,6 +40,9 @@ else sed -i -e "s|image.sysdir.1 = change_to_image_sysdir/|image.sysdir.1 = system-images/android-${SDK_VERSION}/default/${CPU_ARCH_FAMILY}/|g" $NAME/config.ini sed -i -e "s|skin.path = change_to_absolute_path/pixel_4_xl_skin|skin.path = $(pwd)/${NAME}/pixel_4_xl_skin|g" $NAME/config.ini + # Set the number of CPU cores in config.ini + echo "hw.cpu.ncore=5" >> $NAME/config.ini + echo "Android virtual device successfully created: ${NAME}" fi @@ -57,7 +59,7 @@ echo "Starting the emulator..." if [[ "$CI" == "true" || "$(uname -s)" == "Linux" ]]; then echo "Starting the emulator with KVM..." - emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu swiftshader_indirect -accel on -qemu -m 4096 -cores 5 & + emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu swiftshader_indirect -accel on -qemu -m 4096 & else emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu guest -verbose -qemu -vnc :0 fi From 3515d591ebc393bf9cd236a8cb386c7f1c2e3ed3 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 18:11:21 +0530 Subject: [PATCH 75/98] fix emulator name --- detox/.detoxrc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detox/.detoxrc.json b/detox/.detoxrc.json index a38b3f4faa4..8fd9e431766 100644 --- a/detox/.detoxrc.json +++ b/detox/.detoxrc.json @@ -37,7 +37,7 @@ "android.emulator": { "type": "android.emulator", "device": { - "avdName": "detox_pixel_4_xl_api_31" + "avdName": "detox_pixel_4_xl_api_33" } } }, From 5822ec51d6ba25007dbece7082f1979dfd4122b5 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 20:47:43 +0530 Subject: [PATCH 76/98] set RUNNING_ENE=true --- .github/workflows/e2e-android-detox.yml | 52 ++++++++++++++----------- index.ts | 7 ++-- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index c87fad642c4..6ad4fdbd8a3 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -34,6 +34,7 @@ env: TEST_CYCLE_LINK_PREFIX: ${{ secrets.MM_MOBILE_E2E_TEST_CYCLE_LINK_PREFIX }} WEBHOOK_URL: ${{ secrets.MM_MOBILE_E2E_WEBHOOK_URL }} FAILURE_MESSAGE: "Something has failed" + RUNNING_E2E: "true" concurrency: group: "${{ github.workflow }}-${{ github.event.pull_request.number }}-${{ github.event.label.name }}" @@ -41,7 +42,7 @@ concurrency: jobs: build-android-apk: - if: github.event.label.name == 'E2E Android tests for PR' && false + # if: github.event.label.name == 'E2E Android tests for PR' runs-on: ubuntu-latest-8-cores env: ORG_GRADLE_PROJECT_jvmargs: -Xmx8g @@ -86,11 +87,12 @@ jobs: - name: ci/upload-android-pr-build uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 with: - name: android-build-apk-${{ github.run_id }} - path: "android/app/build/outputs/apk/**/app-*.apk" + name: android-build-files-${{ github.run_id }} + path: "android/app/build/**/*" detox-android-e2e: runs-on: ubuntu-latest-8-cores + needs: build-android-apk env: ANDROID_HOME: /usr/local/lib/android/sdk ANDROID_SDK_ROOT: /usr/local/lib/android/sdk @@ -118,30 +120,36 @@ jobs: STORE_PASSWORD: "${{ secrets.MM_MOBILE_STORE_PASSWORD }}" MATTERMOST_BUILD_GH_TOKEN: "${{ secrets.MATTERMOST_BUILD_GH_TOKEN }}" + - name: Download android build files + uses: actions/download-artifact@v4 + with: + name: android-build-files-${{ github.run_id }} + path: android/app/build + - name: Install Dependencies run: | cd detox npm install - - name: Create destination path - run: mkdir -p android/app/build/outputs/apk - - - name: Download artifact - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - curl -L -H "Authorization: token $GITHUB_TOKEN" \ - -H "Accept: application/vnd.github.v3+json" \ - https://api.github.com/repos/mattermost/mattermost-mobile/actions/artifacts/2508660502/zip \ - --output android/app/build/outputs/apk/artifact.zip - - - name: Unzip artifact - run: unzip android/app/build/outputs/apk/artifact.zip -d android/app/build/outputs/apk - - - name: Cleanup - run: | - find android/app/build -type f - rm android/app/build/outputs/apk/artifact.zip + # - name: Create destination path + # run: mkdir -p android/app/build + + # - name: Download artifact + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # run: | + # curl -L -H "Authorization: token $GITHUB_TOKEN" \ + # -H "Accept: application/vnd.github.v3+json" \ + # https://api.github.com/repos/mattermost/mattermost-mobile/actions/artifacts/2508660502/zip \ + # --output android/app/build/artifact.zip + + # - name: Unzip artifact + # run: unzip android/app/build/artifact.zip -d android/app/build + + # - name: Cleanup + # run: | + # find android/app/build -type f + # rm android/app/build/outputs/apk/artifact.zip - name: Set up Android SDK run: | diff --git a/index.ts b/index.ts index 2a87c4cd233..775a11e6e71 100644 --- a/index.ts +++ b/index.ts @@ -4,7 +4,6 @@ import TurboLogger from '@mattermost/react-native-turbo-log'; import {LogBox, Platform, UIManager} from 'react-native'; import ViewReactNativeStyleAttributes from 'react-native/Libraries/Components/View/ReactNativeStyleAttributes'; -import {RUNNING_E2E} from 'react-native-dotenv'; import 'react-native-gesture-handler'; import {Navigation} from 'react-native-navigation'; @@ -30,8 +29,10 @@ if (__DEV__) { ]); // Ignore all notifications if running e2e - const isRunningE2e = RUNNING_E2E === 'true'; - logInfo(`RUNNING_E2E: ${RUNNING_E2E}, isRunningE2e: ${isRunningE2e}`); + // eslint-disable-next-line no-process-env + const isRunningE2e = process.env.RUNNING_E2E === 'true'; + // eslint-disable-next-line no-process-env + logInfo(`RUNNING_E2E: ${process.env.RUNNING_E2E}, isRunningE2e: ${isRunningE2e}`); if (isRunningE2e) { LogBox.ignoreAllLogs(true); } From ee005a1e343fccd2c47be91a2a0ba79853cf9dce Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 22:35:49 +0530 Subject: [PATCH 77/98] download whole build file --- .github/workflows/e2e-android-detox.yml | 52 ++++++++++++------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 6ad4fdbd8a3..69df5cd6af1 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -42,7 +42,7 @@ concurrency: jobs: build-android-apk: - # if: github.event.label.name == 'E2E Android tests for PR' + if: github.event.label.name == 'E2E Android tests for PR' runs-on: ubuntu-latest-8-cores env: ORG_GRADLE_PROJECT_jvmargs: -Xmx8g @@ -92,7 +92,7 @@ jobs: detox-android-e2e: runs-on: ubuntu-latest-8-cores - needs: build-android-apk + # needs: build-android-apk env: ANDROID_HOME: /usr/local/lib/android/sdk ANDROID_SDK_ROOT: /usr/local/lib/android/sdk @@ -120,36 +120,36 @@ jobs: STORE_PASSWORD: "${{ secrets.MM_MOBILE_STORE_PASSWORD }}" MATTERMOST_BUILD_GH_TOKEN: "${{ secrets.MATTERMOST_BUILD_GH_TOKEN }}" - - name: Download android build files - uses: actions/download-artifact@v4 - with: - name: android-build-files-${{ github.run_id }} - path: android/app/build + # - name: Download android build files + # uses: actions/download-artifact@v4 + # with: + # name: android-build-files-${{ github.run_id }} + # path: android/app/build - name: Install Dependencies run: | cd detox npm install - # - name: Create destination path - # run: mkdir -p android/app/build - - # - name: Download artifact - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # run: | - # curl -L -H "Authorization: token $GITHUB_TOKEN" \ - # -H "Accept: application/vnd.github.v3+json" \ - # https://api.github.com/repos/mattermost/mattermost-mobile/actions/artifacts/2508660502/zip \ - # --output android/app/build/artifact.zip - - # - name: Unzip artifact - # run: unzip android/app/build/artifact.zip -d android/app/build - - # - name: Cleanup - # run: | - # find android/app/build -type f - # rm android/app/build/outputs/apk/artifact.zip + - name: Create destination path + run: mkdir -p android/app/build + + - name: Download artifact + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + curl -L -H "Authorization: token $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/mattermost/mattermost-mobile/actions/artifacts/2523423750/zip \ + --output android/app/build/artifact.zip + + - name: Unzip artifact + run: unzip android/app/build/artifact.zip -d android/app/build + + - name: Cleanup + run: | + find android/app/build -type f + rm android/app/build/outputs/apk/artifact.zip - name: Set up Android SDK run: | From 9bcf094b08b6073488ab2c2bc09c7d110fbdd1a8 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 22:39:34 +0530 Subject: [PATCH 78/98] download whole build file --- .github/workflows/e2e-android-detox.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 69df5cd6af1..b661baefcab 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -146,10 +146,10 @@ jobs: - name: Unzip artifact run: unzip android/app/build/artifact.zip -d android/app/build - - name: Cleanup - run: | - find android/app/build -type f - rm android/app/build/outputs/apk/artifact.zip + # - name: Cleanup + # run: | + # find android/app/build -type f + # rm android/app/build/outputs/apk/artifact.zip - name: Set up Android SDK run: | From 389de3d3e7313c545b02070fcc19eda377a07d20 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 2 Feb 2025 23:02:05 +0530 Subject: [PATCH 79/98] screen record --- .github/workflows/e2e-android-detox.yml | 283 ++++++++++++------------ 1 file changed, 144 insertions(+), 139 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index b661baefcab..2a5d161c5d8 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -91,142 +91,147 @@ jobs: path: "android/app/build/**/*" detox-android-e2e: - runs-on: ubuntu-latest-8-cores - # needs: build-android-apk - env: - ANDROID_HOME: /usr/local/lib/android/sdk - ANDROID_SDK_ROOT: /usr/local/lib/android/sdk - - steps: - - name: ci/checkout-repo - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - with: - ref: ${{ github.event.pull_request.head.sha }} - - - name: Install Dependencies - run: sudo apt-get update && sudo apt-get install -y libpulse0 - - - name: Enable KVM - run: | - echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules - sudo udevadm control --reload-rules - sudo udevadm trigger --name-match=kvm - - - name: ci/prepare-android-build - uses: ./.github/actions/prepare-android-build - env: - STORE_FILE: "${{ secrets.MM_MOBILE_STORE_FILE }}" - STORE_ALIAS: "${{ secrets.MM_MOBILE_STORE_ALIAS }}" - STORE_PASSWORD: "${{ secrets.MM_MOBILE_STORE_PASSWORD }}" - MATTERMOST_BUILD_GH_TOKEN: "${{ secrets.MATTERMOST_BUILD_GH_TOKEN }}" - - # - name: Download android build files - # uses: actions/download-artifact@v4 - # with: - # name: android-build-files-${{ github.run_id }} - # path: android/app/build - - - name: Install Dependencies - run: | - cd detox - npm install - - - name: Create destination path - run: mkdir -p android/app/build - - - name: Download artifact - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - curl -L -H "Authorization: token $GITHUB_TOKEN" \ - -H "Accept: application/vnd.github.v3+json" \ - https://api.github.com/repos/mattermost/mattermost-mobile/actions/artifacts/2523423750/zip \ - --output android/app/build/artifact.zip - - - name: Unzip artifact - run: unzip android/app/build/artifact.zip -d android/app/build - - # - name: Cleanup - # run: | - # find android/app/build -type f - # rm android/app/build/outputs/apk/artifact.zip - - - name: Set up Android SDK - run: | - export ANDROID_HOME=/usr/local/lib/android/sdk - export PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/emulator:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH - echo "ANDROID_HOME=$ANDROID_HOME" >> $GITHUB_ENV - echo "PATH=$PATH" >> $GITHUB_ENV - - - name: Install scrot, ffmpeg, and Xvfb - run: sudo apt-get install -y scrot ffmpeg xvfb - - - name: Start Xvfb - run: | - Xvfb :99 -screen 0 1920x1080x24 & - export DISPLAY=:99 - echo "DISPLAY=:99" >> $GITHUB_ENV - - - name: Start Video Recording - run: | - ffmpeg -video_size 1920x1080 -framerate 25 -f x11grab -i :99.0 -codec:v libx264 -preset ultrafast -qp 0 screen_recording.mp4 & - echo $! > ffmpeg_pid.txt - - - name: Accept Android licenses - run: | - yes | sdkmanager --licenses || true - - - name: Install Android system image - run: | - sdkmanager "system-images;android-33;default;x86_64" # Use x86_64 for KVM - sdkmanager "platform-tools" "emulator" - - - name: Create and start Android emulator - run: | - cd detox - chmod +x ./create_android_emulator.sh - ./create_android_emulator.sh - - - name: Generate Report Path - id: s3 - run: | - path="${{ github.run_id }}/${{ github.sha }}" - echo "path=$(echo "${path}" | sed 's/\./-/g')" >> ${GITHUB_OUTPUT} - - - name: Save report Detox Dependencies - id: report-link - run: | - cd detox - npm run e2e:save-report - env: - DETOX_AWS_ACCESS_KEY_ID: ${{ secrets.MM_MOBILE_DETOX_AWS_ACCESS_KEY_ID }} - DETOX_AWS_SECRET_ACCESS_KEY: ${{ secrets.MM_MOBILE_DETOX_AWS_SECRET_ACCESS_KEY }} - IOS: false - BUILD_ID: ${{ github.run_id }} - REPORT_PATH: ${{ steps.s3.outputs.path }} - ## These are needed for the MM Webhook report - COMMIT_HASH: ${{ github.sha }} - BRANCH: ${{ github.ref }} - - - name: Take Screenshot on Failure - if: failure() - run: scrot failure_screenshot.png - - - name: Upload Screenshot on Failure - if: failure() - uses: actions/upload-artifact@v4 - with: - name: failure-screenshot - path: failure_screenshot.png - - - name: Stop Android emulator - if: always() # Ensure the emulator is stopped even if the tests fail - run: | - adb emu kill - - - name: Upload android Test Report - if: always() - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - name: android-results-${{ github.run_id }} - path: detox/artifacts/ + runs-on: ubuntu-latest-8-cores + # needs: build-android-apk + env: + ANDROID_HOME: /usr/local/lib/android/sdk + ANDROID_SDK_ROOT: /usr/local/lib/android/sdk + + steps: + - name: ci/checkout-repo + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Install Dependencies + run: sudo apt-get update && sudo apt-get install -y libpulse0 + + - name: Enable KVM + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + + - name: ci/prepare-android-build + uses: ./.github/actions/prepare-android-build + env: + STORE_FILE: "${{ secrets.MM_MOBILE_STORE_FILE }}" + STORE_ALIAS: "${{ secrets.MM_MOBILE_STORE_ALIAS }}" + STORE_PASSWORD: "${{ secrets.MM_MOBILE_STORE_PASSWORD }}" + MATTERMOST_BUILD_GH_TOKEN: "${{ secrets.MATTERMOST_BUILD_GH_TOKEN }}" + + - name: Install Dependencies + run: | + cd detox + npm install + + - name: Create destination path + run: mkdir -p android/app/build + + - name: Download artifact + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + curl -L -H "Authorization: token $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/mattermost/mattermost-mobile/actions/artifacts/2523423750/zip \ + --output android/app/build/artifact.zip + + - name: Unzip artifact + run: unzip android/app/build/artifact.zip -d android/app/build + + - name: List files + run: | + find android/app/build -type f + + - name: Set up Android SDK + run: | + export ANDROID_HOME=/usr/local/lib/android/sdk + export PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/emulator:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH + echo "ANDROID_HOME=$ANDROID_HOME" >> $GITHUB_ENV + echo "PATH=$PATH" >> $GITHUB_ENV + + - name: Install scrot, ffmpeg, and Xvfb + run: sudo apt-get install -y scrot ffmpeg xvfb + + - name: Start Xvfb + run: | + Xvfb :99 -screen 0 1920x1080x24 & + export DISPLAY=:99 + echo "DISPLAY=:99" >> $GITHUB_ENV + + - name: Start Video Recording + run: | + ffmpeg -video_size 1920x1080 -framerate 25 -f x11grab -i :99.0 -codec:v libx264 -preset ultrafast -qp 0 screen_recording.mp4 & + echo $! > ffmpeg_pid.txt + + - name: Accept Android licenses + run: | + yes | sdkmanager --licenses || true + + - name: Install Android system image + run: | + sdkmanager "system-images;android-33;default;x86_64" # Use x86_64 for KVM + sdkmanager "platform-tools" "emulator" + + - name: Create and start Android emulator + run: | + cd detox + chmod +x ./create_android_emulator.sh + ./create_android_emulator.sh + + - name: Generate Report Path + id: s3 + run: | + path="${{ github.run_id }}/${{ github.sha }}" + echo "path=$(echo "${path}" | sed 's/\./-/g')" >> ${GITHUB_OUTPUT} + + - name: Save report Detox Dependencies + id: report-link + run: | + cd detox + npm run e2e:save-report + env: + DETOX_AWS_ACCESS_KEY_ID: ${{ secrets.MM_MOBILE_DETOX_AWS_ACCESS_KEY_ID }} + DETOX_AWS_SECRET_ACCESS_KEY: ${{ secrets.MM_MOBILE_DETOX_AWS_SECRET_ACCESS_KEY }} + IOS: false + BUILD_ID: ${{ github.run_id }} + REPORT_PATH: ${{ steps.s3.outputs.path }} + ## These are needed for the MM Webhook report + COMMIT_HASH: ${{ github.sha }} + BRANCH: ${{ github.ref }} + + - name: Take Screenshot on Failure + if: failure() + run: scrot failure_screenshot.png + + - name: Upload Screenshot on Failure + if: failure() + uses: actions/upload-artifact@v4 + with: + name: failure-screenshot + path: failure_screenshot.png + + - name: Stop Video Recording + if: always() + run: | + kill $(cat ffmpeg_pid.txt) + + - name: Upload Video Recording + if: always() + uses: actions/upload-artifact@v4 + with: + name: screen-recording + path: screen_recording.mp4 + + - name: Stop Android emulator + if: always() # Ensure the emulator is stopped even if the tests fail + run: | + adb emu kill + + - name: Upload android Test Report + if: always() + uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 + with: + name: android-results-${{ github.run_id }} + path: detox/artifacts/ From fa650a5da68c69109e9ec8a4ff80ff87ba41c90d Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 00:35:18 +0530 Subject: [PATCH 80/98] screen record --- .github/workflows/e2e-android-detox.yml | 35 ++++++------------------- detox/create_android_emulator.sh | 2 +- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 2a5d161c5d8..1eb03ad85f8 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -21,7 +21,7 @@ env: DEVICE_NAME: ${{ inputs.ios_device_name }} DEVICE_OS_VERSION: ${{ inputs.ios_device_os_name }} DETOX_AWS_S3_BUCKET: "mattermost-detox-report" - HEADLESS: "true" + HEADLESS: "false" TYPE: ${{ inputs.run-type }} PULL_REQUEST: "https://github.com/mattermost/mattermost-mobile/pull/${{ github.event.number }}" SITE_1_URL: ${{ inputs.MM_TEST_SERVER_URL || 'https://mobile-e2e-site-1.test.mattermost.cloud' }} @@ -104,7 +104,10 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} - name: Install Dependencies - run: sudo apt-get update && sudo apt-get install -y libpulse0 + run: | + sudo apt-get update + sudo apt-get install -y libpulse0 + sudo apt-get install -y scrot ffmpeg xvfb - name: Enable KVM run: | @@ -138,11 +141,9 @@ jobs: --output android/app/build/artifact.zip - name: Unzip artifact - run: unzip android/app/build/artifact.zip -d android/app/build - - - name: List files run: | - find android/app/build -type f + unzip android/app/build/artifact.zip -d android/app/build + rm -rf android/app/build/artifact.zip - name: Set up Android SDK run: | @@ -151,27 +152,19 @@ jobs: echo "ANDROID_HOME=$ANDROID_HOME" >> $GITHUB_ENV echo "PATH=$PATH" >> $GITHUB_ENV - - name: Install scrot, ffmpeg, and Xvfb - run: sudo apt-get install -y scrot ffmpeg xvfb - - name: Start Xvfb run: | Xvfb :99 -screen 0 1920x1080x24 & export DISPLAY=:99 echo "DISPLAY=:99" >> $GITHUB_ENV - - name: Start Video Recording - run: | - ffmpeg -video_size 1920x1080 -framerate 25 -f x11grab -i :99.0 -codec:v libx264 -preset ultrafast -qp 0 screen_recording.mp4 & - echo $! > ffmpeg_pid.txt - - name: Accept Android licenses run: | yes | sdkmanager --licenses || true - name: Install Android system image run: | - sdkmanager "system-images;android-33;default;x86_64" # Use x86_64 for KVM + sdkmanager "system-images;android-33;default;x86_64" sdkmanager "platform-tools" "emulator" - name: Create and start Android emulator @@ -212,18 +205,6 @@ jobs: name: failure-screenshot path: failure_screenshot.png - - name: Stop Video Recording - if: always() - run: | - kill $(cat ffmpeg_pid.txt) - - - name: Upload Video Recording - if: always() - uses: actions/upload-artifact@v4 - with: - name: screen-recording - path: screen_recording.mp4 - - name: Stop Android emulator if: always() # Ensure the emulator is stopped even if the tests fail run: | diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index fc1eca0961e..cf25f87c9ca 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -59,7 +59,7 @@ echo "Starting the emulator..." if [[ "$CI" == "true" || "$(uname -s)" == "Linux" ]]; then echo "Starting the emulator with KVM..." - emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu swiftshader_indirect -accel on -qemu -m 4096 & + emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu host -accel on -qemu -m 4096 & else emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu guest -verbose -qemu -vnc :0 fi From 578a60d4cb856e9377e61940e54f2a8e1596d963 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 01:00:42 +0530 Subject: [PATCH 81/98] install app in emulator --- detox/create_android_emulator.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index cf25f87c9ca..9df5d4fda7a 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -82,10 +82,17 @@ if [[ "$CI" == "true" ]]; then done fi +if [[ "$CI" == "true" ]]; then + # Install the app + echo "Installing the app..." + cd .. + adb install -r android/app/build/outputs/apk/debug/app-debug.apk +fi + # Start the server -cd .. +echo "Starting the server..." npm run start & -sleep 180 +sleep 120 # Run tests echo "Running tests..." From 0aff8a9d92cbad0444361677666cc16f2e6aed09 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 04:10:17 +0530 Subject: [PATCH 82/98] wait for metro server --- detox/create_android_emulator.sh | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index 9df5d4fda7a..7f065fd1e9a 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -87,12 +87,32 @@ if [[ "$CI" == "true" ]]; then echo "Installing the app..." cd .. adb install -r android/app/build/outputs/apk/debug/app-debug.apk -fi -# Start the server -echo "Starting the server..." -npm run start & -sleep 120 + # Verify the app is installed + echo "Verifying the app is installed..." + adb shell pm list packages | grep "com.mattermost.rnbeta" && echo "App is installed." || echo "App is not installed." + + # Start the server + echo "Starting the server..." + npm run start & + + # Wait for the server to be ready + timeout=120 + interval=5 + elapsed=0 + + while ! nc -z localhost 8081; do + if [[ $elapsed -ge $timeout ]]; then + echo "Server did not start within 3 minutes." + exit 1 + fi + echo "Waiting for the server to be ready..." + sleep $interval + elapsed=$((elapsed + interval)) + done + + echo "Server is ready." +fi # Run tests echo "Running tests..." From 04aa89f3548b259c984410e116b3c0969afbf567 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 04:24:23 +0530 Subject: [PATCH 83/98] test launchAPP --- detox/e2e/support/server_api/system.ts | 7 +++++++ detox/e2e/support/server_api/user.ts | 3 +++ detox/e2e/test/setup.ts | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/detox/e2e/support/server_api/system.ts b/detox/e2e/support/server_api/system.ts index 1bbcec80fe7..8bc8578b2ad 100644 --- a/detox/e2e/support/server_api/system.ts +++ b/detox/e2e/support/server_api/system.ts @@ -27,7 +27,12 @@ import {apiUploadFile, getResponseFromError} from './common'; * @param {string} baseUrl - the base server URL */ export const apiCheckSystemHealth = async (baseUrl: string): Promise => { + // eslint-disable-next-line no-console + console.log('IN apiCheckSystemHealth *************************'); const {data} = await apiPingServerStatus(baseUrl); + // eslint-disable-next-line no-console + console.log('apiPingServerStatus *************************', data.status); + jestExpect(data.status).toEqual('OK'); jestExpect(data.database_status).toEqual('OK'); jestExpect(data.filestore_status).toEqual('OK'); @@ -86,6 +91,8 @@ export const apiGetConfig = async (baseUrl: string): Promise => { * @return {Object} returns {data} on success or {error, status} on error */ export const apiPingServerStatus = async (baseUrl: string): Promise => { + // eslint-disable-next-line no-console + console.log('IN apiPingServerStatus *************************'); try { const response = await client.get(`${baseUrl}/api/v4/system/ping?get_server_status=true`); return {data: response.data}; diff --git a/detox/e2e/support/server_api/user.ts b/detox/e2e/support/server_api/user.ts index afd1d046d32..fc1134a3ae5 100644 --- a/detox/e2e/support/server_api/user.ts +++ b/detox/e2e/support/server_api/user.ts @@ -25,6 +25,9 @@ import {getResponseFromError} from './common'; * @return {Object} returns {user, status} on success or {error, status} on error */ export const apiAdminLogin = (baseUrl: string): any => { + // eslint-disable-next-line no-console + console.log('In apiAdminLogin *************************', baseUrl, adminUsername, adminPassword); + return apiLogin(baseUrl, { username: adminUsername, password: adminPassword, diff --git a/detox/e2e/test/setup.ts b/detox/e2e/test/setup.ts index edd07e3b782..4e752aa10a4 100644 --- a/detox/e2e/test/setup.ts +++ b/detox/e2e/test/setup.ts @@ -5,11 +5,17 @@ import {Plugin, System, User} from '@support/server_api'; import {siteOneUrl} from '@support/test_config'; beforeAll(async () => { + // eslint-disable-next-line no-console + console.log('Setup started *************************'); + // Login as sysadmin and reset server configuration await System.apiCheckSystemHealth(siteOneUrl); await User.apiAdminLogin(siteOneUrl); await Plugin.apiDisableNonPrepackagedPlugins(siteOneUrl); + // Add wait time before launching the app + await new Promise((resolve) => setTimeout(resolve, 5000)); + await device.launchApp({ newInstance: true, launchArgs: {detoxPrintBusyIdleResources: 'YES'}, From 1c2471a0388814b7b7b1f7b0306eeabc4e7b8333 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 05:20:24 +0530 Subject: [PATCH 84/98] launch app with timeout --- detox/.detoxrc.json | 5 ++++- detox/create_android_emulator.sh | 2 +- detox/e2e/support/server_api/system.ts | 6 ------ detox/e2e/test/setup.ts | 3 --- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/detox/.detoxrc.json b/detox/.detoxrc.json index 8fd9e431766..1773baf002b 100644 --- a/detox/.detoxrc.json +++ b/detox/.detoxrc.json @@ -52,7 +52,10 @@ }, "android.emu.debug": { "device": "android.emulator", - "app": "android.debug" + "app": "android.debug", + "launchArgs": { + "timeout": 120000 + } }, "android.emu.release": { "device": "android.emulator", diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index 7f065fd1e9a..10e3e2e2413 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -117,4 +117,4 @@ fi # Run tests echo "Running tests..." cd detox -npm run e2e:android-test -- about.e2e.ts +npm run e2e:android-test --loglevel -- about.e2e.ts diff --git a/detox/e2e/support/server_api/system.ts b/detox/e2e/support/server_api/system.ts index 8bc8578b2ad..fe5696339e8 100644 --- a/detox/e2e/support/server_api/system.ts +++ b/detox/e2e/support/server_api/system.ts @@ -27,11 +27,7 @@ import {apiUploadFile, getResponseFromError} from './common'; * @param {string} baseUrl - the base server URL */ export const apiCheckSystemHealth = async (baseUrl: string): Promise => { - // eslint-disable-next-line no-console - console.log('IN apiCheckSystemHealth *************************'); const {data} = await apiPingServerStatus(baseUrl); - // eslint-disable-next-line no-console - console.log('apiPingServerStatus *************************', data.status); jestExpect(data.status).toEqual('OK'); jestExpect(data.database_status).toEqual('OK'); @@ -91,8 +87,6 @@ export const apiGetConfig = async (baseUrl: string): Promise => { * @return {Object} returns {data} on success or {error, status} on error */ export const apiPingServerStatus = async (baseUrl: string): Promise => { - // eslint-disable-next-line no-console - console.log('IN apiPingServerStatus *************************'); try { const response = await client.get(`${baseUrl}/api/v4/system/ping?get_server_status=true`); return {data: response.data}; diff --git a/detox/e2e/test/setup.ts b/detox/e2e/test/setup.ts index 4e752aa10a4..14566a5bf09 100644 --- a/detox/e2e/test/setup.ts +++ b/detox/e2e/test/setup.ts @@ -5,9 +5,6 @@ import {Plugin, System, User} from '@support/server_api'; import {siteOneUrl} from '@support/test_config'; beforeAll(async () => { - // eslint-disable-next-line no-console - console.log('Setup started *************************'); - // Login as sysadmin and reset server configuration await System.apiCheckSystemHealth(siteOneUrl); await User.apiAdminLogin(siteOneUrl); From a5f6c8801b286703282b79965d0617a8530c4ef9 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 05:45:36 +0530 Subject: [PATCH 85/98] reverse port forwarding --- detox/.detoxrc.json | 5 +---- detox/create_android_emulator.sh | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/detox/.detoxrc.json b/detox/.detoxrc.json index 1773baf002b..8fd9e431766 100644 --- a/detox/.detoxrc.json +++ b/detox/.detoxrc.json @@ -52,10 +52,7 @@ }, "android.emu.debug": { "device": "android.emulator", - "app": "android.debug", - "launchArgs": { - "timeout": 120000 - } + "app": "android.debug" }, "android.emu.release": { "device": "android.emulator", diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index 10e3e2e2413..c23f40e5e0d 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -114,6 +114,10 @@ if [[ "$CI" == "true" ]]; then echo "Server is ready." fi +# Set up ADB reverse port forwarding +echo "Setting up ADB reverse port forwarding..." +adb reverse tcp:8081 tcp:8081 + # Run tests echo "Running tests..." cd detox From ba9dd110248721f8612e5950b087475dd8431cd7 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 06:37:44 +0530 Subject: [PATCH 86/98] Fix report --- .github/workflows/e2e-android-detox.yml | 1 + detox/e2e/config.js | 3 +-- detox/e2e/support/server_api/system.ts | 1 - detox/e2e/support/server_api/user.ts | 3 --- detox/e2e/test/setup.ts | 3 --- detox/save_report.js | 2 ++ 6 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 1eb03ad85f8..d28b3cd21c3 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -35,6 +35,7 @@ env: WEBHOOK_URL: ${{ secrets.MM_MOBILE_E2E_WEBHOOK_URL }} FAILURE_MESSAGE: "Something has failed" RUNNING_E2E: "true" + IOS: "false" concurrency: group: "${{ github.workflow }}-${{ github.event.pull_request.number }}-${{ github.event.label.name }}" diff --git a/detox/e2e/config.js b/detox/e2e/config.js index ef2f0194b2d..574fb3a9a3b 100644 --- a/detox/e2e/config.js +++ b/detox/e2e/config.js @@ -3,13 +3,12 @@ const platform = process.env.IOS === 'true' ? 'ios' : 'android'; const shard = process.env.CI_NODE_INDEX ? process.env.CI_NODE_INDEX : ''; -const testTimeout = process.env.CI ? 300000 : 120000; module.exports = { setupFilesAfterEnv: ['./test/setup.ts'], maxWorkers: 1, testSequencer: './custom_sequencer.js', - testTimeout, + testTimeout: 120000, rootDir: '.', testMatch: ['/test/**/*.e2e.ts'], transform: { diff --git a/detox/e2e/support/server_api/system.ts b/detox/e2e/support/server_api/system.ts index fe5696339e8..1bbcec80fe7 100644 --- a/detox/e2e/support/server_api/system.ts +++ b/detox/e2e/support/server_api/system.ts @@ -28,7 +28,6 @@ import {apiUploadFile, getResponseFromError} from './common'; */ export const apiCheckSystemHealth = async (baseUrl: string): Promise => { const {data} = await apiPingServerStatus(baseUrl); - jestExpect(data.status).toEqual('OK'); jestExpect(data.database_status).toEqual('OK'); jestExpect(data.filestore_status).toEqual('OK'); diff --git a/detox/e2e/support/server_api/user.ts b/detox/e2e/support/server_api/user.ts index fc1134a3ae5..afd1d046d32 100644 --- a/detox/e2e/support/server_api/user.ts +++ b/detox/e2e/support/server_api/user.ts @@ -25,9 +25,6 @@ import {getResponseFromError} from './common'; * @return {Object} returns {user, status} on success or {error, status} on error */ export const apiAdminLogin = (baseUrl: string): any => { - // eslint-disable-next-line no-console - console.log('In apiAdminLogin *************************', baseUrl, adminUsername, adminPassword); - return apiLogin(baseUrl, { username: adminUsername, password: adminPassword, diff --git a/detox/e2e/test/setup.ts b/detox/e2e/test/setup.ts index 14566a5bf09..edd07e3b782 100644 --- a/detox/e2e/test/setup.ts +++ b/detox/e2e/test/setup.ts @@ -10,9 +10,6 @@ beforeAll(async () => { await User.apiAdminLogin(siteOneUrl); await Plugin.apiDisableNonPrepackagedPlugins(siteOneUrl); - // Add wait time before launching the app - await new Promise((resolve) => setTimeout(resolve, 5000)); - await device.launchApp({ newInstance: true, launchArgs: {detoxPrintBusyIdleResources: 'YES'}, diff --git a/detox/save_report.js b/detox/save_report.js index 0b59d8829be..db8f7c8fba7 100644 --- a/detox/save_report.js +++ b/detox/save_report.js @@ -106,6 +106,8 @@ const saveReport = async () => { const xml = fse.readFileSync(combinedFilePath); const {testsuites} = convertXmlToJson(xml); + console.log('**************** Tests:', testsuites.tests); + // Generate short summary, write to file and then send report via webhook const allTests = getAllTests(testsuites); const summary = generateShortSummary(allTests); From b20d3e77fed3366bdf8fcac3c255e8054f703ac6 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 08:51:22 +0530 Subject: [PATCH 87/98] Fix report --- detox/save_report.js | 8 ++++++-- detox/utils/report.js | 32 +++++++++++++++++++------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/detox/save_report.js b/detox/save_report.js index db8f7c8fba7..8f640df04d8 100644 --- a/detox/save_report.js +++ b/detox/save_report.js @@ -99,14 +99,18 @@ const saveReport = async () => { // Merge all XML reports into one single XML report const platform = process.env.IOS === 'true' ? 'ios' : 'android'; const combinedFilePath = `${ARTIFACTS_DIR}/${platform}-combined.xml`; + + console.log('Combined file path:', combinedFilePath); + console.log('Merfe file arg:', [`${ARTIFACTS_DIR}/${platform}-results*/${platform}-junit*.xml`]); + await mergeFiles(path.join(__dirname, combinedFilePath), [`${ARTIFACTS_DIR}/${platform}-results*/${platform}-junit*.xml`]); console.log(`Merged, check ${combinedFilePath}`); // Read XML from a file const xml = fse.readFileSync(combinedFilePath); - const {testsuites} = convertXmlToJson(xml); + const {testsuites} = convertXmlToJson(xml, platform); - console.log('**************** Tests:', testsuites.tests); + console.log('**************** Tests:', testsuites); // Generate short summary, write to file and then send report via webhook const allTests = getAllTests(testsuites); diff --git a/detox/utils/report.js b/detox/utils/report.js index c0bc53fb944..32092006438 100644 --- a/detox/utils/report.js +++ b/detox/utils/report.js @@ -11,24 +11,30 @@ const {ARTIFACTS_DIR} = require('./constants'); const MAX_FAILED_TITLES = 5; -function convertXmlToJson(xml) { - const platform = process.env.IOS === 'true' ? 'ios' : 'android'; +function convertXmlToJson(xml, platform) { const jsonFile = `${ARTIFACTS_DIR}/${platform}-junit.json`; - // Convert XML to JSON - xml2js.parseString(xml, {mergeAttrs: true}, (err, result) => { - if (err) { - throw err; - } + return new Promise((resolve, reject) => { + // Convert XML to JSON + xml2js.parseString(xml, {mergeAttrs: true}, (parseErr, result) => { + if (parseErr) { + reject(parseErr); + return; + } - // Convert result to a JSON string - const json = JSON.stringify(result, null, 4); + // Convert result to a JSON string + const json = JSON.stringify(result, null, 4); - // Save JSON in a file - fse.writeFileSync(jsonFile, json); + // Save JSON in a file + fse.writeJson(jsonFile, json, (err) => { + if (err) { + reject(err); + return; + } + resolve(readJsonFromFile(jsonFile)); + }); + }); }); - - return readJsonFromFile(jsonFile); } function getAllTests(testSuites) { From 2c40864aaa220e4b10281d0ab8cf95396cfa075d Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 09:47:53 +0530 Subject: [PATCH 88/98] Fix report --- detox/utils/report.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detox/utils/report.js b/detox/utils/report.js index 32092006438..ad3d0b67d07 100644 --- a/detox/utils/report.js +++ b/detox/utils/report.js @@ -31,7 +31,7 @@ function convertXmlToJson(xml, platform) { reject(err); return; } - resolve(readJsonFromFile(jsonFile)); + resolve(json); }); }); }); From 0bc9c8fc2c328d8cc501179c739c3f64d668a27b Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 10:20:14 +0530 Subject: [PATCH 89/98] debug report --- detox/utils/report.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/detox/utils/report.js b/detox/utils/report.js index ad3d0b67d07..95a2a81a4cd 100644 --- a/detox/utils/report.js +++ b/detox/utils/report.js @@ -14,10 +14,16 @@ const MAX_FAILED_TITLES = 5; function convertXmlToJson(xml, platform) { const jsonFile = `${ARTIFACTS_DIR}/${platform}-junit.json`; + console.log('=============== xml', xml); return new Promise((resolve, reject) => { + console.log('=============== In promise', xml); + // Convert XML to JSON xml2js.parseString(xml, {mergeAttrs: true}, (parseErr, result) => { + console.log('------------- in xml2js', result); + if (parseErr) { + console.log('=============== parseErr', parseErr); reject(parseErr); return; } @@ -25,12 +31,17 @@ function convertXmlToJson(xml, platform) { // Convert result to a JSON string const json = JSON.stringify(result, null, 4); + console.log('============= json', json); + // Save JSON in a file fse.writeJson(jsonFile, json, (err) => { if (err) { + console.log('=============== err', err); reject(err); return; } + + console.log('=============== jsonFile', jsonFile); resolve(json); }); }); From b582befb52900f2cd7c92c22e5568efbedbdae5c Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 19:51:16 +0530 Subject: [PATCH 90/98] modular shell script --- .github/workflows/e2e-android-detox.yml | 16 +-- detox/create_android_emulator.sh | 180 ++++++++++++------------ 2 files changed, 93 insertions(+), 103 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index d28b3cd21c3..9f6178d4e19 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -174,6 +174,11 @@ jobs: chmod +x ./create_android_emulator.sh ./create_android_emulator.sh + - name: Run Detox tests + run: | + cd detox + npm run e2e:android -- about.e2e.ts + - name: Generate Report Path id: s3 run: | @@ -195,17 +200,6 @@ jobs: COMMIT_HASH: ${{ github.sha }} BRANCH: ${{ github.ref }} - - name: Take Screenshot on Failure - if: failure() - run: scrot failure_screenshot.png - - - name: Upload Screenshot on Failure - if: failure() - uses: actions/upload-artifact@v4 - with: - name: failure-screenshot - path: failure_screenshot.png - - name: Stop Android emulator if: always() # Ensure the emulator is stopped even if the tests fail run: | diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index c23f40e5e0d..4f55e864571 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -1,124 +1,120 @@ #!/bin/bash # Reference: Download Android (AOSP) Emulators - https://github.com/wix/Detox/blob/master/docs/guide/android-dev-env.md#android-aosp-emulators -# sdkmanager "system-images;android-31;default;arm64-v8a" -# sdkmanager --licenses set -ex set -o pipefail SDK_VERSION=33 -NAME="detox_pixel_4_xl_api_${SDK_VERSION}" - -# Set ANDROID_AVD_HOME to the current directory -if [[ "$CI" == "true" ]]; then - export ANDROID_AVD_HOME=$(pwd)/.android/avd - mkdir -p $ANDROID_AVD_HOME -fi - -if emulator -list-avds | grep -q $NAME; then - echo "'${NAME}' Android virtual device already exists." -else - CPU_ARCH_FAMILY='' - CPU_ARCH='' +AVD_NAME="detox_pixel_4_xl_api_${SDK_VERSION}" + +setup_avd_home() { + if [[ "$CI" == "true" ]]; then + export ANDROID_AVD_HOME=$(pwd)/.android/avd + mkdir -p "$ANDROID_AVD_HOME" + fi +} + +get_cpu_architecture() { if [[ $(uname -p) == 'arm' ]]; then - CPU_ARCH_FAMILY=arm64-v8a - CPU_ARCH=arm64 + echo "arm64-v8a arm64" + else + echo "x86_64 x86_64" + fi +} + +create_avd() { + local cpu_arch_family cpu_arch + read cpu_arch_family cpu_arch < <(get_cpu_architecture) + + avdmanager create avd -n "$AVD_NAME" -k "system-images;android-${SDK_VERSION};default;${cpu_arch_family}" -p "$AVD_NAME" -d 'pixel' + + cp -r android_emulator/ "$AVD_NAME/" + sed -i -e "s|AvdId = change_avd_id|AvdId = ${AVD_NAME}|g" "$AVD_NAME/config.ini" + sed -i -e "s|avd.ini.displayname = change_avd_displayname|avd.ini.displayname = Detox Pixel 4 XL API ${SDK_VERSION}|g" "$AVD_NAME/config.ini" + sed -i -e "s|abi.type = change_type|abi.type = ${cpu_arch_family}|g" "$AVD_NAME/config.ini" + sed -i -e "s|hw.cpu.arch = change_cpu_arch|hw.cpu.arch = ${cpu_arch}|g" "$AVD_NAME/config.ini" + sed -i -e "s|image.sysdir.1 = change_to_image_sysdir/|image.sysdir.1 = system-images/android-${SDK_VERSION}/default/${cpu_arch_family}/|g" "$AVD_NAME/config.ini" + sed -i -e "s|skin.path = change_to_absolute_path/pixel_4_xl_skin|skin.path = $(pwd)/${AVD_NAME}/pixel_4_xl_skin|g" "$AVD_NAME/config.ini" + + echo "hw.cpu.ncore=5" >> "$AVD_NAME/config.ini" + echo "Android virtual device successfully created: ${AVD_NAME}" +} + +start_adb_server() { + echo "Restarting ADB server..." + adb kill-server + adb start-server +} + +start_emulator() { + echo "Starting the emulator..." + local emulator_opts="-avd $AVD_NAME -no-snapshot -no-boot-anim -no-audio -no-window" + + if [[ "$CI" == "true" || "$(uname -s)" == "Linux" ]]; then + emulator $emulator_opts -gpu host -accel on -qemu -m 4096 & else - CPU_ARCH_FAMILY=x86_64 - CPU_ARCH=x86_64 + emulator $emulator_opts -gpu guest -verbose -qemu -vnc :0 fi +} - # Create virtual device in a relative "detox_pixel_4_xl_api_${SDK_VERSION}" folder - avdmanager create avd -n $NAME -k "system-images;android-${SDK_VERSION};default;${CPU_ARCH_FAMILY}" -p $NAME -d 'pixel' - - # Copy predefined config and skin - cp -r android_emulator/ $NAME/ - sed -i -e "s|AvdId = change_avd_id|AvdId = ${NAME}|g" $NAME/config.ini - sed -i -e "s|avd.ini.displayname = change_avd_displayname|avd.ini.displayname = Detox Pixel 4 XL API ${SDK_VERSION}|g" $NAME/config.ini - sed -i -e "s|abi.type = change_type|abi.type = ${CPU_ARCH_FAMILY}|g" $NAME/config.ini - sed -i -e "s|hw.cpu.arch = change_cpu_arch|hw.cpu.arch = ${CPU_ARCH}|g" $NAME/config.ini - sed -i -e "s|image.sysdir.1 = change_to_image_sysdir/|image.sysdir.1 = system-images/android-${SDK_VERSION}/default/${CPU_ARCH_FAMILY}/|g" $NAME/config.ini - sed -i -e "s|skin.path = change_to_absolute_path/pixel_4_xl_skin|skin.path = $(pwd)/${NAME}/pixel_4_xl_skin|g" $NAME/config.ini - - # Set the number of CPU cores in config.ini - echo "hw.cpu.ncore=5" >> $NAME/config.ini - - echo "Android virtual device successfully created: ${NAME}" -fi - -# Kill existing ADB server -echo "Killing existing ADB server..." -adb kill-server - -# Start ADB server -echo "Starting ADB server..." -adb start-server - -# Start the emulator -echo "Starting the emulator..." - -if [[ "$CI" == "true" || "$(uname -s)" == "Linux" ]]; then - echo "Starting the emulator with KVM..." - emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu host -accel on -qemu -m 4096 & -else - emulator -avd $NAME -no-snapshot -no-boot-anim -no-audio -no-window -gpu guest -verbose -qemu -vnc :0 -fi - -if [[ "$CI" == "true" ]]; then - # Wait for the emulator to boot - echo "Waiting for the emulator to boot..." - adb wait-for-device +wait_for_emulator() { + if [[ "$CI" != "true" ]]; then return; fi - # Check if the emulator is fully booted - echo "Checking if the emulator is fully booted..." - while true; do - boot_completed=$(adb shell getprop sys.boot_completed | tr -d '\r') - if [[ "$boot_completed" == "1" ]]; then - echo "Emulator is fully booted." - break - fi - echo "Waiting for emulator to boot..." + echo "Waiting for emulator to boot..." + adb wait-for-device + until [[ "$(adb shell getprop sys.boot_completed | tr -d '\r')" == "1" ]]; do + echo "Waiting for emulator to fully boot..." sleep 10 done -fi + echo "Emulator is fully booted." +} -if [[ "$CI" == "true" ]]; then - # Install the app +install_app() { echo "Installing the app..." - cd .. adb install -r android/app/build/outputs/apk/debug/app-debug.apk - - # Verify the app is installed - echo "Verifying the app is installed..." adb shell pm list packages | grep "com.mattermost.rnbeta" && echo "App is installed." || echo "App is not installed." +} - # Start the server +start_server() { echo "Starting the server..." npm run start & + local timeout=120 interval=5 elapsed=0 - # Wait for the server to be ready - timeout=120 - interval=5 - elapsed=0 - - while ! nc -z localhost 8081; do + until nc -z localhost 8081; do if [[ $elapsed -ge $timeout ]]; then echo "Server did not start within 3 minutes." exit 1 fi - echo "Waiting for the server to be ready..." + echo "Waiting for server to be ready..." sleep $interval elapsed=$((elapsed + interval)) done - echo "Server is ready." -fi +} + +setup_adb_reverse() { + echo "Setting up ADB reverse port forwarding..." + adb reverse tcp:8081 tcp:8081 +} + +main() { + setup_avd_home + + if ! emulator -list-avds | grep -q "$AVD_NAME"; then + create_avd + else + echo "'${AVD_NAME}' Android virtual device already exists." + fi + + start_adb_server + start_emulator + wait_for_emulator -# Set up ADB reverse port forwarding -echo "Setting up ADB reverse port forwarding..." -adb reverse tcp:8081 tcp:8081 + if [[ "$CI" == "true" ]]; then + install_app + start_server + setup_adb_reverse + fi +} -# Run tests -echo "Running tests..." -cd detox -npm run e2e:android-test --loglevel -- about.e2e.ts +main From ed24a92c5168c9685197e148b0502fb4123e95a1 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 20:24:17 +0530 Subject: [PATCH 91/98] modular shell script --- detox/create_android_emulator.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index 4f55e864571..cca7f0c7549 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -71,12 +71,13 @@ wait_for_emulator() { install_app() { echo "Installing the app..." - adb install -r android/app/build/outputs/apk/debug/app-debug.apk + adb install -r ../android/app/build/outputs/apk/debug/app-debug.apk adb shell pm list packages | grep "com.mattermost.rnbeta" && echo "App is installed." || echo "App is not installed." } start_server() { echo "Starting the server..." + cd .. npm run start & local timeout=120 interval=5 elapsed=0 From 3da2faea6279041e0abf28b30b87f3e2909476f6 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 20:30:36 +0530 Subject: [PATCH 92/98] modular shell script --- .github/workflows/e2e-android-detox.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 9f6178d4e19..9551f434cb9 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -177,7 +177,7 @@ jobs: - name: Run Detox tests run: | cd detox - npm run e2e:android -- about.e2e.ts + npm run e2e:android-test -- about.e2e.ts - name: Generate Report Path id: s3 From 51e9d5cc31991b4bc5360d70db3b1cab3546c702 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 20:50:34 +0530 Subject: [PATCH 93/98] check running tests --- .github/workflows/e2e-android-detox.yml | 8 ++++---- detox/create_android_emulator.sh | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 9551f434cb9..46959bccfff 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -174,10 +174,10 @@ jobs: chmod +x ./create_android_emulator.sh ./create_android_emulator.sh - - name: Run Detox tests - run: | - cd detox - npm run e2e:android-test -- about.e2e.ts + # - name: Run Detox tests + # run: | + # cd detox + # npm run e2e:android-test -- about.e2e.ts - name: Generate Report Path id: s3 diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index cca7f0c7549..8a52a28d182 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -98,6 +98,11 @@ setup_adb_reverse() { adb reverse tcp:8081 tcp:8081 } +run_detox_tests() { + echo "Running Detox tests..." + npm run e2e:android-test -- about.e2e.ts +} + main() { setup_avd_home @@ -116,6 +121,8 @@ main() { start_server setup_adb_reverse fi + + run_detox_tests } main From bcdaa00f5aa5ecf5cf4b80da1c0816d866acf16c Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 20:57:10 +0530 Subject: [PATCH 94/98] check running tests --- detox/create_android_emulator.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index 8a52a28d182..31d19aef92c 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -100,6 +100,7 @@ setup_adb_reverse() { run_detox_tests() { echo "Running Detox tests..." + cd detox npm run e2e:android-test -- about.e2e.ts } From 5ed87cc6b368075c3a06f6816b78942fe7bd3852 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 22:12:20 +0530 Subject: [PATCH 95/98] add more test files --- .github/workflows/e2e-android-detox.yml | 8 ++++---- detox/create_android_emulator.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 46959bccfff..7a619f3db51 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -174,10 +174,10 @@ jobs: chmod +x ./create_android_emulator.sh ./create_android_emulator.sh - # - name: Run Detox tests - # run: | - # cd detox - # npm run e2e:android-test -- about.e2e.ts + - name: Run Detox tests + run: | + cd detox + npm run e2e:android-test -- about.e2e.ts account_menu.e2e.ts - name: Generate Report Path id: s3 diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index 31d19aef92c..66b96aaad0e 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -101,7 +101,7 @@ setup_adb_reverse() { run_detox_tests() { echo "Running Detox tests..." cd detox - npm run e2e:android-test -- about.e2e.ts + npm run e2e:android-test -- about.e2e.ts account_menu.e2e.ts } main() { From 33ebb838755c9278de76cfde8dd4620eb3821d7c Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 22:38:29 +0530 Subject: [PATCH 96/98] add more test files --- .github/workflows/e2e-android-detox.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/e2e-android-detox.yml b/.github/workflows/e2e-android-detox.yml index 7a619f3db51..9f0607d418f 100644 --- a/.github/workflows/e2e-android-detox.yml +++ b/.github/workflows/e2e-android-detox.yml @@ -174,11 +174,6 @@ jobs: chmod +x ./create_android_emulator.sh ./create_android_emulator.sh - - name: Run Detox tests - run: | - cd detox - npm run e2e:android-test -- about.e2e.ts account_menu.e2e.ts - - name: Generate Report Path id: s3 run: | From 39fe54a34481d2151466b5908458104b0f55129a Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Mon, 3 Feb 2025 23:54:02 +0530 Subject: [PATCH 97/98] fix reporting --- detox/save_report.js | 2 -- detox/utils/report.js | 40 +++++++++++----------------------------- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/detox/save_report.js b/detox/save_report.js index 8f640df04d8..867458e88e3 100644 --- a/detox/save_report.js +++ b/detox/save_report.js @@ -110,8 +110,6 @@ const saveReport = async () => { const xml = fse.readFileSync(combinedFilePath); const {testsuites} = convertXmlToJson(xml, platform); - console.log('**************** Tests:', testsuites); - // Generate short summary, write to file and then send report via webhook const allTests = getAllTests(testsuites); const summary = generateShortSummary(allTests); diff --git a/detox/utils/report.js b/detox/utils/report.js index 95a2a81a4cd..c9d3d5e734c 100644 --- a/detox/utils/report.js +++ b/detox/utils/report.js @@ -14,38 +14,20 @@ const MAX_FAILED_TITLES = 5; function convertXmlToJson(xml, platform) { const jsonFile = `${ARTIFACTS_DIR}/${platform}-junit.json`; - console.log('=============== xml', xml); - return new Promise((resolve, reject) => { - console.log('=============== In promise', xml); - - // Convert XML to JSON - xml2js.parseString(xml, {mergeAttrs: true}, (parseErr, result) => { - console.log('------------- in xml2js', result); - - if (parseErr) { - console.log('=============== parseErr', parseErr); - reject(parseErr); - return; - } - - // Convert result to a JSON string - const json = JSON.stringify(result, null, 4); - - console.log('============= json', json); + // Convert XML to JSON + xml2js.parseString(xml, {mergeAttrs: true}, (err, result) => { + if (err) { + throw err; + } - // Save JSON in a file - fse.writeJson(jsonFile, json, (err) => { - if (err) { - console.log('=============== err', err); - reject(err); - return; - } + // Convert result to a JSON string + const json = JSON.stringify(result, null, 4); - console.log('=============== jsonFile', jsonFile); - resolve(json); - }); - }); + // Save JSON in a file + fse.writeFileSync(jsonFile, json); }); + + return readJsonFromFile(jsonFile); } function getAllTests(testSuites) { From c020bc86ee1e5cabc0511ff345e1575581b81052 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Tue, 4 Feb 2025 07:55:54 +0530 Subject: [PATCH 98/98] Check Running e2e var is picked up --- detox/create_android_emulator.sh | 2 +- index.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/detox/create_android_emulator.sh b/detox/create_android_emulator.sh index 66b96aaad0e..2ed0b566045 100755 --- a/detox/create_android_emulator.sh +++ b/detox/create_android_emulator.sh @@ -78,7 +78,7 @@ install_app() { start_server() { echo "Starting the server..." cd .. - npm run start & + RUNNING_E2E=true npm run start & local timeout=120 interval=5 elapsed=0 until nc -z localhost 8081; do diff --git a/index.ts b/index.ts index 775a11e6e71..2a87c4cd233 100644 --- a/index.ts +++ b/index.ts @@ -4,6 +4,7 @@ import TurboLogger from '@mattermost/react-native-turbo-log'; import {LogBox, Platform, UIManager} from 'react-native'; import ViewReactNativeStyleAttributes from 'react-native/Libraries/Components/View/ReactNativeStyleAttributes'; +import {RUNNING_E2E} from 'react-native-dotenv'; import 'react-native-gesture-handler'; import {Navigation} from 'react-native-navigation'; @@ -29,10 +30,8 @@ if (__DEV__) { ]); // Ignore all notifications if running e2e - // eslint-disable-next-line no-process-env - const isRunningE2e = process.env.RUNNING_E2E === 'true'; - // eslint-disable-next-line no-process-env - logInfo(`RUNNING_E2E: ${process.env.RUNNING_E2E}, isRunningE2e: ${isRunningE2e}`); + const isRunningE2e = RUNNING_E2E === 'true'; + logInfo(`RUNNING_E2E: ${RUNNING_E2E}, isRunningE2e: ${isRunningE2e}`); if (isRunningE2e) { LogBox.ignoreAllLogs(true); }