mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-01-01 18:38:42 -05:00
135 lines
6.0 KiB
YAML
135 lines
6.0 KiB
YAML
name: e2e-Android
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
# Android builds require access to several secrets, so Github won't run
|
|
# those jobs when triggered by pull requests by external developers.
|
|
# Instead, we're just running these jobs when staff decides to merge a PR
|
|
# into main
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
# This might be refactored to use concurrency from GitHub Actions directly?
|
|
deduplicate:
|
|
runs-on: macos-latest
|
|
steps:
|
|
- uses: fkirc/skip-duplicate-actions@master
|
|
with:
|
|
github_token: ${{ github.token }}
|
|
cancel_others: true
|
|
|
|
test:
|
|
needs: deduplicate
|
|
runs-on: macos-latest
|
|
# Kill the task if not finished after 60 minutes
|
|
timeout-minutes: 60
|
|
|
|
steps:
|
|
- name: Check out Git repository
|
|
uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 1
|
|
|
|
- name: Install Node.js, NPM and Yarn
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: 16
|
|
|
|
# Use the Android command line tools to download an AOSP emulator image, and setup new avd
|
|
# The name of the device for testing has to be the same as on the .detoxrc.js file (even if it is not a Pixel)
|
|
# The mac-os latest runner has 3 different versions of Java pre-installed (8,11,17), and there were errors when setting to use either 11 or 17 explicitly here
|
|
# I am assuming (but haven't tested) it uses 8 and then this step works
|
|
- name: Download Android Emulator Image
|
|
run: |
|
|
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install "system-images;android-28;default;x86"
|
|
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd --force --name Pixel_5_API_31_AOSP --device "Nexus 5X" -k 'system-images;android-28;default;x86'
|
|
$ANDROID_HOME/emulator/emulator -list-avds
|
|
|
|
- name: Cache node modules
|
|
uses: actions/cache@v3
|
|
id: cache
|
|
with:
|
|
path: node_modules
|
|
key: node-modules-${{ hashFiles('**/package-lock.json') }}
|
|
|
|
- name: Rebuild detox from cache
|
|
if: steps.cache.outputs.cache-hit == 'true'
|
|
run: npx detox clean-framework-cache && npx detox build-framework-cache
|
|
|
|
- name: Install Dependencies
|
|
if: steps.cache.outputs.cache-hit != 'true'
|
|
run: npm install
|
|
|
|
# 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\n' "JWT_ANONYMOUS_API_SECRET" "$OAUTH_CLIENT_ID" "$OAUTH_CLIENT_SECRET" "$E2E_TEST_USERNAME" "$E2E_TEST_PASSWORD" > .env
|
|
- 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
|
|
|
|
# Macos-latest runner has 3 Java versions pre-installed, if not specified as here, the build step errors with requiring at least Java 11 or higher
|
|
# So, this step is needed for the apk build step, but somehow this is breaking emulator setup, so it is placed here
|
|
- name: Set up JDK 11
|
|
uses: actions/setup-java@v3
|
|
with:
|
|
java-version: '11'
|
|
distribution: 'zulu'
|
|
|
|
# This is by far the longest step in this job, currently we are building the apk everytime, maybe there should be a more specific trigger for the entire job
|
|
- name: Build for detox
|
|
run: npm run e2e:build:android
|
|
|
|
# Starts the avd previously set-up by name
|
|
- name: Android Emulator
|
|
timeout-minutes: 10
|
|
continue-on-error: true
|
|
run: |
|
|
echo "Starting emulator"
|
|
nohup $ANDROID_HOME/emulator/emulator -avd Pixel_5_API_31_AOSP -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"
|
|
|
|
# Start the Android e2e tests with extensive logging and screen captures for failing tests
|
|
- name: Android Detox
|
|
run: npm run e2e:test:android -- --debug-synchronization 500 --take-screenshots failing --record-videos failing -l trace
|
|
|
|
# The artifacts for the failing tests are available for download on github.com on the page of the individual actions run
|
|
- name: Store Detox artifacts on test failure
|
|
uses: actions/upload-artifact@v3
|
|
if: failure()
|
|
with:
|
|
name: detox-artifacts
|
|
path: artifacts
|
|
|
|
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 }}
|