name: Tests

on:
  push:
#    branches: [master]
  pull_request:
    types: [opened, synchronize, reopened]
  release:
    types: [created]

jobs:

  test_basic:
    name: basic PHP ${{ matrix.php }} - I ${{ matrix.imagemagick }}
    runs-on: ubuntu-20.04
    strategy:
      fail-fast: false
      matrix:
        os: [ ubuntu-latest ]
        php: [ 5.4 ]
        imagemagick: [
            # 7.0.10-27,
            # 6.9.2-0,
            git7,
            git6
        ]
#        exclude:
#          - php: 5.4
#            imagemagick: 6.8.7-0
#        allow_failures:
#         - imagemagick: git7
#          - imagemagick: git6

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

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

      - name: Apt install required packages
        run: |
          sudo apt-get update
          sudo apt-get install -y fonts-urw-base35 || true
          sudo apt-get install -y libfreetype6-dev || true
          sudo apt-get install -y texlive-fonts-recommended || true

      - name: Sanity check package.xml and install ImageMagick
        run: |
          for file in tests/*.phpt; do grep $(basename $file) package.xml >/dev/null || (echo "Missing $file from package.xml" ; exit 1); done
          bash ./imagemagick_dependency.sh " ${{ matrix.imagemagick }}"

      - name: Configure and check fonts are present
        run: |
          export NO_INTERACTION=1
          export REPORT_EXIT_STATUS=1
          export SKIP_SLOW_TESTS=1
          export PHP_IMAGICK_VERSION=$(php -r '$sxe = simplexml_load_file ("package.xml"); echo (string) $sxe->version->release;')
          export CFLAGS=$(php util/calculate_cflags.php "${{ matrix.php }}" "${{ matrix.imagemagick }}")
          echo "CFLAGS are ${CFLAGS}"
          phpize
          ./configure --with-imagick="${HOME}/im/imagemagick-${{ matrix.imagemagick }}"
          sudo make install
          php -d extension=imagick.so util/check_fonts.php

      - name: Run Imagick tests
        run: |
          export TEST_PHP_EXECUTABLE=`which php`
          php run-tests.php -d extension=imagick.so -d extension_dir=modules -n ./*.phpt --show-diff
          php run-tests.php -d extension=imagick.so -d extension_dir=modules -n ./tests/*.phpt --show-diff
          for i in `ls tests/*.diff 2>/dev/null`; do echo "-- START ${i}"; cat $i; echo "-- END"; done
          php ./util/check_version.php


  test_all:
    name: Full PHP ${{ matrix.php }} - I ${{ matrix.imagemagick }}
    needs: test_basic
    runs-on: ubuntu-20.04
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        php: [5.4, 8.0, 7.4, 7.3, 7.2, 7.1, 7.0, 5.6, 5.5]
        imagemagick: [
          7.0.10-27,
          7.0.8-4,
          7.0.1-0,
          git7,
          6.9.2-0,
          6.8.7-0,
          6.7.8-0,
          git6
        ]
        exclude:
          - php: 5.4
            imagemagick: 6.8.7-0
        allow_failures:
          - imagemagick: git7
          - imagemagick: git6

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

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

      - name: Apt install required packages
        run: |
          sudo apt-get update
          sudo apt-get install -y fonts-urw-base35 || true
          sudo apt-get install -y libfreetype6-dev || true
          sudo apt-get install -y texlive-fonts-recommended || true

      - name: Sanity check package.xml and install ImageMagick
        run: |
          for file in tests/*.phpt; do grep $(basename $file) package.xml >/dev/null || (echo "Missing $file from package.xml" ; exit 1); done
          bash ./imagemagick_dependency.sh " ${{ matrix.imagemagick }}"

      - name: Configure and check fonts are present
        run: |
          export NO_INTERACTION=1
          export REPORT_EXIT_STATUS=1
          export SKIP_SLOW_TESTS=1
          export PHP_IMAGICK_VERSION=$(php -r '$sxe = simplexml_load_file ("package.xml"); echo (string) $sxe->version->release;')
          export CFLAGS=$(php util/calculate_cflags.php "${{ matrix.php }}" "${{ matrix.imagemagick }}")
          echo "CFLAGS are ${CFLAGS}"
          phpize
          ./configure --with-imagick="${HOME}/im/imagemagick-${{ matrix.imagemagick }}"
          sudo make install
          php -d extension=imagick.so util/check_fonts.php

      - name: Run Imagick tests
        run: |
          export TEST_PHP_EXECUTABLE=`which php`
          php run-tests.php -d extension=imagick.so -d extension_dir=modules -n ./*.phpt --show-diff
          php run-tests.php -d extension=imagick.so -d extension_dir=modules -n ./tests/*.phpt --show-diff
          for i in `ls tests/*.diff 2>/dev/null`; do echo "-- START ${i}"; cat $i; echo "-- END"; done
          php ./util/check_version.php

