name: CI

on:
- pull_request
- push

jobs:
  unit-tests:
    strategy:
      matrix:
        operating-system:
        - ubuntu-latest
        - windows-latest
        - macos-latest
        php-version:
        - '5.3'
        - '5.4'
        - '5.5'
        - '5.6'
        - '7.0'
        - '7.1'
        - '7.2'
        - '7.3'
        - '7.4'
        - '8.0'
        - '8.1'

    name: unit-tests on php-${{ matrix.php-version }} - ${{ matrix.operating-system }}
    runs-on: ${{ matrix.operating-system }}

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: ${{ matrix.php-version }}
        extensions: dom, libxml, xmlwriter
        coverage: xdebug

    - name: Install composer dependencies
      run: composer update --no-ansi --no-interaction --no-progress

    - name: Run unit tests
      run: php tests/run.php unit

  e2e-tests:
    strategy:
      matrix:
        tesseract-version:
        - '3.02'
        - '3.03'
        - '3.04'
        - '3.05'
        - '4.00'
        - '4.1.0'
        - '4.1.1'

    name: e2e-tests on tesseract-${{ matrix.tesseract-version }}
    runs-on: ubuntu-latest
    container: quay.io/thiagoalessio/tesseract-ocr-for-php-ci:${{ matrix.tesseract-version }}

    steps:
    - name: Checkout code
      uses: actions/checkout@v1

    - name: Install dependencies
      run: composer update --no-ansi --no-interaction --no-progress

    - name: Run end-to-end tests
      run: php tests/run.php e2e

  code-coverage:
    strategy:
      matrix:
        operating-system:
        - ubuntu-latest
        - macos-latest

    name: code-coverage on ${{ matrix.operating-system }}
    runs-on: ${{ matrix.operating-system }}

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.1'
        extensions: dom, libxml, xmlwriter
        coverage: xdebug

    - name: Install system dependencies (linux)
      run: >
        sudo apt-get -y update &&
        DEBIAN_FRONTEND=noninteractive sudo apt-get -y install
        tesseract-ocr tesseract-ocr-deu tesseract-ocr-jpn tesseract-ocr-spa
      if: ${{ matrix.operating-system == 'ubuntu-latest' }}

    - name: Install system dependencies (macos)
      run: brew install tesseract tesseract-lang
      if: ${{ matrix.operating-system == 'macos-latest' }}

    - name: Install composer dependencies
      run: composer update --no-ansi --no-interaction --no-progress

    - name: Run unit + e2e tests
      run: php tests/run.php unit e2e

    - name: Report code coverage
      run: bash <(curl -s https://codecov.io/bash)
