name: Code Coverage

on: workflow_dispatch

jobs:

  codecov:
    runs-on: ubuntu-20.04
    env:
      WEBPCONVERT_EWWW_API_KEY: ${{ secrets.WEBPCONVERT_EWWW_API_KEY }}
      WEBPCONVERT_WPC_API_URL: ${{ secrets.WEBPCONVERT_WPC_API_URL }}
      WEBPCONVERT_WPC_API_KEY: ${{ secrets.WEBPCONVERT_WPC_API_KEY }}
      WEBPCONVERT_WPC_API_URL_API0: ${{ secrets.WEBPCONVERT_WPC_API_URL_API0 }}
    steps:
    - name: Checkout
      uses: actions/checkout@v2

#    - name: Setup vips
#      run: |
#        chmod +x ./.github/install-vips.sh
#        ./.github/install-vips.sh

    - name: Setup ffmpeg
      uses: FedericoCarboni/setup-ffmpeg@v1

    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.1'
        # Note: Currently, gmagick and imagick are mutually exclusive.
        # It seems they are installed in the order indicated in "extensions" and the latter cancels the former
        extensions: exif, mbstring, fileinfo, gd, vips, gmagick, imagick

    - name: Setup problem matchers for PHP
      run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

    - name: Setup problem matchers for PHPUnit
      run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

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

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

    - name: Install dependencies
      run: composer install --prefer-dist --no-progress

    - name: Run test suite
      run: composer run-script test-with-coverage

    - name: Upload Scrutinizer coverage
      uses: sudo-bot/action-scrutinizer@latest
      with:
        cli-args: "--format=php-clover build/coverage.clover"
