name: CI build
on: [ push, pull_request ]
jobs:
    build:
        name: PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }} ${{ matrix.extra-label }} ${{ matrix.composer-dependencies }}
        runs-on: ${{ matrix.operating-system }}
        strategy:
            fail-fast: false
            matrix:
                operating-system: [ ubuntu-latest ]
                php-versions: [ '8.1', '8.2', '8.3' ]
                composer-dependencies: [ '', '--prefer-lowest' ]
                symfony-version: [ '' ]
                extra-label: [ '' ]
                include:
                    # SF 5.4 and 6.4
                    -   php-versions: '8.1'
                        operating-system: ubuntu-latest
                        symfony-version: '5.4.*'
                        extra-label: 'SF 5.4'

                    -   php-versions: '8.2'
                        operating-system: ubuntu-latest
                        symfony-version: '5.4.*'
                        extra-label: 'SF 5.4'

                    -   php-versions: '8.1'
                        operating-system: ubuntu-latest
                        symfony-version: '6.4.*'
                        extra-label: 'SF 6.4'

                    # Windows
                    -   php-versions: '8.1'
                        operating-system: windows-latest

                    # Windows
                    -   php-versions: '8.2'
                        operating-system: windows-latest

                    # Windows
                    -   php-versions: '8.3'
                        operating-system: windows-latest

        steps:
            -   name: Checkout
                uses: actions/checkout@v2

            -   name: Setup PHP, with composer and extensions
                uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
                with:
                    php-version: ${{ matrix.php-versions }}
                    ini-values: memory_limit=-1
                    tools: composer:v2

            -   name: Get composer cache directory
                id: composer-cache
                run: echo "::set-output name=dir::$(composer config cache-files-dir)"

            -   name: Cache dependencies
                uses: actions/cache@v2
                with:
                    path: ${{ steps.composer-cache.outputs.dir }}
                    key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
                    restore-keys: ${{ runner.os }}-composer-

            -   name: Specific Symfony version
                if: ${{ matrix.symfony-version != '' }}
                run: composer require --dev --no-update symfony/symfony=${{ matrix.symfony-version }}

            # for some reason vendor/symfony/symfony/src/Symfony/Bridge/Monolog/Processor/CompatibilityProcessor.php tries to load Monolog, so let's just add it
            -   name: Install Monolog for Symfony 6.4
                if: ${{ matrix.symfony-version == '6.4.*' }}
                run: composer require --dev --no-update monolog/monolog=3.5.0

            -   name: Install Composer dependencies
                run: composer update --no-progress --prefer-dist --optimize-autoloader ${{ matrix.composer-dependencies }}

            -   name: Run Tests
                run: vendor/bin/phpunit
