name: PHP Semver CI

on:
  push:
    branches: [ master ]
    paths-ignore:
      - '**.md'
  pull_request:
    branches: [ master ]

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ]
    steps:
      - uses: actions/checkout@v2

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php-versions }}

      - name: Validate composer.json and composer.lock
        run: composer validate --strict

      - name: Cache Composer packages
        id: composer-cache
        uses: actions/cache@v2
        with:
          path: vendor
          key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            ${{ runner.os }}-php-

      - name: Install dependencies
        run: |
          composer self-update
          composer install --prefer-dist --no-progress --no-suggest

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


  coverage:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '7.4'
          extensions: xdebug

      - name: Validate composer.json and composer.lock
        run: composer validate --strict

      - name: Cache Composer packages
        id: composer-cache
        uses: actions/cache@v2
        with:
          path: vendor
          key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            ${{ runner.os }}-php-

      - name: Install dependencies
        run: |
          composer self-update
          composer install --prefer-dist --no-progress --no-suggest

      - name: Execute coverage
        run: vendor/bin/phpunit --coverage-clover clover.xml

      - name: Upload coverage report
        run: bash <(curl -s https://codecov.io/bash)