name: Development Client

on:
  workflow_dispatch: {}
  pull_request:
    branches: [master]
    paths:
      - .github/workflows/development-client.yml
      - packages/expo-dev-*/**

jobs:
  android:
    runs-on: ubuntu-18.04
    steps:
      - name: Check out repository
        uses: actions/checkout@v2
        with:
          submodules: false
      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"
      - uses: actions/cache@v2
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-
      - run: yarn install --frozen-lockfile
      - uses: actions/cache@v2
        with:
          path: ~/.gradle/caches
          key: ${{ runner.os }}-gradle-${{ hashFiles('android/*.gradle*') }}
          restore-keys: |
            ${{ runner.os }}-gradle-
      - uses: actions/cache@v2
        id: cache-android-ndk
        with:
          path: /usr/local/lib/android/sdk/ndk/19.2.5345600/
          key: ${{ runner.os }}-ndk-19.2.5345600
          restore-keys: |
            ${{ runner.os }}-ndk-
      - name: Install NDK
        if: steps.cache-android-ndk.outputs.cache-hit != 'true'
        run: |
          sudo $ANDROID_HOME/tools/bin/sdkmanager --install "ndk;19.2.5345600"
      - run: yarn global add expo-cli
      - run: echo "$(yarn global bin)" >> $GITHUB_PATH
      - name: Init new expo app
        working-directory: ../
        run: expo-cli init development-client-android-test --name development-client-android-test --yes
      - name: Add dependencies
        working-directory: ../development-client-android-test
        run: yarn add file:../expo/packages/expo-dev-menu file:../expo/packages/expo-dev-menu-interface file:../expo/packages/expo-dev-launcher
      - name: Setup app.config.json
        working-directory: ../development-client-android-test
        run: echo "{\"name\":\"development-client-android-test\",\"plugins\":[\"expo-dev-menu\",\"expo-dev-launcher\"],\"android\":{\"package\":\"com.devclient.test\"},\"ios\":{\"bundleIdentifier\":\"com.devclient.test\"}}" > app.config.json
      - name: Eject
        working-directory: ../development-client-android-test
        run: expo-cli eject
      - name: Build debug
        env:
          ANDROID_NDK_HOME: /usr/local/lib/android/sdk/ndk/19.2.5345600/
        working-directory: ../development-client-android-test/android
        run: ./gradlew assembleDebug

  ios:
    runs-on: macos-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v2
        with:
          submodules: false
      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"
      - uses: actions/cache@v2
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-
      - run: yarn install --frozen-lockfile
      - run: yarn global add expo-cli
      - run: echo "$(yarn global bin)" >> $GITHUB_PATH
      - name: Init new expo app
        working-directory: ../
        run: expo-cli init development-client-ios-test --name development-client-ios-test --yes
      - name: Add dependencies
        working-directory: ../development-client-ios-test
        run: yarn add file:../expo/packages/expo-dev-menu file:../expo/packages/expo-dev-menu-interface file:../expo/packages/expo-dev-launcher
      - name: Setup app.config.json
        working-directory: ../development-client-ios-test
        run: echo "{\"name\":\"development-client-ios-test\",\"plugins\":[\"expo-dev-menu\",\"expo-dev-launcher\"],\"android\":{\"package\":\"com.devclient.test\"},\"ios\":{\"bundleIdentifier\":\"com.devclient.test\"}}" > app.config.json
      - name: Eject
        working-directory: ../development-client-ios-test
        run: expo-cli eject
      - name: Build debug
        working-directory: ../development-client-ios-test
        run: xcodebuild -workspace ios/developmentclientiostest.xcworkspace -scheme developmentclientiostest -configuration debug -sdk iphonesimulator -arch x86_64
