name: Build

on:
    push: ~
    pull_request: ~
    release:
        types: [created]
    schedule:
        -
            cron: "0 1 * * 6" # Run at 1am every Saturday
    workflow_dispatch: ~

jobs:
    tests:
        runs-on: ubuntu-latest
        name: Build and test
        strategy:
            fail-fast: false
            matrix:
                php: ["8.1", "8.2", "8.3"]
                symfony: ["^5.4", "^6.4", "^7.0"]
                dbal: ["^2.0", "^3.0"]
                exclude:
                    -
                        php: "8.1"
                        symfony: "^7.0"
                    -
                        symfony: "^7.0"
                        dbal: "^2.0"

        steps:
            -
                uses: actions/checkout@v4

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

            -
                name: Restrict Symfony version
                if: matrix.symfony != ''
                run: |
                    composer global config --no-plugins allow-plugins.symfony/flex true
                    composer global require --no-progress --no-scripts --no-plugins "symfony/flex:^1.17 || ^2.0"
                    composer config extra.symfony.require "${{ matrix.symfony }}"

            -
                name: Restrict DBAL version
                if: matrix.dbal != ''
                run: |
                    composer require doctrine/dbal "${{ matrix.dbal }}" --no-update

            -
                name: Install dependencies
                run: composer update ${{ matrix.composer-flags }}

            -
                name: Run analysis
                run: composer analyse

            -
                name: Run tests
                run: composer test
