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  pull_request:
15    paths:
16      - .github/workflows/android-unit-tests.yml
17      - android/**
18      - fastlane/**
19      - packages/**/android/**
20      - tools/**
21      - yarn.lock
22
23concurrency:
24  group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
25  cancel-in-progress: true
26
27jobs:
28  test:
29    runs-on: ubuntu-latest
30    timeout-minutes: 60
31    env:
32      ORG_GRADLE_PROJECT_reactNativeArchitectures: x86
33      GRADLE_OPTS: -Dorg.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=1024m
34    steps:
35      - name: ⬢ Setup Node
36        uses: actions/setup-node@v3
37        with:
38          node-version: '14.17'
39      - name: �� Check out repository
40        uses: actions/checkout@v3
41        with:
42          submodules: true
43      - name: �� Use JDK 11
44        uses: actions/setup-java@v3
45        with:
46          distribution: 'temurin'
47          java-version: '11'
48      - name: ♻️ Restore workspace node modules
49        uses: actions/cache@v2
50        id: node-modules-cache
51        with:
52          path: |
53            # See "workspaces" → "packages" in the root package.json for the source of truth of
54            # which node_modules are affected by the root yarn.lock
55            node_modules
56            apps/*/node_modules
57            home/node_modules
58            packages/*/node_modules
59            packages/@expo/*/node_modules
60            packages/@unimodules/*/node_modules
61            react-native-lab/react-native/node_modules
62          key: ${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
63      - name: �� Install node modules in root dir
64        run: yarn install --frozen-lockfile
65      - name: ♻️ Restore node modules in tools
66        uses: actions/cache@v2
67        with:
68          path: tools/node_modules
69          key: ${{ runner.os }}-tools-modules-${{ hashFiles('tools/yarn.lock') }}
70      - name: ♻️ Restore Gradle caches
71        uses: actions/cache@v2
72        with:
73          path: ~/.gradle/caches
74          key: ${{ runner.os }}-gradle-${{ hashFiles('android/*.gradle*') }}
75          restore-keys: |
76            ${{ runner.os }}-gradle-
77      - run: echo "$(pwd)/bin" >> $GITHUB_PATH
78      - name: Run Spotless lint check
79        working-directory: android
80        run: ./gradlew spotlessCheck || { echo '::error Spotless lint failed. Run `./gradlew spotlessApply` to automatically fix formatting.' && exit 1; }
81      - name: �� Run native Android unit tests
82        timeout-minutes: 30
83        run: expotools native-unit-tests --platform android
84      - name: �� Run instrumented unit tests
85        timeout-minutes: 40
86        uses: reactivecircus/android-emulator-runner@v2
87        with:
88          api-level: 29
89          emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -no-snapshot-save
90          script: |
91            # wait for emulator to be fully boot up
92            sleep 180
93            bin/expotools android-native-unit-tests --type instrumented
94      - name: �� Save test results
95        if: always()
96        uses: actions/upload-artifact@v3
97        with:
98          name: test-results
99          path: packages/**/build/test-results/**/*xml
100