name: iOS Build & Detox

on:
  workflow_call:
    inputs:
      NVMRC:
        required: true
        type: string
    secrets:
      MAPBOX_ACCESS_TOKEN:
        required: true

jobs:
  build:
    runs-on: macos-latest
    timeout-minutes: 25

    defaults:
      run:
        working-directory: ./example

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Access Token
        run: echo $MAPBOX_ACCESS_TOKEN > ./accesstoken
        env:
          MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}

      - name: Setup node ${{ inputs.NVMRC }}
        uses: actions/setup-node@v2.5.0
        with:
          node-version: ${{ inputs.NVMRC }}

      - name: Install Yarn Dependencies
        run: yarn install --network-timeout 1000000

      - name: Install Pod Dependencies
        run: cd ios && pod --version && pod install

      - name: Install Detox Dependencies
        run: |
          brew tap wix/brew
          brew install applesimutils

      - name: Build for detox
        run: yarn detox build

      - name: Test with detox
        run: yarn detox test --debug-synchronization 200
