name: build

on:
  push:
    branches: [ master, v2, v3 ]
  pull_request:
    branches: [ master, v2, v3 ]

jobs:
  build:
    runs-on: 'ubuntu-latest'
    strategy:
      matrix:
        php-versions: [ '8.0', '8.1', '8.2' ]

    steps:
    - uses: actions/checkout@v2

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

    - 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 install --prefer-dist --no-progress --no-interaction

    - name: Run linter
      run: ./vendor/bin/pint -v --test

    - name: Run tests
      run: vendor/bin/phpunit -c ./phpunit.xml

    - uses: php-actions/phpstan@v3
      with:
        path: src/

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