name: CLI

on:
  push:
    branches: [main, 'sdk-*']
    paths:
      - .github/workflows/cli.yml
      - packages/expo/**
      - yarn.lock
  pull_request:
    paths:
      - .github/workflows/cli.yml
      - packages/expo/**
      - yarn.lock
  schedule:
    - cron: 0 14 * * *

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

jobs:
  test:
    runs-on: ubuntu-18.04
    steps:
      - name: 👀 Checkout a ref for the event
        uses: actions/checkout@v2
        with:
          fetch-depth: 100
      - name: ⬇️ Fetch commits from base branch
        run: git fetch origin ${{ github.event.before || github.base_ref || 'main' }}:${{ github.event.before || github.base_ref || 'main' }} --depth 100
        if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
      - name: ♻️ Restore workspace node modules
        uses: actions/cache@v2
        id: node-modules-cache
        with:
          path: |
            # See "workspaces" → "packages" in the root package.json for the source of truth of
            # which node_modules are affected by the root yarn.lock
            node_modules
            apps/*/node_modules
            home/node_modules
            packages/*/node_modules
            packages/@unimodules/*/node_modules
            react-native-lab/react-native/node_modules
          key: ${{ runner.os }}-modules-v2-${{ hashFiles('yarn.lock') }}
      - name: 🧶 Install node modules in root dir
        run: yarn install --frozen-lockfile
      - name: Build CLI
        run: yarn prepare:cli
        working-directory: packages/expo
      - name: Unit Test CLI
        run: yarn test:cli
        working-directory: packages/expo
      - name: E2E Test CLI
        run: yarn test:cli:e2e
        working-directory: packages/expo
      # - name: 🔔 Notify on Slack
      #   uses: 8398a7/action-slack@v3
      #   if: failure() && (github.event.ref == 'refs/heads/main' || startsWith(github.event.ref, 'refs/heads/sdk-'))
      #   env:
      #     GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      #     SLACK_WEBHOOK_URL: ${{ secrets.slack_webhook_api }}
      #   with:
      #     channel: '#expo-cli'
      #     status: ${{ job.status }}
      #     fields: job,message,ref,eventName,author,took
      #     author_name: Check packages
