chore: Add Detox e2e tests & BrowserStack CI #52
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Detox BrowserStack | |
on: | |
pull_request: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
outputs: | |
app_url: ${{ steps.upload.outputs.app_url }} | |
app_client_url: ${{ steps.upload-client.outputs.app_client_url }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# Cache builds during dev to speed up actions | |
- name: Cache builds | |
id: cache-builds | |
uses: actions/cache@v4 | |
with: | |
path: | | |
android/.gradle | |
android/app/build | |
key: app-build-${{ github.run_id }} | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci | |
- name: Expo prebuild | |
if: steps.cache-builds.outputs.cache-hit != 'true' | |
run: npx expo prebuild | |
- name: Install Java | |
if: steps.cache-builds.outputs.cache-hit != 'true' | |
uses: actions/setup-java@v3 | |
with: | |
java-version: 17 | |
distribution: adopt | |
cache: gradle | |
- name: Setup Android SDK | |
uses: android-actions/setup-android@v3 | |
with: | |
cmdline-tools-version: 11076708 | |
packages: 'ndk;25.1.8937393' | |
- run: sdkmanager 'cmake;3.22.1' 'cmake;3.18.1' | |
- run: sdkmanager --list_installed | |
- name: Build translations | |
if: steps.cache-builds.outputs.cache-hit != 'true' | |
run: npm run build:translations | |
- name: Build intl polyfills | |
if: steps.cache-builds.outputs.cache-hit != 'true' | |
run: npm run build:intl-polyfills | |
- name: Build backend | |
if: steps.cache-builds.outputs.cache-hit != 'true' | |
run: npm run build:backend | |
- name: Build app for Detox | |
if: steps.cache-builds.outputs.cache-hit != 'true' | |
run: npx detox build --configuration android.att.release | |
env: | |
COMAPEO_METRICS_URL: ${{ secrets.COMAPEO_METRICS_URL }} | |
COMAPEO_METRICS_API_KEY: ${{ secrets.COMAPEO_METRICS_API_KEY }} | |
MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }} | |
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} | |
# JVM args to match those used by EAS: https://docs.expo.dev/build-reference/infrastructure/#android-build-server-configurations | |
# - `Xmx` specifies the maximum memory allocation pool for a Java virtual machine (JVM) | |
# - `XX:MaxMetaspaceSize`: the maximum permanent generation size | |
_JAVA_OPTIONS: '-Xmx14g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError' | |
- name: Upload app to BrowserStack | |
id: upload | |
run: (echo -n "app_url=" && scripts/upload-app.mjs) >> $GITHUB_OUTPUT | |
env: | |
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} | |
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} | |
- name: Upload app client to BrowserStack | |
id: upload-client | |
run: (echo -n "app_client_url=" && scripts/upload-app-client.mjs) >> $GITHUB_OUTPUT | |
env: | |
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} | |
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} | |
devices: | |
runs-on: ubuntu-latest | |
outputs: | |
devices: ${{ steps.get-devices.outputs.devices }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Get available devices | |
id: get-devices | |
run: '(echo -n "devices=" && jq -c . e2e-detox/devices.json) >> $GITHUB_OUTPUT' | |
test: | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
- devices | |
strategy: | |
max-parallel: 5 | |
matrix: | |
include: ${{ fromJson(needs.devices.outputs.devices) }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# Don't cache this because we install patched Detox | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Fake adb to keep Detox happy | |
run: | | |
mkdir -p $ANDROID_SDK_ROOT/platform-tools | |
echo '#!/bin/bash' > $ANDROID_SDK_ROOT/platform-tools/adb | |
chmod +x $ANDROID_SDK_ROOT/platform-tools/adb | |
- name: Install Patched Detox for BrowserStack | |
run: npm install --no-save detox@npm:@avinashbharti97/detox@^20.26.2 | |
- name: Get branch name | |
run: | | |
if [ "${{ github.event_name }}" == "push" ]; then | |
BRANCH_NAME=${GITHUB_REF#refs/heads/} | |
elif [ "${{ github.event_name }}" == "pull_request" ]; then | |
BRANCH_NAME=${GITHUB_HEAD_REF} | |
else | |
BRANCH_NAME="unknown" | |
fi | |
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | |
- name: Get build ID | |
run: echo "BUILD_ID=$BRANCH_NAME-${GITHUB_SHA::7}" >> $GITHUB_ENV | |
- name: Run Detox tests | |
run: npx detox test --configuration android.cloud.release | |
env: | |
BROWSERSTACK_APP_URL: ${{ needs.build.outputs.app_url }} | |
BROWSERSTACK_APP_CLIENT_URL: ${{ needs.build.outputs.app_client_url }} | |
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} | |
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} | |
DEVICE_NAME: ${{ matrix.name }} | |
DEVICE_OS_VERSION: ${{ matrix.osVersion }} |