name: coverage

on:
  push:
  pull_request:

jobs:
  linux_tests:
    runs-on: ubuntu-20.04

    strategy:
      fail-fast: true

    name: PHP Code Coverage

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 8.1
          extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, gd, xdebug
          tools: composer:v2
          coverage: xdebug

      - name: Install dependencies
        uses: nick-invision/retry@v2
        with:
          timeout_minutes: 5
          max_attempts: 2
          command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

      - name: Execute tests
        run: vendor/bin/phpunit --verbose

      - name: Upload coverage results to Coveralls
        env:
          COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: vendor/bin/php-coveralls -v
