name: iOS Build & Detox

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

jobs:
  build:
    runs-on: macos-latest
    timeout-minutes: 45  # Figure out why this job can be super slow; runner hardware?

    defaults:
      run:
        working-directory: ./example

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

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

      - name: Install Yarn Dependencies
        run: yarn install --immutable --check-cache

      - 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 -c ios.sim.release

      - name: Test with detox
        run: yarn detox test --debug-synchronization 200 -c ios.sim.release
