name: CI

on:
  push:
    branches: [ main, master, 1.x ]
  pull_request:
    branches: [ main, master, 1.x ]

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        php-version:
          - '7.2'
          - '7.3'
          - '7.4'
          - '8.0'
          - '8.1'
          - '8.2'
          - '8.3'
          - '8.4'
          - '8.5'
      fail-fast: false

    name: PHP ${{ matrix.php-version }}

    steps:
      - name: Checkout code
        uses: actions/checkout@v6
        with:
          fetch-depth: 10

      # Setup PHP environment
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php-version }}
          extensions: mbstring, pdo, sqlite, pdo_sqlite

      - name: Install dependencies
        run: composer install --prefer-dist --no-interaction --no-progress

      - name: Run tests
        run: .github/run-phpunit.sh ${{ matrix.php-version }}

      - name: Upload Scrutinizer coverage
        if: ${{ hashFiles('coverage.clover') != '' }}
        uses: sudo-bot/action-scrutinizer@latest
        with:
          cli-args: "--format=php-clover coverage.clover --revision=${{ github.event.pull_request.head.sha || github.sha }}"
