name: run-tests

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

jobs:
    test:
        runs-on: ${{ matrix.os }}
        strategy:
            fail-fast: true
            matrix:
                php: [8.0, 7.4, 7.3, 7.2]
                laravel: [8.*, 7.*, 6.*]
                dependency-version: [prefer-lowest, prefer-stable]
                os: [ubuntu-latest]

        name: P${{ matrix.php }} - ${{ matrix.os }}

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

            - name: Install sqlite3
              run: sudo apt-get install sqlite3 libsqlite3-dev

            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: ${{ matrix.php }}
                  extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, iconv, imagick
                  coverage: none

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

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

            - name: Send Slack notification
              uses: 8398a7/action-slack@v2
              if: failure()
              with:
                  status: ${{ job.status }}
                  author_name: ${{ github.actor }}
              env:
                  SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
                  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
