name: build

on: [push, pull_request]

env:
  COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
    phpstan:
        runs-on: ubuntu-20.04
        name: PHPStan
        steps:
            - name: Checkout
              uses: actions/checkout@v2
            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: 8.0
            - run: composer require --no-update liip/imagine-bundle:"^1.7 || ^2.0"
            - name: Update project dependencies
              uses: ramsey/composer-install@v1
            - name: PHPStan
              uses: docker://oskarstark/phpstan-ga
              env:
                  CHECK_PLATFORM_REQUIREMENTS: false
                  REQUIRE_DEV: true
              with:
                  args: analyse
    cs-fixer:
        runs-on: ubuntu-20.04
        name: PHP-CS-Fixer
        steps:
            - name: Checkout
              uses: actions/checkout@v2
            - name: Fix CS
              uses: docker://oskarstark/php-cs-fixer-ga
    tests:
        runs-on: ubuntu-20.04
        strategy:
            matrix:
                php:
                    - '7.4'
                    - '8.0'
                    - '8.1'
                dependencies: [highest]
                symfony: ['*']
                validate_docs: [false]
                with_imagine: [false]
                with_oneupbundle: [true]
                include:
                    - extra: ', validate docs with lowest deps on PHP 7.4'
                      php: '7.4' # PHP 8 not yet supported by rusty
                      symfony: '*'
                      validate_docs: true
                      dependencies: lowest
                      with_imagine: false
                      with_oneupbundle: false
                    - php: '8.0'
                      symfony: '5.4.*'
                      dependencies: highest
                      with_imagine: false
                      with_oneupbundle: true
                    - php: '8.0'
                      symfony: '6.0.*'
                      dependencies: highest
                      with_imagine: false
                      with_oneupbundle: true
                    - php: '8.1'
                      symfony: '6.0.*'
                      dependencies: highest
                      with_imagine: false
                      with_oneupbundle: true
        name: PHP ${{ matrix.php }} with Symfony ${{ matrix.symfony }} tests with ${{ matrix.dependencies }} dependencies${{ matrix.extra }}
        steps:
            - name: Checkout
              uses: actions/checkout@v2
            - name: Cache
              uses: actions/cache@v2
              with:
                  path: ~/.composer/cache/files
                  key: ${{ matrix.php }}-${{ matrix.symfony }}-${{ matrix.dependencies }}
            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: ${{ matrix.php }}
                  extensions: mongodb-stable, pdo_sqlite
            - run: |
                  composer global config --no-plugins allow-plugins.symfony/flex true
                  composer global require --no-interaction --no-progress symfony/flex:^1.11
                  composer config extra.symfony.require ${{ matrix.symfony }}
              if: matrix.symfony != '*'
            - run: composer require --no-update liip/imagine-bundle:"^1.7 || ^2.0"
              if: matrix.with_imagine
            - run: composer require --no-update oneup/flysystem-bundle:"^4.0.1"
              if: matrix.with_oneupbundle
            - run: composer require --dev --no-update kphoen/rusty:"dev-update-php-parser"
              if: matrix.validate_docs
            - name: Update project dependencies
              uses: ramsey/composer-install@v1
              with:
                dependency-versions: ${{ matrix.dependencies }}
            - run: vendor/bin/phpunit
            - run: vendor/bin/rusty check --no-execute ./docs
              if: matrix.validate_docs
