name: E2E

on:
  push:
  pull_request:

permissions:
  contents: read

jobs:
  browser_tests:
    runs-on: ubuntu-latest
    if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[ci skip]')"

    strategy:
      fail-fast: false
      matrix:
        php: ["8.1", "8.3"]

    name: Linux / PHP ${{ matrix.php }}

    services:
      mailhost:
        image: docker.io/greenmail/standalone
        ports:
          - '3143:3143'
          - '3025:3025'
      browserhost:
        image: docker.io/selenium/standalone-chromium
        volumes:
          - '/dev/shm:/dev/shm'
          - ${{ github.workspace }}:/roundcubemail
        ports:
          - '4444:4444'
        options: '--add-host=host.docker.internal:host-gateway'

    env:
      WEBDRIVER_CONNECT_URL: 'http://localhost:4444'
      SERVER_URL: 'http://host.docker.internal:8000'
      SERVER_BIND: '0.0.0.0:8000'
      BROWSER_DOWNLOADS_DIR: '/roundcubemail/tests/Browser/downloads'
      TESTRUNNER_DOWNLOADS_DIR: './tests/Browser/downloads'
      RC_CONFIG_IMAP_HOST: 'tls://localhost:3143'
      RC_CONFIG_SMTP_HOST: 'localhost:3025'

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

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: dom, curl, fileinfo, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, ldap, intl, pspell
          tools: composer:v2
          coverage: none

      - name: Setup NPM
        uses: actions/setup-node@v4
        with:
          node-version: '16'

      - name: Setup problem matchers
        run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

      - name: Install Aspell
        run: sudo apt-get -y install aspell aspell-en aspell-de

      - name: Execute tests
        run: .ci/run_browser_tests.sh

      - name: Upload screenshots as artifacts
        # Upload screenshot if the test suite failed.
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: screenshots
          path: tests/Browser/screenshots
          
