name: run-tests

on:
    push:
    pull_request:
    schedule:
        -   cron: '0 0 * * *'

jobs:
    test:

        runs-on: ubuntu-latest
        strategy:
            fail-fast: true
            matrix:
                php: [7.4, 8.0]
                dependency-version: [prefer-stable]

        env:
            extensions: dom, curl, libxml, mbstring, zip, pcntl, bcmath, soap, intl, iconv

        name: P${{ matrix.php }} - ${{ matrix.dependency-version }}

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

            -   name: Cache dependencies
                uses: actions/cache@v3.0.1
                with:
                    path: ~/.composer/cache/files
                    key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

            -   name: Setup PHP extensions
                id: cache-env
                uses: shivammathur/cache-extensions@v1
                with:
                    php-version: ${{ matrix.php }}
                    extensions: ${{ env.extensions }}
                    key: php-extensions-cache-v1

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

            -   name: Install dependencies
                run: |
                    composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest

            -   name: Install Pandoc
                run: |
                    sudo apt-get update
                    sudo apt-get install -y wget
                    sudo mkdir -p /usr/src/pandoc
                    cd /usr/src/pandoc
                    sudo wget https://github.com/jgm/pandoc/releases/download/2.15/pandoc-2.15-1-amd64.deb
                    sudo dpkg -i pandoc-2.15-1-amd64.deb

            -   name: Execute tests
                run: vendor/bin/phpunit
