version: 1

environment:
  php: 8.0
  node: 14

services:
  - mysql: 5.7
  - redis:

pipeline:
  - name: Setup
    cmd: |
      composer require "algolia/algoliasearch-client-php:^2.2" --dev --no-interaction --no-update

      composer require "laravel/framework:^9.0" --dev --no-interaction --no-update

      composer install --no-interaction --prefer-dist --optimize-autoloader
      ./vendor/bin/testbench-dusk package:discover
      ./vendor/bin/testbench-dusk view:clear
  - name: PHPStan
    cmd: |
      if [[ -f "phpstan.neon.dist" && -f "phpstan-baseline.neon" && -f "./vendor/bin/phpstan" ]]; then
        ./vendor/bin/phpstan analyse
      fi
  - name: PHPUnit
    cmd: |
      ./vendor/bin/phpunit --stop-on-failure --no-coverage --testdox
  - name: Set up Dusk tests
    cmd: |
      cp webpack.mix.js.dist webpack.mix.js

      if [[ $CI_COMMIT_BRANCH = "3.0" || $CI_COMMIT_BRANCH = "develop" ]]; then
        composer run dusk:assets --no-interaction
      else
        composer run dusk:dev-assets --no-interaction
      fi

      ./vendor/bin/dusk-updater detect --auto-update
  - name: Dusk tests
    cmd: |
      APP_URL=http://nova-dusk-suite.test CI=true ./vendor/bin/phpunit -c phpunit.dusk.xml.dist --stop-on-failure --exclude-group external-network,local-time --no-coverage

