name: Build

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

jobs:
    test:
        runs-on: ubuntu-20.04

        name: "PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}"

        timeout-minutes: 10

        strategy:
            fail-fast: false
            matrix:
                php: [7.4, 8.0]
                symfony: [^4.4, ^5.2]

        steps:
            -   uses: actions/checkout@v2

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

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

            -   name: Cache Composer
                uses: actions/cache@v2
                with:
                    path: ${{ steps.composer-cache.outputs.dir }}
                    key: ${{ runner.os }}-php-${{ matrix.php }}-package-${{ matrix.package }}-composer-${{ hashFiles(format('src/Sylius/{0}/composer.json', matrix.package)) }}
                    restore-keys: |
                        ${{ runner.os }}-php-${{ matrix.php }}-package-${{ matrix.package }}-composer-
                        ${{ runner.os }}-php-${{ matrix.php }}-package-

            -   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: Install dependencies
                run: composer install --ansi --no-interaction

            -   name: Run Psalm
                run: vendor/bin/psalm

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

            -   name: Run Infection
                run: phpdbg -qrr vendor/bin/infection --min-msi=100
