mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-06-18 04:30:45 -04:00
* Use same assemble task as detox does (plus arch restriction) * Add detox mock env var * Upload test apk as well * Download test apk and run detox test script * Adapt test step for detox * Update e2e_android.yml * Only run the tests that are passing * Trigger e2e test on PRs to main * Restrict to arch emulator uses * Remove maestro env vars * Add detox logs and screen recordings * Re-arrange CLI args * Remove artifacts config * First test run without logs and screen records * Only run signedOut test * Remove the osx-specific detox lines --------- Co-authored-by: Johannes Klein <17345891+jtklein@users.noreply.github.com>
299 lines
13 KiB
YAML
299 lines
13 KiB
YAML
name: e2e-Android
|
|
permissions:
|
|
contents: read
|
|
on:
|
|
workflow_dispatch:
|
|
pull_request:
|
|
push:
|
|
branches:
|
|
- 'main'
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
build:
|
|
# 4-core Ubunutu GitHub Larger Runner
|
|
# https://docs.github.com/en/enterprise-cloud@latest/billing/reference/actions-runner-pricing#x64-powered-larger-runners
|
|
runs-on: ubuntu-24.04-m
|
|
|
|
steps:
|
|
- name: Check out Git repository
|
|
uses: actions/checkout@v6
|
|
|
|
# Generate the secret files needed for a release build
|
|
- name: Create .env file
|
|
env:
|
|
OAUTH_CLIENT_ID: ${{ secrets.OAUTH_CLIENT_ID }}
|
|
OAUTH_CLIENT_SECRET: ${{ secrets.OAUTH_CLIENT_SECRET }}
|
|
E2E_TEST_USERNAME: ${{ secrets.E2E_TEST_USERNAME }}
|
|
E2E_TEST_PASSWORD: ${{ secrets.E2E_TEST_PASSWORD }}
|
|
JWT_ANONYMOUS_API_SECRET: ${{ secrets.JWT_ANONYMOUS_API_SECRET }}
|
|
GMAPS_API_KEY: ${{ secrets.GMAPS_API_KEY }}
|
|
run: printf 'API_URL=https://stagingapi.inaturalist.org/v2\nOAUTH_API_URL=https://staging.inaturalist.org\nJWT_ANONYMOUS_API_SECRET=%s\nOAUTH_CLIENT_ID=%s\nOAUTH_CLIENT_SECRET=%s\nE2E_TEST_USERNAME=%s\nE2E_TEST_PASSWORD=%s\nGMAPS_API_KEY=%s\nANDROID_MODEL_FILE_NAME=INatVision_Small_2_fact256_8bit.tflite\nANDROID_TAXONOMY_FILE_NAME=taxonomy.csv\nANDROID_GEOMODEL_FILE_NAME=INatGeomodel_Small_2_8bit.tflite\nIOS_MODEL_FILE_NAME=INatVision_Small_2_fact256_8bit.mlmodel\nIOS_TAXONOMY_FILE_NAME=taxonomy.json\nIOS_GEOMODEL_FILE_NAME=INatGeomodel_Small_2_8bit.mlmodel\nCV_MODEL_VERSION=small_2\n' "$JWT_ANONYMOUS_API_SECRET" "$OAUTH_CLIENT_ID" "$OAUTH_CLIENT_SECRET" "$E2E_TEST_USERNAME" "$E2E_TEST_PASSWORD" "$GMAPS_API_KEY" > .env
|
|
|
|
- name: Add secrets to google-services.json
|
|
env:
|
|
FIREBASE_PROJECT_NUMBER: ${{ secrets.FIREBASE_PROJECT_NUMBER }}
|
|
FIREBASE_PROJECT_ID: ${{ secrets.FIREBASE_PROJECT_ID }}
|
|
FIREBASE_STORAGE_BUCKET: ${{ secrets.FIREBASE_STORAGE_BUCKET }}
|
|
FIREBASE_STAGING_GOOGLE_APP_ID: ${{ secrets.FIREBASE_STAGING_GOOGLE_APP_ID }}
|
|
FIREBASE_STAGING_PACKAGE_NAME: ${{ secrets.FIREBASE_STAGING_PACKAGE_NAME }}
|
|
FIREBASE_STAGING_API_KEY: ${{ secrets.FIREBASE_STAGING_API_KEY }}
|
|
run: |
|
|
cp android/app/google-services.example.json android/app/google-services.json
|
|
sed -i "s/your_project_number/${FIREBASE_PROJECT_NUMBER//\//\\/}/g" "android/app/google-services.json"
|
|
sed -i "s/your_project_id/${FIREBASE_PROJECT_ID//\//\\/}/g" "android/app/google-services.json"
|
|
sed -i "s/your_storage_bucket/${FIREBASE_STORAGE_BUCKET//\//\\/}/g" "android/app/google-services.json"
|
|
sed -i "s/your_mobilesdk_app_id/${FIREBASE_STAGING_GOOGLE_APP_ID//\//\\/}/g" "android/app/google-services.json"
|
|
sed -i "s/your_package_name/${FIREBASE_STAGING_PACKAGE_NAME//\//\\/}/g" "android/app/google-services.json"
|
|
sed -i "s/your_current_key/${FIREBASE_STAGING_API_KEY//\//\\/}/g" "android/app/google-services.json"
|
|
|
|
- name: Create keystore.properties file
|
|
env:
|
|
ANDROID_KEY_STORE_PASSWORD: ${{ secrets.ANDROID_KEY_STORE_PASSWORD }}
|
|
ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
|
|
ANDROID_ALIAS: ${{ secrets.ANDROID_ALIAS }}
|
|
run: printf 'storePassword=%s\nkeyPassword=%s\nkeyAlias=%s\nstoreFile=release.keystore' "$ANDROID_KEY_STORE_PASSWORD" "$ANDROID_KEY_PASSWORD" "$ANDROID_ALIAS" > android/keystore.properties
|
|
|
|
- name: Generate release keystore
|
|
env:
|
|
ANDROID_ALIAS: ${{ secrets.ANDROID_ALIAS }}
|
|
ANDROID_KEY_STORE_PASSWORD: ${{ secrets.ANDROID_KEY_STORE_PASSWORD }}
|
|
ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
|
|
run: |
|
|
keytool -genkeypair -v -noprompt -storetype PKCS12 -keystore release.keystore -alias "$ANDROID_ALIAS" -keyalg RSA -keysize 2048 -validity 10000 -storepass "$ANDROID_KEY_STORE_PASSWORD" -keypass "$ANDROID_KEY_PASSWORD" -dname "CN=mqttserver.ibm.com, OU=ID, O=IBM, L=Hursley, S=Hants, C=GB"
|
|
|
|
- name: Move keystore
|
|
run: mv release.keystore android/app/release.keystore
|
|
|
|
- uses: actions/setup-node@v6
|
|
with:
|
|
node-version-file: '.nvmrc'
|
|
cache: 'npm'
|
|
|
|
- uses: actions/setup-java@v5
|
|
with:
|
|
distribution: 'zulu'
|
|
java-version: '17'
|
|
|
|
- name: Setup Gradle
|
|
uses: gradle/actions/setup-gradle@v5
|
|
with:
|
|
gradle-version: '9.0.0'
|
|
|
|
- name: Install JS dependencies
|
|
run: |
|
|
npm install
|
|
|
|
- name: Download the small example cv and geomodel
|
|
run: |
|
|
npm run add-example-model -- -f=main
|
|
|
|
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
|
|
# This will be available for all subsequent steps
|
|
- name: Set MOCK_MODE to e2e
|
|
run: echo "MOCK_MODE=e2e" >> "$GITHUB_ENV"
|
|
|
|
- name: Android Build
|
|
run: |
|
|
cd android
|
|
./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release -PreactNativeArchitectures=x86_64
|
|
|
|
- name: Upload APK
|
|
uses: actions/upload-artifact@v6
|
|
with:
|
|
name: release-apk
|
|
path: android/app/build/outputs/apk/release/*-release.apk
|
|
|
|
- name: Upload Test Binary APK
|
|
uses: actions/upload-artifact@v6
|
|
with:
|
|
name: release-androidTest-apk
|
|
path: android/app/build/outputs/apk/androidTest/release/*-release-androidTest.apk
|
|
|
|
test:
|
|
# 4-core Ubunutu GitHub Larger Runner
|
|
# https://docs.github.com/en/enterprise-cloud@latest/billing/reference/actions-runner-pricing#x64-powered-larger-runners
|
|
# `cores` setting for emulator actions should be updated to reflect changes to this
|
|
runs-on: ubuntu-24.04-m
|
|
needs: build
|
|
|
|
steps:
|
|
- name: Check out Git repository
|
|
uses: actions/checkout@v6
|
|
with:
|
|
fetch-depth: 1
|
|
|
|
- name: Download Android Detox app APK
|
|
uses: actions/download-artifact@v7
|
|
with:
|
|
name: release-apk
|
|
path: android/app/build/outputs/apk/release
|
|
|
|
- name: Download Test Binary APK
|
|
uses: actions/download-artifact@v7
|
|
with:
|
|
name: release-androidTest-apk
|
|
path: android/app/build/outputs/apk/androidTest/release
|
|
|
|
- name: Install Node.js, NPM and Yarn
|
|
uses: actions/setup-node@v6
|
|
with:
|
|
node-version-file: '.nvmrc'
|
|
cache: 'npm'
|
|
|
|
- name: Cache node modules
|
|
uses: actions/cache@v5
|
|
id: cache
|
|
with:
|
|
path: node_modules
|
|
key: node-modules-${{ hashFiles('**/package-lock.json') }}
|
|
|
|
# supposedly our current cache includes native modules like Realm
|
|
# that have compiled binaries specific to the environment where they were installed
|
|
# which might not be the same as the github actions environment
|
|
# so we need to rebuild them
|
|
- name: Rebuild native modules
|
|
if: steps.cache.outputs.cache-hit == 'true'
|
|
run: npm rebuild
|
|
|
|
- name: Install Dependencies
|
|
if: steps.cache.outputs.cache-hit != 'true'
|
|
run: npm install
|
|
|
|
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
|
|
# This will be available for all subsequent steps
|
|
- name: Set MOCK_MODE to e2e
|
|
run: echo "MOCK_MODE=e2e" >> "$GITHUB_ENV"
|
|
|
|
# Generate the secret files needed for a release build
|
|
- name: Create .env file
|
|
env:
|
|
OAUTH_CLIENT_ID: ${{ secrets.OAUTH_CLIENT_ID }}
|
|
OAUTH_CLIENT_SECRET: ${{ secrets.OAUTH_CLIENT_SECRET }}
|
|
E2E_TEST_USERNAME: ${{ secrets.E2E_TEST_USERNAME }}
|
|
E2E_TEST_PASSWORD: ${{ secrets.E2E_TEST_PASSWORD }}
|
|
JWT_ANONYMOUS_API_SECRET: ${{ secrets.JWT_ANONYMOUS_API_SECRET }}
|
|
run: |
|
|
printf 'API_URL=https://stagingapi.inaturalist.org/v2\nOAUTH_API_URL=https://staging.inaturalist.org\nJWT_ANONYMOUS_API_SECRET=%s\nOAUTH_CLIENT_ID=%s\nOAUTH_CLIENT_SECRET=%s\nE2E_TEST_USERNAME=%s\nE2E_TEST_PASSWORD=%s\nGMAPS_API_KEY=%s\nANDROID_MODEL_FILE_NAME=INatVision_Small_2_fact256_8bit.tflite\nANDROID_TAXONOMY_FILE_NAME=taxonomy.csv\nANDROID_GEOMODEL_FILE_NAME=INatGeomodel_Small_2_8bit.tflite\nIOS_MODEL_FILE_NAME=INatVision_Small_2_fact256_8bit.mlmodel\nIOS_TAXONOMY_FILE_NAME=taxonomy.json\nIOS_GEOMODEL_FILE_NAME=INatGeomodel_Small_2_8bit.mlmodel\nCV_MODEL_VERSION=small_2\n' \
|
|
"$JWT_ANONYMOUS_API_SECRET" \
|
|
"$OAUTH_CLIENT_ID" \
|
|
"$OAUTH_CLIENT_SECRET" \
|
|
"$E2E_TEST_USERNAME" \
|
|
"$E2E_TEST_PASSWORD" \
|
|
"$GMAPS_API_KEY" > .env
|
|
|
|
# These KVM settings are in support of the android-emulator-runner action that takes advantage of them
|
|
# Further reading:
|
|
# - https://github.blog/changelog/2023-02-23-hardware-accelerated-android-virtualization-on-actions-windows-and-linux-larger-hosted-runners/
|
|
# - https://github.com/reactivecircus/android-emulator-runner/tree/v2/?tab=readme-ov-file#github-action---android-emulator-runner
|
|
|
|
- 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
|
|
|
|
# AVD Cache: we can reuse a previously-created AVD to save time and make the test-run start step more dependable
|
|
# both android-emulator-runner steps should have the same image config for cores, api-level, target
|
|
- name: Attempt to restore AVD cache
|
|
uses: actions/cache/restore@v5
|
|
id: avd-cache-restore
|
|
with:
|
|
path: |
|
|
~/.android/avd/*
|
|
~/.android/adb*
|
|
key: avd-34-aosp
|
|
- name: Create AVD and generate snapshot for caching
|
|
if: steps.avd-cache-restore.outputs.cache-hit != 'true'
|
|
uses: reactivecircus/android-emulator-runner@v2
|
|
with:
|
|
cores: 4
|
|
api-level: 34
|
|
target: default
|
|
arch: x86_64
|
|
profile: pixel_5
|
|
avd-name: Pixel_5_API_34_AOSP
|
|
force-avd-creation: false
|
|
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
|
|
disable-animations: false
|
|
script: echo "Generated AVD snapshot for caching."
|
|
|
|
- name: Save AVD cache
|
|
if: steps.avd-cache-restore.outputs.cache-hit != 'true'
|
|
uses: actions/cache/save@v5
|
|
with:
|
|
path: |
|
|
~/.android/avd/*
|
|
~/.android/adb*
|
|
key: avd-34-aosp
|
|
|
|
- name: Ensure servers are running
|
|
id: status_check
|
|
run: |
|
|
# is rails running?
|
|
curl -I --fail "https://staging.inaturalist.org/ping"
|
|
# is node running & is ES working?
|
|
curl -I --fail "https://stagingapi.inaturalist.org/v2/taxa"
|
|
|
|
- name: Run e2e tests
|
|
uses: reactivecircus/android-emulator-runner@v2
|
|
# don't mark job as error so that retries so that we can rely on the retry to succeed and mark job & workflow green
|
|
continue-on-error: true
|
|
id: first_test_run
|
|
with:
|
|
cores: 4
|
|
api-level: 34
|
|
target: default
|
|
arch: x86_64
|
|
profile: pixel_5
|
|
avd-name: Pixel_5_API_34_AOSP
|
|
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: |
|
|
npm run e2e:android:test -p e2e/signedOut.e2e.js
|
|
|
|
- name: Run e2e test (retry, with logs)
|
|
uses: reactivecircus/android-emulator-runner@v2
|
|
# if first_test_run fails, but we `continue-on-error`, failure() is false. so we need to check it's specific _outcome_
|
|
if: ${{ steps.first_test_run.outcome == 'failure' }}
|
|
with:
|
|
cores: 4
|
|
api-level: 34
|
|
target: default
|
|
arch: x86_64
|
|
profile: pixel_5
|
|
avd-name: Pixel_5_API_34_AOSP
|
|
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: |
|
|
# provide more debugging context on retry failure
|
|
# we're explicitly not using `detox test --retries` because we want to run them w/ different options
|
|
npx detox test --configuration android.release --take-screenshots failing --record-videos failing --record-logs all -l trace e2e/signedOut.e2e.js
|
|
|
|
|
|
- name: Store Detox artifacts on test failure
|
|
uses: actions/upload-artifact@v6
|
|
# don't run this if it's status check that failed or if our first test run passes (no first_test_run check needed)
|
|
if: ${{ failure() && steps.status_check.outcome != 'failure' }}
|
|
with:
|
|
name: detox-artifacts
|
|
path: artifacts
|
|
retention-days: 5
|
|
|
|
notify:
|
|
name: Notify Slack
|
|
needs: test
|
|
if: ${{ success() || failure() }}
|
|
runs-on: macos-latest
|
|
steps:
|
|
- uses: iRoachie/slack-github-actions@v2.3.0
|
|
if: env.SLACK_WEBHOOK_URL != null
|
|
env:
|
|
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_BUILDS_WEBHOOK_URL }}
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|