name: Dusk Apache
on:
  push:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: false

jobs:
  dusk_apache:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: true
      max-parallel: 1
      matrix:
        php-versions: [ '8.2' ]
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        env:
          DEBUG: true
          APP_ENV: "testing"
      - uses: ./.github/actions/setup-php
        with:
          php_version: ${{ matrix.php-versions }}
      - name: Npm install
        uses: actions/setup-node@v3
        with:
          node-version: 16
          cache: 'npm'
          cache-dependency-path: ./package-lock.json
      - run: npm install
      - run: npm run build
      - run: php artisan dusk:install
      - run: php artisan dusk:chrome-driver
      - name: Remove screenshot layout test
        run: |
          rm -f userfiles/templates/big/src/tests/Browser/BigScreenshotLayoutsTest.php
      - name: Setup Apache
        uses: thunder/apache-shiva-php-action@v1
        with:
          php-version: '8.2'
          site-directory: /home/runner/work/microweber/microweber/
          # Defaults to 8888
          http-port: 8000
      - name: Run Dusk Tests
        run: |
          chmod -R 0755 vendor/laravel/dusk/bin/
          composer test:dusk
      - name: Upload Screenshots
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: screenshots
          path: tests/Browser/screenshots
      - name: Upload Console Logs
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: console
          path: tests/Browser/console
      - name: Upload Laravel Storage Logs
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: storage-logs
          path: storage/logs
      - name: Upload Laravel config
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: config
          path: config
