name: CLI Test

on:
  pull_request:
    paths:
      - '.github/workflows/cli.yml'
      - 'packages/cli/**'
      - 'packages/create-app/**'
      - 'packages/core/**'
      - 'packages/core-api/**'
      - 'yarn.lock'

jobs:
  build:
    runs-on: ${{ matrix.os }}

    services:
      postgres:
        image: postgres:latest
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: postgres
        ports:
          - 5432/tcp
        # needed because the postgres container does not provide a healthcheck
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

    strategy:
      matrix:
        os: [ubuntu-latest]
        node-version: [12.x]

    env:
      CI: true
      NODE_OPTIONS: --max-old-space-size=4096

    name: Node ${{ matrix.node-version }} on ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      - name: find location of global yarn cache
        id: yarn-cache
        run: echo "::set-output name=dir::$(yarn cache dir)"
      - name: cache global yarn cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.yarn-cache.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: use node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: yarn install
        run: yarn install --frozen-lockfile
      - run: yarn tsc
      - run: yarn build
      - name: verify app and plugin creation
        env:
          POSTGRES_HOST: localhost
          POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
        run: |
          sudo sysctl fs.inotify.max_user_watches=524288
          node ${{ github.workspace }}/packages/cli/e2e-test/cli-e2e-test.js
