name: Build

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

jobs:
    tests:
        runs-on: ubuntu-latest
        name: "PHP ${{ matrix.php }}${{ matrix.symfony != '' && format(', Symfony {0}', matrix.symfony) || '' }}${{ matrix.symfony-contracts != '' && format(', Contracts {0}', matrix.symfony-contracts) || '' }}${{ matrix.twig != '' && format(', Twig {0}', matrix.twig) || '' }}"
        strategy:
            fail-fast: false
            matrix:
                include:
                    -
                        php: 7.4
                        symfony: ^4.4
                        symfony-contracts: ^1.1
                        twig: 2.*
                    -
                        php: 7.4
                        symfony: ^4.4
                        symfony-contracts: ^2.0
                        twig: 2.*
                    -
                        php: 7.4
                        symfony: ^4.4
                        symfony-contracts: ^1.1
                        twig: 3.*
                    -
                        php: 7.4
                        symfony: ^4.4
                        symfony-contracts: ^2.0
                        twig: 3.*
                    -
                        php: 7.4
                        symfony: ^5.2
                        symfony-contracts: ^2.0
                        twig: 2.*
                    -
                        php: 7.4
                        symfony: ^5.2
                        symfony-contracts: ^2.0
                        twig: 3.*
                    -
                        php: 8.0
                        symfony: ^4.4
                        twig: 2.*
                    -
                        php: 8.0
                        symfony: ^5.2
                        twig: 3.*

        steps:
            -
                uses: actions/checkout@v2

            -
                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 require --no-progress --no-scripts --no-plugins "symfony/flex:^1.10"
                    composer config extra.symfony.require "${{ matrix.symfony }}"

            -
                name: Update Symfony Contracts version
                if: matrix.symfony-contracts != ''
                run: composer require "symfony/translation-contracts:${{ matrix.symfony-contracts }}" "symfony/service-contracts:${{ matrix.symfony-contracts }}" --no-update --no-scripts

            -
                name: Update Twig version
                if: matrix.twig != ''
                run: composer require --dev "twig/twig:${{ matrix.twig }}" --no-update --no-scripts

            -
                name: Install dependencies
                run: composer update

            -
                name: Run analysis
                run: composer analyse

            -
                name: Run tests
                run: composer test
