Skip to content

Commit

Permalink
chore(ci): E2E setup (#716)
Browse files Browse the repository at this point in the history
* chore: setup maestro test action

* chore: test

* chore: test 2

* chore: add example test

* chore: test 3

* chore: test 4

* fix: app id

* chore: save apk build artifact

* chore: update path

* chore: update path

* chore: install apk on emulator

* chore: remove incorrect value

* chore: update path

* chore: enable maestro tests

* chore: add second test

* chore: check if app is installed

* chore: run maestro

* chore: run single test

* chore: customise emulator options

* chore: update config

* chore: update config

* chore: update config

* chore: use virtual display

* chore: don't install emulator

* chore: disable virtual screen

* chore: change options

* add maestro script

* add yarn bootstrap no pods

* bump node version

* migrate example test

* add ios test

* fix ios bundle name

* merge two pipelines

* change executor

* fix ios

* remove unused file

---------

Co-authored-by: Piotr Trocki <[email protected]>
  • Loading branch information
jaworek and Piotr Trocki authored May 12, 2023
1 parent 16173bd commit e1dd3ef
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 129 deletions.
21 changes: 3 additions & 18 deletions .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Install dependencies
description: "Installs and caches the dependencies"
description: 'Installs and caches the dependencies'

runs:
using: "composite"
using: 'composite'
steps:
- name: Install dependencies
shell: bash
Expand All @@ -28,18 +28,3 @@ runs:
shell: bash
run: yarn install --frozen-lockfile
working-directory: example

- name: Cache fabric example node modules
id: cache-fabricexample-npm
uses: actions/cache@v3
env:
cache-name: cached-fabric-npm-deps
with:
path: fabricexample/node_modules
key: ${{ hashFiles('./fabricexample/yarn.lock') }}-${{ hashFiles('./yarn.lock') }}

- name: Install required fabric example dependencies on yarn.lock change
if: steps.cache-fabricexample-npm.outputs.cache-hit != 'true'
shell: bash
run: yarn install --frozen-lockfile
working-directory: fabricexample
69 changes: 26 additions & 43 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@ on:
- '.github/workflows/android.yml'
- 'android/**'
- 'example/android/**'
- 'fabricexample/android/**'
push:
branches:
- master


concurrency:
concurrency:
group: ${{ github.ref }}-android
cancel-in-progress: true

jobs:
android-build:
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/install-dependencies
Expand All @@ -42,51 +40,36 @@ jobs:

- name: Install required example dependencies on yarn.lock change
if: steps.cache-example-npm.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
working-directory: example
run: yarn bootstrap-no-pods --frozen-lockfile

- uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "11"

- name: Build Android
run: ./gradlew assembleDebug
working-directory: example/android

android-build-fabric:
runs-on: ubuntu-latest
needs: android-build
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/install-dependencies
distribution: 'zulu'
java-version: '11'

- name: Pull dependencies
- name: Gradle cache
uses: actions/cache@v3
with:
path: ./node_modules
key: ${{ hashFiles('./package.json') }}
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/buildSrc/**/*.kt') }}

- name: Cache fabric example node modules
id: cache-fabricexample-npm
uses: actions/cache@v3
env:
cache-name: cached-fabric-npm-deps
with:
path: fabricexample/node_modules
key: ${{ hashFiles('./fabricexample/yarn.lock') }}-${{ hashFiles('./yarn.lock') }}

- name: Install required fabric example dependencies on yarn.lock change
if: steps.cache-fabricexample-npm.outputs.cache-hit != 'true'
shell: bash
run: yarn install --frozen-lockfile
working-directory: fabricexample
- name: Install Maestro CLI
run: export MAESTRO_VERSION=1.21.3; curl -Ls "https://get.maestro.mobile.dev" | bash

- uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "11"
- name: Add Maestro to path
run: echo "${HOME}/.maestro/bin" >> $GITHUB_PATH

- name: Build Android (Fabric)
run: ./gradlew assembleDebug -PreactNativeArchitectures=arm64-v8a
working-directory: fabricexample/android
- name: Run Android Emulator and app
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
arch: x86_64
target: google_apis
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: |
yarn run-example-android
yarn test:e2e:android
63 changes: 15 additions & 48 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ on:
- '.github/workflows/ios.yml'
- 'ios/**'
- 'example/ios/**'
- 'fabricexample/ios/**'
push:
branches:
push:
branches:
- master

concurrency:
Expand Down Expand Up @@ -57,51 +56,19 @@ jobs:
run: NO_FLIPPER=1 pod install
working-directory: example/ios

- name: Build iOS
run: xcodebuild -scheme PagerViewExample -workspace PagerViewExample.xcworkspace -sdk iphonesimulator -configuration Debug COMPILER_INDEX_STORE_ENABLE=NO
working-directory: example/ios

ios-build-fabric:
needs: ios-build
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/install-dependencies
- name: Install Maestro CLI
run: |
curl -Ls "https://get.maestro.mobile.dev" | bash
brew tap facebook/fb
brew install facebook/fb/idb-companion
- name: Pull dependencies
uses: actions/cache@v3
with:
path: ./node_modules
key: ${{ hashFiles('./package.json') }}
- name: Add Maestro to path
run: echo "${HOME}/.maestro/bin" >> $GITHUB_PATH

- name: Cache fabric example node modules
id: cache-fabricexample-npm
uses: actions/cache@v3
env:
cache-name: cached-fabric-npm-deps
with:
path: fabricexample/node_modules
key: ${{ hashFiles('./fabricexample/yarn.lock') }}-${{ hashFiles('./yarn.lock') }}

- name: Install required fabric example dependencies on yarn.lock change
if: steps.cache-fabricexample-npm.outputs.cache-hit != 'true'
shell: bash
run: yarn install --frozen-lockfile
working-directory: fabricexample

- name: Cache FabricExample Pods
id: cache-pods-fabric
uses: actions/cache@v3
env:
cache-name: cached-ios-pods-deps-fabric
with:
path: fabricexample/ios/Pods
key: ${{ hashFiles('./fabricexample/ios/Podfile.lock') }}

- name: Install FabricExample Pods
run: NO_FLIPPER=1 pod install
working-directory: fabricexample/ios
- name: Build iOS App
run: |
yarn run-example-ios
- name: Build iOS (Fabric)
run: xcodebuild -scheme FabricExample -workspace FabricExample.xcworkspace -sdk iphonesimulator -configuration Debug COMPILER_INDEX_STORE_ENABLE=NO
working-directory: fabricexample/ios
- name: Run tests
run: |
yarn test:e2e:ios
19 changes: 5 additions & 14 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ on:
branches:
- master

concurrency:
concurrency:
group: ${{ github.ref }}-js
cancel-in-progress: true

jobs:
install-dependencies:
install-dependencies:
name: Install dependencies
runs-on: ubuntu-latest
steps:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install dependencies
- name: Install dependencies
uses: ./.github/actions/install-dependencies

verify-package-source:
Expand All @@ -45,20 +45,11 @@ jobs:
path: example/node_modules
key: ${{ hashFiles('./example/yarn.lock') }}-${{ hashFiles('./yarn.lock') }}

- name: Pull fabric example node modules
id: cache-fabricexample-npm
uses: actions/cache@v3
env:
cache-name: cached-fabric-npm-deps
with:
path: fabricexample/node_modules
key: ${{ hashFiles('./fabricexample/yarn.lock') }}-${{ hashFiles('./yarn.lock') }}

- name: Lint files
run: yarn lint

- name: Typecheck files
run: yarn typescript

- name: Build package
run: yarn prepare
run: yarn prepare
8 changes: 4 additions & 4 deletions example/ios/PagerViewExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@
"-lc++",
"$(inherited)",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = com.pagerviewexample;
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PagerViewExample.app/PagerViewExample";
};
Expand All @@ -473,7 +473,7 @@
"-lc++",
"$(inherited)",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = com.pagerviewexample;
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PagerViewExample.app/PagerViewExample";
};
Expand All @@ -497,7 +497,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = com.pagerviewexample;
PRODUCT_NAME = PagerViewExample;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand All @@ -522,7 +522,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = com.pagerviewexample;
PRODUCT_NAME = PagerViewExample;
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down
20 changes: 20 additions & 0 deletions maestro-tests/basic_example/tc14_pager_basic_example.yaml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
appId: ${APP_ID}
---
- launchApp
- assertVisible: 'PagerView Example'
- tapOn: 'Basic Example'
- assertVisible: 'Basic Example'
- tapOn: 'Last'
- assertVisible: 'page number 9'
- assertVisible: 'Page 10 / 10 '
- assertVisible: 'Prev'
- tapOn: 'Prev'
- repeat:
times: 8
commands:
- tapOn: 'Prev'
- assertVisible: 'page number 0'
- assertVisible: 'Page 1 / 10 '
- tapOn: 'Prev'
- assertVisible: 'page number 0'
- assertVisible: 'Page 1 / 10 '
3 changes: 3 additions & 0 deletions maestro-tests/test2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
appId: ${APP_ID}
---
- launchApp
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
"example": "yarn --cwd example",
"bootstrap": "yarn example && yarn && yarn example pods",
"fabricexample": "yarn --cwd fabricexample",
"bootstrap-fabric": "yarn fabricexample && yarn && yarn fabricexample pods"
"bootstrap-fabric": "yarn fabricexample && yarn && yarn fabricexample pods",
"bootstrap-no-pods": "yarn example && yarn",
"test:e2e:android": "bash ./scripts/run-maestro-tests.sh android",
"run-example-android": "cd example;react-native run-android --variant=release",
"run-example-ios": "cd example;react-native run-ios --configuration Release --simulator \"iPhone 13 (15.2)\"",
"test:e2e:ios": "bash ./scripts/run-maestro-tests.sh ios"
},
"keywords": [
"react-native",
Expand Down
52 changes: 52 additions & 0 deletions scripts/run-maestro-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

trap 'exit' INT

PLATFORM=${1:-}

# Validate passed platform
case $PLATFORM in
ios | android )
;;

*)
echo "Error! You must pass either 'android' or 'ios'"
echo ""
exit 1
;;
esac

if [ "$PLATFORM" == "ios" ]; then
APPID="com.pagerviewexample"
allTestFiles=$(ls maestro-tests/*.yaml maestro-tests/basic_example/*.yaml)
else
APPID="com.pagerviewexample"
allTestFiles=$(ls maestro-tests/*.yaml maestro-tests/basic_example/*.yaml)
fi

failedTests=()
for file in $allTestFiles
do
if ! maestro test "$file" -e APP_ID="$APPID";
then
echo "Test ${file} failed. Retrying in 30 seconds..."
sleep 30
if ! maestro test "$file" -e APP_ID="$APPID";
then
echo "Test ${file} failed again. Retrying for the last time in 120 seconds..."
sleep 120
if ! maestro test "$file" -e APP_ID="$APPID";
then
failedTests+=("$file")
fi
fi
fi
done

if [ ${#failedTests[@]} -eq 0 ]; then
exit 0
else
echo "These tests failed:"
printf '%s\n' "${failedTests[@]}"
exit 1
fi
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
"skipLibCheck": true,
"strict": true,
"target": "esnext"
}
},
"exclude": ["fabricexample"]
}

0 comments on commit e1dd3ef

Please sign in to comment.