1name: Android Unit Tests
2
3on:
4  workflow_dispatch: {}
5  push:
6    branches: [main]
7    paths:
8      - .github/workflows/android-unit-tests.yml
9      - android/**
10      - fastlane/**
11      - packages/**/android/**
12      - tools/**
13      - yarn.lock
14      - '!packages/@expo/cli/**'
15  pull_request:
16    paths:
17      - .github/workflows/android-unit-tests.yml
18      - android/**
19      - fastlane/**
20      - packages/**/android/**
21      - tools/**
22      - yarn.lock
23      - '!packages/@expo/cli/**'
24
25concurrency:
26  group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
27  cancel-in-progress: true
28
29jobs:
30  test:
31    runs-on: ubuntu-20.04
32    timeout-minutes: 60
33    env:
34      ORG_GRADLE_PROJECT_reactNativeArchitectures: x86_64
35      GRADLE_OPTS: -Dorg.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=1024m
36    strategy:
37      matrix:
38        api-level: [31]
39    steps:
40      - name: ⬢ Setup Node
41        uses: actions/setup-node@v3
42        with:
43          node-version: '14.17'
44      - name: �� Check out repository
45        uses: actions/checkout@v3
46        with:
47          submodules: true
48      - name: �� Use JDK 11
49        uses: actions/setup-java@v3
50        with:
51          distribution: 'temurin'
52          java-version: '11'
53      - name: ♻️ Restore caches
54        uses: ./.github/actions/expo-caches
55        id: expo-caches
56        with:
57          yarn-workspace: 'true'
58          yarn-tools: 'true'
59          avd: 'true'
60          avd-api: ${{ matrix.api-level }}
61      - name: ➕ Add `bin` to GITHUB_PATH
62        run: echo "$(pwd)/bin" >> $GITHUB_PATH
63      - name: �� Install node modules in root dir
64        if: steps.expo-caches.outputs.yarn-workspace-hit != 'true'
65        run: yarn install --frozen-lockfile
66      - name: �� Run Spotless lint check
67        working-directory: android
68        run: ./gradlew spotlessCheck || { echo '::error Spotless lint failed. Run `./gradlew spotlessApply` to automatically fix formatting.' && exit 1; }
69      - name: �� Run native Android unit tests
70        timeout-minutes: 30
71        run: expotools native-unit-tests --platform android
72      - name: �� Run instrumented unit tests
73        timeout-minutes: 40
74        uses: reactivecircus/android-emulator-runner@v2
75        with:
76          api-level: ${{ matrix.api-level }}
77          avd-name: avd-${{ matrix.api-level }}
78          arch: x86_64
79          force-avd-creation: false
80          script: expotools android-native-unit-tests --type instrumented
81      - name: �� Save test results
82        if: always()
83        uses: actions/upload-artifact@v3
84        with:
85          name: test-results
86          path: packages/**/build/test-results/**/*xml
87