name: run-tests

on:
    push:
    pull_request:
    schedule:
        - cron: "0 0 * * *"

jobs:
    test:
        if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
        runs-on: ubuntu-latest
        strategy:
            fail-fast: false
            matrix:
                php: [8.5, 8.4, 8.3, 8.2, 8.1]
                laravel: ["^12.0", "^11.0", "^10.0", "^9.0"]
                dependency-version: [prefer-lowest, prefer-stable]
                exclude:
                    -   laravel: "^12.0"
                        php: 8.1
                    -   laravel: "^11.0"
                        php: 8.1
                    -   laravel: "^10.0"
                        php: 8.4
                    -   laravel: "^10.0"
                        php: 8.5
                    -   laravel: "^9.0"
                        php: 8.4
                    -   laravel: "^9.0"
                        php: 8.5
        name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

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

            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: ${{ matrix.php }}
                  extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
                  coverage: none

            - name: Install dependencies
              run: |
                  composer require "laravel/framework:${{ matrix.laravel }}" "nesbot/carbon:>=2.72" --dev --no-interaction --no-update
                  composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction

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