name: CI

on:
  push:
  pull_request:
    branches: [ master ]

jobs:
  test:
    name: PHP
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        php: ['8.0']
        phpunit: ['latest']
        include:
        - php: '7.2'
          phpunit: '8.5.13'
        - php: '7.3'
          phpunit: '8.5.13'
        - php: '7.4'
          phpunit: '8.5.13'
          coverage: xdebug
          flags: '--coverage-clover clover.xml'
#         - php: '8.1'
#           experimental: true

    services:
      mysql:
        image: mariadb
        ports:
          - 3306/tcp
        env:
          MYSQL_ALLOW_EMPTY_PASSWORD: false
          MYSQL_ROOT_PASSWORD: secret
          MYSQL_DATABASE: yourls_tests
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

    steps:
    - uses: actions/checkout@v2.4.0

    - name: Use PHP ${{ matrix.php }}
      uses: shivammathur/setup-php@2.15.0
      with:
        php-version: ${{ matrix.php }}
        extensions: mbstring, curl, zip, dom, simplexml, intl, pdo_mysql
        tools: phpunit:${{ matrix.phpunit }}
        coverage: ${{ matrix.coverage }}

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

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

    # - name: Install dependencies
    #   if: steps.composer-cache.outputs.cache-hit != 'true'
    #   run: composer install --prefer-dist --no-progress --no-suggest
    #   env:
    #     APP_ENV: testing

    # - name: Lint
    #   run: composer run-script lint

    - name: Prepare the application
      run: |
        git clone https://github.com/ozh/YOURLS-fr_FR.git user/languages/fr
        cp user/languages/fr/fr_FR.* user/languages
        cp tests/data/config/yourls-tests-config-ci.php user/config.php

    - name: Test
      run: phpunit --configuration phpunit.xml.dist ${{ matrix.flags }}
      env:
        DB_PORT: ${{ job.services.mysql.ports['3306'] }}

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