name: Cypress

on:
  pull_request:
  push:
    branches:
      - master
      - stable*

env:
  APP_NAME: social
  BRANCH: ${{ github.base_ref }}
  CYPRESS_baseUrl: http://127.0.0.1:8082/index.php

jobs:
  cypress:
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        # run 2 copies of the current job in parallel
        containers: [1, 2]
        node-version: ['12']
        php-versions: ['7.4']

    name: Runner ${{ matrix.containers }}

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

      - name: Setup server
        run: |
          cd cypress
          docker-compose up -d
      - name: Set up node ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}

      - name: Install dependencies & build app
        run: |
          npm ci
          composer install
          TESTING=true npm run build --if-present
      - name: Wait for server
        run: |
          npm install -g wait-on
          wait-on -i 500 -t 240000 $CYPRESS_baseUrl

      - name: Enable app & configure server
        run: |
          cd cypress
          docker-compose exec --env APP_NAME=${{ env.APP_NAME }} -T nextcloud bash /initserver.sh
      - name: Cypress run
        uses: cypress-io/github-action@v1
        with:
          record: true
          parallel: true
          # cypress env
          ci-build-id: ${{ github.sha }}-${{ github.run_number }}
          tag: ${{ github.event_name }}
        env:
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          # https://github.com/cypress-io/github-action/issues/124
          COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }}
