Skip to content

Commit

Permalink
build-macos-latest
Browse files Browse the repository at this point in the history
  • Loading branch information
yasserfaraazkhan committed Jun 26, 2024
1 parent e0df643 commit 24d1542
Showing 1 changed file with 49 additions and 121 deletions.
170 changes: 49 additions & 121 deletions .github/workflows/e2e-detox-android-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,129 +95,57 @@ jobs:
# device_name: ${{ env.DEVICE_NAME }}
# device_os_version: ${{env.DEVICE_OS_VERSION}}

android:
name: Android
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
api-level: [31]
# TODO: Let's not care about different APIs for now
# api-level: [31, 32, 33, 34]
rn-version: ['latest']
build:
runs-on: macos-latest
timeout-minutes: 40

steps:
- uses: actions/checkout@v4

- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: false
# large-packages: true
# swap-storage: true

- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'

- name: ci/prepare-node-deps
uses: ./.github/actions/prepare-node-deps

- name: Gradle cache
uses: gradle/actions/setup-gradle@v3
with:
# TODO: Remove this after we merge
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/add_e2e_android' }}

- name: AVD Deps
run: |
sudo apt update
sudo apt-get install -y libpulse0 libgl1
- 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/1578521977/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: rm android/app/build/outputs/apk/artifact.zip

- name: AVD cache
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}

- name: Start React Native Metro Server
run: npm run start &

- name: Install Detox Dependencies
run: cd detox && npm i

- name: create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
profile: pixel_6_pro
api-level: ${{ matrix.api-level }}
arch: x86_64
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
script: echo "Generated AVD snapshot for caching."

- name: Enable KVM group perms
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: Run tests
uses: reactivecircus/android-emulator-runner@v2
with:
profile: pixel_6_pro
api-level: ${{ matrix.api-level }}
arch: x86_64
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: |
touch adb-log.txt
$ANDROID_HOME/platform-tools/adb logcat '*:D' >> adb-log.txt &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 5; done; input keyevent 82'
$ANDROID_HOME/platform-tools/adb shell settings put global window_animation_scale 0
$ANDROID_HOME/platform-tools/adb shell settings put global transition_animation_scale 0
$ANDROID_HOME/platform-tools/adb shell settings put global animator_duration_scale 0
$ANDROID_HOME/platform-tools/adb exec-out screencap -p > emulator-31.png
sleep 5
cd detox && npm run e2e:android-test -- detox/e2e/test/account/about.e2e.ts

- uses: actions/upload-artifact@v3
with:
name: Android-Emulator-Screenshots
path: emulator-31.jpg
- uses: actions/upload-artifact@v3
with:
name: Android-Emulator-Screenshots
path: emulator-31.png
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
fetch-depth: 1

- name: Node
uses: actions/setup-node@v4
with:
node-version: 18

- name: Use specific Java version for sdkmanager to work
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'

- name: Download Android Emulator Image
run: |
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install "system-images;android-29;google_apis;x86"
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd --force --name emu --device "Nexus 5X" -k 'system-images;android-29;google_apis;x86'
$ANDROID_HOME/emulator/emulator -list-avds
- name: Android Emulator
timeout-minutes: 10
continue-on-error: true
run: |
echo "Starting emulator"
nohup $ANDROID_HOME/emulator/emulator -avd emu -no-audio -no-snapshot -no-window &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82'
$ANDROID_HOME/platform-tools/adb devices
echo "Emulator started"
- name: capture
run: |
screencapture emulator-31.jpg
$ANDROID_HOME/platform-tools/adb exec-out screencap -p > emulator-31.png
- uses: actions/upload-artifact@v3
with:
name: Android-Emulator-Screenshots
path: emulator-31.jpg

- uses: actions/upload-artifact@v3
with:
name: Android-Emulator-Screenshots
path: emulator-31.png

# download-e2e-results:
# runs-on: ubuntu-22.04
Expand Down

0 comments on commit 24d1542

Please sign in to comment.