Skip to content

Commit

Permalink
feat: e2e tesing on android ci/cd (#48)
Browse files Browse the repository at this point in the history
* feat: e2e tesing on android ci/cd

* fix: fastlane add to gemfile

* fix: broken refer to non existing lane

* add: fastlane-plugin-stream_actions to use sugar syntax

* add: fastlane-plugin-stream_actions to use sugar syntax

* add: Pluginfile

* fix: changing test device

* fix: api 30 pixel 5

* fix: upgrade jest and improve test performance by onky using fake timers, simulate delay after fetch
  • Loading branch information
vanGalilea authored Sep 15, 2023
1 parent d45f6a5 commit 327696e
Show file tree
Hide file tree
Showing 13 changed files with 474 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
root: true,
extends: '@react-native',
ignorePatterns: ['e2e/'],
ignorePatterns: ['e2e/', 'coverage'],
};
89 changes: 89 additions & 0 deletions .github/actions/bootstrap/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: 'Bootstrap'
description: 'Bootstrap Dependencies'
runs:
using: 'composite'
steps:
- run: echo "IMAGE=${ImageOS}-${ImageVersion}" >> $GITHUB_ENV
shell: bash

- uses: actions/setup-node@v3
if: ${{ env.INSTALL_NODE == 'true' }}
with:
node-version: 18.x
cache: 'yarn'

- name: Install Yarn Dependencies
if: ${{ env.INSTALL_NODE == 'true' }}
run: yarn install --immutable
shell: bash

- name: Cache pods
uses: actions/cache@v3
if: ${{ env.INSTALL_PODS == 'true' }}
with:
path: ios/Pods
key: ${{ env.IMAGE }}-pods-${{ hashFiles('ios/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-pods-
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
bundler-cache: true

- name: Cache Gradle
if: ${{ env.INSTALL_JAVA == 'true' }}
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ env.IMAGE }}-gradle-${{ hashFiles('*.gradle*', 'gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- uses: actions/setup-java@v3
if: ${{ env.INSTALL_JAVA == 'true' }}
with:
distribution: 'zulu'
java-version: '11'
check-latest: true

- name: Install pods
if: ${{ env.INSTALL_PODS == 'true' }}
run: bundle exec fastlane pod_install
shell: bash

# Retrieve the cached emulator snapshot
- uses: actions/cache@v3
if: ${{ env.INSTALL_ANDROID_EMULATOR == 'true' }}
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: ${{ env.IMAGE }}-android-emulator

# Required for Maestro on iOS
- uses: actions/[email protected]
if: ${{ env.INSTALL_PYTHON == 'true' }}
with:
python-version: 3.8
cache: 'pip'

# Required to run E2E testing
- name: Install Maestro
if: ${{ env.INSTALL_MAESTRO == 'true' }}
shell: bash
run: |
if [ "${{ env.INSTALL_PYTHON }}" = "true" ]; then
brew install facebook/fb/idb-companion
pip install fb-idb
fi
env MAESTRO_VERSION="1.29.0" curl -Ls 'https://get.maestro.mobile.dev' | bash
echo "$HOME/.maestro/bin" >> $GITHUB_PATH
# Required to capture Android video during E2E testing
- name: Install FFmpeg
if: ${{ env.INSTALL_FFMPEG == 'true' }}
uses: FedericoCarboni/setup-ffmpeg@v2
91 changes: 91 additions & 0 deletions .github/workflows/e2e-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: E2E Testing
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: react-native-workflow-${{ github.ref }}
cancel-in-progress: true

jobs:
build_android:
name: Build Android
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/bootstrap
timeout-minutes: 15
env:
INSTALL_NODE: true
INSTALL_JAVA: true

- name: Build
run: bundle exec fastlane build_android

- name: Upload .apk
uses: actions/upload-artifact@v3
with:
name: apk
path: '**/dist/*.apk'

test_android:
name: Test Android
needs: build_android
timeout-minutes: 100
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/bootstrap
timeout-minutes: 15
env:
INSTALL_NODE: true
INSTALL_FFMPEG: true
INSTALL_MAESTRO: true
INSTALL_ANDROID_EMULATOR: true

- name: Download .apk
uses: actions/download-artifact@v3
with:
name: apk

- name: Create AVD Snapshot
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 30
arch: x86_64
target: google_apis
profile: pixel_5
force-avd-creation: false
avd-name: test
ram-size: 8192M
disk-size: 2048M
emulator-boot-timeout: 1000
emulator-options: -no-window -no-boot-anim -no-audio -no-snapshot-load -gpu swiftshader_indirect
script: echo 'AVD snapshot is generated and will be cached for the future runs.'

- name: Test
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 30
arch: x86_64
target: google_apis
profile: pixel_5
force-avd-creation: false
avd-name: test
ram-size: 8192M
disk-size: 2048M
emulator-boot-timeout: 1000
emulator-options: -no-window -no-boot-anim -no-audio -no-snapshot-load -gpu swiftshader_indirect
script: bundle exec fastlane test_android

- uses: actions/upload-artifact@v3
if: failure()
with:
name: Android Test Data
path: |
**/fastlane/recordings
~/.maestro/tests
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ source 'https://rubygems.org'
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby ">= 2.6.10"

gem 'cocoapods', '~> 1.12'
gem 'cocoapods', '~> 1.12', '>= 1.12.1'
gem 'fastlane'

plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
eval_gemfile(plugins_path) if File.exist?(plugins_path)
Loading

0 comments on commit 327696e

Please sign in to comment.