1name: Android Unit Tests
2
3on:
4  workflow_dispatch: {}
5  push:
6    branches: [master]
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-18.04
30    env:
31      NDK_ABI_FILTERS: x86_64
32    steps:
33      - name: Check out repository
34        uses: actions/checkout@v2
35        with:
36          submodules: true
37      - name: Get yarn cache directory path
38        id: yarn-cache-dir-path
39        run: echo "::set-output name=dir::$(yarn cache dir)"
40      - uses: actions/cache@v2
41        name: Restore yarn cache
42        with:
43          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
44          key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
45          restore-keys: |
46            ${{ runner.os }}-yarn-
47      - run: yarn install --frozen-lockfile
48      - uses: actions/cache@v2
49        name: Restore Gradle cache
50        with:
51          path: ~/.gradle/caches
52          key: ${{ runner.os }}-gradle-${{ hashFiles('android/*.gradle*') }}
53          restore-keys: |
54            ${{ runner.os }}-gradle-
55      - uses: actions/cache@v2
56        name: Restore NDK cache
57        id: cache-android-ndk
58        with:
59          path: /usr/local/lib/android/sdk/ndk/19.2.5345600/
60          key: ${{ runner.os }}-ndk-19.2.5345600
61          restore-keys: |
62            ${{ runner.os }}-ndk-
63      - name: Install NDK
64        if: steps.cache-android-ndk.outputs.cache-hit != 'true'
65        run: |
66          sudo $ANDROID_SDK_ROOT/tools/bin/sdkmanager --install "ndk;19.2.5345600"
67      - run: echo "$(pwd)/bin" >> $GITHUB_PATH
68      - name: Patch react-native to support single abi
69        run: sed -i 's/^APP_ABI := .*$/APP_ABI := $(if $(NDK_ABI_FILTERS),$(NDK_ABI_FILTERS),$(armeabi-v7a x86 arm64-v8a x86_64))/g' ReactAndroid/src/main/jni/Application.mk
70        working-directory: react-native-lab/react-native
71      - name: Run Spotless lint check
72        env:
73          ANDROID_NDK_HOME: /usr/local/lib/android/sdk/ndk/19.2.5345600/
74        working-directory: android
75        run: ./gradlew spotlessCheck || { echo '::error Spotless lint failed. Run `./gradlew spotlessApply` to automatically fix formatting.' && exit 1; }
76      - name: Run native Android unit tests
77        env:
78          ANDROID_NDK_HOME: /usr/local/lib/android/sdk/ndk/19.2.5345600/
79        run: expotools native-unit-tests --platform android
80      - name: Save test results
81        if: always()
82        uses: actions/upload-artifact@v2
83        with:
84          name: test-results
85          path: packages/**/build/test-results/**/*xml
86