name: "Build"

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

jobs:
    build:
        runs-on: "ubuntu-latest"

        name: "PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, PHPUnit ${{ matrix.phpunit }}, PHP-Matcher ${{ matrix.php-matcher }}, Doctrine ORM ${{ matrix.orm }}"

        strategy:
            fail-fast: false
            matrix:
                php: [8.1, 8.2, 8.3]
                symfony: [6.4.*, 7.0.*]
                phpunit: [^9.0, ^10.0, ^11.0]
                php-matcher: [^6.0]
                orm: [^2.5, ^3.0]
                exclude:
                    - php: 8.1
                      symfony: 7.0.*
                    - php: 8.1
                      phpunit: ^11.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"
          run: |
                composer global config --no-plugins allow-plugins.symfony/flex true
                composer global require --no-progress --no-scripts --no-plugins symfony/flex
                composer config extra.symfony.require "${{ matrix.symfony }}"

        -
          name: "Restrict coduo/php-matcher version"
          run: "composer require \"coduo/php-matcher:${{ matrix.php-matcher }}\" --no-update --no-scripts"

        -
          name: "Restrict doctrine/orm version"
          run: "composer require \"doctrine/orm:${{ matrix.orm }}\" --no-update --no-scripts"

        -
          name: "Restrict phpunit/phpunit version"
          run: "composer require \"phpunit/phpunit:${{ matrix.phpunit }}\" --no-update --no-scripts"

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

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

        -
          name: "Run analyse"
          run: "composer analyse"

        -
          name: "Setup database"
          run: "test/app/console doctrine:schema:update --force -vvv"

        -
          name: "Run tests"
          run: "vendor/bin/phpunit"
