name: CI

env:
  SYMFONY_PHPUNIT_DIR: "$HOME/symfony-bridge/.phpunit"

on:
  push:
      branches:
          - "*.x"
  pull_request:

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          # Test the latest stable release
          - php-version: '7.3'
          - php-version: '7.4'
          - php-version: '8.0'
          - php-version: '8.1'
            dependencies: 'jean-beru/fos-http-cache-cloudfront'
          - php-version: '7.4'
            symfony-version: '4.*'
          - php-version: '7.4'
            symfony-version: '5.*'
          - php-version: '8.0'
            symfony-version: '6.*'
          # Minimum supported dependencies with the oldest PHP version
          - php-version: '7.3'
            composer-flag: '--prefer-stable --prefer-lowest'
            symfony-version: '4.4'
          # Test latest unreleased versions
          - php-version: '8.0'
            symfony-version: '6.*'
            stability: 'dev'
    name: PHP ${{ matrix.php-version }} Test on Symfony ${{ matrix.symfony-version }} ${{ matrix.dependencies}} ${{ matrix.stability }} ${{ matrix.composer-flag }}
    steps:

      - name: Pull the code
        uses: actions/checkout@v4

      - name: Install PHP and Composer
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php-version }}
          tools: composer:v2, flex
          coverage: none

      - name: Stability
        run: composer config minimum-stability ${{ matrix.stability }}
        if: ${{ matrix.stability }}

      - name: Additional require
        run: composer require --no-update ${{ matrix.dependencies }}
        if: ${{ matrix.dependencies }}

      - name: Composer update
        env:
          SYMFONY_REQUIRE: ${{ matrix.symfony-version }}
        run: |
          composer update ${{ matrix.composer-flag }} --prefer-dist --no-interaction --no-progress

      - name: Composer validate
        run: composer validate --strict --no-check-lock
        if: ${{ matrix.stability != 'dev' }}

      - name: Run tests
        run: php vendor/bin/phpunit -v
        if: ${{ matrix.stability != 'dev' }}

      - name: Run tests allow to fail
        run: php vendor/bin/phpunit -v || true
        continue-on-error: true
        if: ${{ matrix.stability == 'dev' }}
