name: Development Client latest e2e

on:
  workflow_dispatch: {}
  schedule:
    - cron: '0 0 * * SUN' # 0:00 AM UTC time every Sunday

concurrency:
  group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  detox_latest_e2e:
    runs-on: macos-11
    strategy:
      matrix:
        api-level: [31]
    steps:
      - name: 👀 Checkout
        uses: actions/checkout@v3
      - name: ➕ Add `bin` to GITHUB_PATH
        run: echo "$(pwd)/bin" >> $GITHUB_PATH
      - name: 🍺 Install required tools
        run: |
          brew tap wix/brew
          brew install applesimutils
          brew install watchman
      - name: 💎 Setup Ruby and install gems
        uses: ruby/setup-ruby@v1
        with:
          bundler-cache: true
      - name: 💎 Install cocoapods
        run: sudo gem install cocoapods
      - name: 🔨 Use JDK 11
        uses: actions/setup-java@v3
        with:
          distribution: 'temurin'
          java-version: '11'
      - name: ♻️ Restore caches
        uses: ./.github/actions/expo-caches
        id: expo-caches
        with:
          yarn-workspace: 'true'
          avd: 'true'
          avd-api: ${{ matrix.api-level }}
      - name: 🧶 Install `expo-test-runner`
        run: |
          yarn global add expo-test-runner@$(cat package.json | grep '"expo-test-runner": "[0-9]*\.[0-9]*\.[0-9]*' | head -n 1 | awk '{print $2}' | sed 's/"//g; s/,//g')
        working-directory: packages/expo-dev-client
      - name: 🧪 Run tests
        run: |
          yarn latest-e2e
        working-directory: packages/expo-dev-client
      - name: 💾 Store artifacts of build failures
        if: failure()
        uses: actions/upload-artifact@v3
        with:
          name: expo-dev-client-latest-e2e-artifacts
          path: packages/expo-dev-client/artifacts
      - name: 🔔 Notify on Slack
        uses: 8398a7/action-slack@v3
        if: failure()
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SLACK_WEBHOOK_URL: ${{ secrets.slack_webhook_dev_client }}
          MATRIX_CONTEXT: ${{ toJson(matrix) }}
        with:
          channel: '#dev-clients'
          status: ${{ job.status }}
          fields: job,message,ref,eventName,author,took
          author_name: Dev Client e2e
