name: Big test (trigger manually before releasing)

on: workflow_dispatch

permissions:
  contents: read

jobs:
  build:

    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: true
      matrix:
        os: [ubuntu-20.04, ubuntu-18.04, windows-2022, windows-2019, macos-11, macos-10.15]
        #os: [macos-11, macos-10.15, windows-2022, windows-2019]
        php: [8.1, 8.0, 7.4, 7.3, 7.2, 7.1, 7.0]
        #os: [windows-2022]
        #php: [8.1, 7.0]

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

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

    - name: Validate composer.json
      run: composer validate --strict

    - name: Composer alterations for PHP 7.2
      if: matrix.php == '7.2'
      run: |
        echo "Downgrading phpunit to ^8.0, which is the highest version that supports PHP 7.2"
        composer require "phpunit/phpunit:^8.0" --dev --no-update

    - name: Composer alterations for PHP 7.1
      if: matrix.php == '7.1'
      run: |
        echo "Removing phpstan, as it does not work on PHP 7.1"
        composer remove phpstan/phpstan --dev --no-update

        echo "Downgrading phpunit to ^7.0, which is the highest version that supports PHP 7.1"
        composer require "phpunit/phpunit:^7.0" --dev --no-update

    - name: Composer alterations for PHP 7.0
      if: matrix.php == '7.0'
      run: |
        echo "Remove phpstan, as it does not work on PHP 7.0"
        composer remove phpstan/phpstan --dev --no-update

        echo "Downgrading phpunit to ^6.0, which is the highest version that supports PHP 7.0"
        composer require "phpunit/phpunit:^6.0" --dev --no-update

    # Create composer.lock, which is going to be used in the cache key
    - name: Create composer.lock for cache key (this is a library, so composer.lock is not part of repo)
      run: composer update --no-install

    - name: Cache Composer packages
      id: composer-cache
      uses: actions/cache@v3
      with:
        path: vendor
        key: ${{ runner.os }}-php-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
        restore-keys: |
          ${{ runner.os }}-php-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
          ${{ runner.os }}-php-${{ matrix.php }}
          ${{ runner.os }}-php-

    - name: Composer install
      run: composer install --prefer-dist --no-progress

    - name: Run phpunit (test cases)
      run: composer run-script test-no-cov

    - name: Run phpstan on PHP>=7.2 (to check php syntax)
      if: (matrix.php != '7.0') && (matrix.php != '7.1') && (matrix.php != '7.2')
      run: composer run-script phpstan

    - name: run phpcs (to check coding style)
      run: composer run-script phpcs-all
