name: run-tests

on:
  - push
  - pull_request

concurrency: ci-${{ github.ref }}

jobs:
  test:
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: true
      matrix:
        os: [ubuntu-20.04]
        php: [8.3, 8.2, 8.1]
        laravel: ['10.*', '11.*']
        ffmpeg: [5.0, 4.4]
        dependency-version: [prefer-lowest, prefer-stable]
        include:
          - laravel: 10.*
            testbench: 8.*
          - laravel: 11.*
            testbench: 9.*
        exclude:
          - laravel: 11.*
            php: 8.1

    name: ${{ matrix.os }} - P${{ matrix.php }} - L${{ matrix.laravel }} - FF${{ matrix.ffmpeg }} - ${{ matrix.dependency-version }}

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

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

      - name: Install FFmpeg
        uses: Iamshankhadeep/setup-ffmpeg@ffmpeg-5.0-20220119
        with:
          token: ${{ secrets.CI_GITHUB_TOKEN }}
          version: ${{ matrix.ffmpeg }}
        id: setup-ffmpeg

      - name: Install dependencies
        run: |
          composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
          composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest

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

      - name: Execute tests
        run: vendor/bin/phpunit --order-by random
        env:
          FFMPEG_TEMPORARY_FILES_ROOT: ${{ github.workspace }}
          FFMPEG_TEMPORARY_ENCRYPTED_HLS: /dev/shm
