name: Android

on:
  push:
    branches:
      - master
      - fix-ci
  pull_request:
    paths:
      - ".github/workflows/main.yml"
      - "src/**"
      - "android/**"
      - "MMKV/**"

jobs:
  build:
    runs-on: ubuntu-20.04
    strategy:
      fail-fast: false
      matrix:
        include:
          - version: "0.61.x"
            folder: "rn61"
          - version: "0.62.x"
            folder: "rn62"
          - version: "0.63.x"
            folder: "rn63"
          - version: "0.64.x"
            folder: "rn64"
          - version: "0.65.x"
            folder: "rn65"
          - version: "0.66.x"
            folder: "rn66"
          - version: "0.67.x"
            folder: "rn67"  
          - version: "reanimated-2"
            folder: "reanimated2"

    steps:
    - uses: actions/checkout@v2

    - run: printenv

    - name: Get yarn cache directory path
      id: yarn-cache-dir-path
      run: echo "::set-output name=dir::$(yarn cache dir)"

    - uses: actions/cache@v2
      id: yarn-cache
      with:
        path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
        key: ${{ runner.os }}-yarn-${{ matrix.version }}
        restore-keys: |
          ${{ runner.os }}-yarn-

    - name: Build Android apk (release & debug)
      env:
        RN_VERSION: ${{ matrix.version }}
        RN_FOLDER: ${{ matrix.folder }}
        ANDROID_NDK_HOME: /usr/local/lib/android/sdk/ndk/21.4.7075529
      run: |
        echo $RN_VERSION $RN_FOLDER $ANDROID_NDK_HOME
        [[ "$RN_VERSION" == "reanimated-2" ]] && git clone --depth=1 https://github.com/software-mansion-labs/reanimated-2-playground.git "$RN_FOLDER" || npx react-native init "$RN_FOLDER" --version "$RN_VERSION"
        cd "$RN_FOLDER"
        yarn add file:..
        yarn add metro-react-native-babel-preset@0.66.2 -D
        npx mmkv-link
        cd ./android
        echo "cmake.dir=/usr/local/lib/android/sdk/cmake/3.10.2.4988404" >> local.properties
        ./gradlew assembleRelease
        ./gradlew assembleDebug
