name: CI
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: shivammathur/setup-php@v2
        with:
          php-version: '8.0'
          coverage: xdebug
      - name: Configure sysctl limits for Elasticsearch
        run: |
          sudo swapoff -a
          sudo sysctl -w vm.swappiness=1
          sudo sysctl -w fs.file-max=262144
          sudo sysctl -w vm.max_map_count=262144
      - name: Run Elasticsearch
        uses: elastic/elastic-github-actions/elasticsearch@master
        with:
          stack-version: '7.12.0'
      - uses: actions/checkout@v2
      - name: Get composer cache directory
        id: composer-cache
        run: echo "::set-output name=dir::$(composer config cache-files-dir)"
      - name: Cache dependencies
        uses: actions/cache@v2
        with:
          path: ${{ steps.composer-cache.outputs.dir }}
          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: ${{ runner.os }}-composer-
      - name: Install dependencies
        run: composer install --no-progress --no-interaction
      - name: Generate app key
        run: |
          php -r "file_exists('.env') || copy('.env.ci', '.env');"
          php artisan key:generate
      - name: Run tests
        run: vendor/bin/paratest --coverage-clover build/logs/clover.xml
      - name: Upload coverage results to Coveralls
        env:
          COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v
