Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker compose for testing #9525

Merged
merged 9 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .ci/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
services:
mailhost:
image: docker.io/greenmail/standalone
browserhost:
image: docker.io/selenium/standalone-chromium
volumes:
- '/dev/shm:/dev/shm'
- './Browser/downloads:/downloads'

browser_tests:
depends_on:
- mailhost
- browserhost
hostname: 'testrunner'
image: ghcr.io/roundcube/roundcubemail-testrunner:php8.3
volumes:
- '..:/app'
- './Browser/downloads:/downloads'
environment:
WEBDRIVER_CONNECT_URL: 'http://browserhost:4444'
SERVER_URL: 'http://testrunner:8000'
SERVER_BIND: '0.0.0.0:8000'
BROWSER_DOWNLOADS_DIR: '/downloads'
TESTRUNNER_DOWNLOADS_DIR: './Browser/downloads'
RC_CONFIG_IMAP_HOST: 'tls://mailhost:3143'
RC_CONFIG_SMTP_HOST: 'mailhost:3025'
command:
- .ci/run_browser_tests.sh

tests:
depends_on:
- mailhost
image: ghcr.io/roundcube/roundcubemail-testrunner:php8.3
volumes:
- '..:/app'
command:
- .ci/run_tests.sh

codespell:
image: ghcr.io/roundcube/roundcubemail-testrunner:php8.3
volumes:
- '..:/app'
command:
- vendor/bin/php-cs-fixer
- fix
- --dry-run
- --using-cache=no
- --diff
- --verbose

codestyle:
image: ghcr.io/roundcube/roundcubemail-testrunner:php8.3
volumes:
- '..:/app'
command:
- npx
- eslint
- .
16 changes: 13 additions & 3 deletions .github/config-test.inc.php → .ci/config-test.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@
$config['db_dsnw'] = 'sqlite:///' . sys_get_temp_dir() . '/roundcube-test-sqlite.db?mode=0646';

// Test user credentials
$config['tests_username'] = 'test';
$config['tests_password'] = 'test';
$config['tests_username'] = '[email protected]';
$config['tests_password'] = 'admin';

$config['imap_host'] = getenv('RC_CONFIG_IMAP_HOST') ?: 'localhost:143';
$config['imap_auth_type'] = 'IMAP';
$config['imap_conn_options'] = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
];
// $config['managesieve_host'] = 'localhost:4190';

// GreenMail
$config['smtp_host'] = 'localhost:25';
$config['smtp_host'] = getenv('RC_CONFIG_SMTP_HOST') ?: 'localhost:25';

// Settings required by the tests

Expand Down
48 changes: 48 additions & 0 deletions .ci/docker-images/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
ARG PHPVERSION=8.3
FROM php:${PHPVERSION}-cli

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libfreetype6-dev \
libicu-dev \
libjpeg62-turbo-dev \
libldap2-dev \
libpng-dev \
libpq-dev \
libsqlite3-dev \
libzip-dev \
libpspell-dev \
libonig-dev \
libldap-common \
libenchant-2-dev \
nodejs \
npm \
aspell \
aspell-en \
aspell-de \
hunspell-en-us \
git \
&& apt-get clean

# TODO: Do we need the multiarch-args? What for?
#RUN debMultiarch="$(dpkg-architecture --query DEB_BUILD_MULTIARCH)" \
RUN docker-php-ext-configure gd --with-jpeg --with-freetype \
#&& docker-php-ext-configure ldap --with-libdir="lib/$debMultiarch" \
&& docker-php-ext-configure ldap \
&& docker-php-ext-install \
zip \
pcntl \
gd \
ldap \
intl \
pspell \
enchant

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

# Create working directory
WORKDIR /app

VOLUME /app
14 changes: 14 additions & 0 deletions .ci/docker-images/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

case "$1" in
8.1|8.3)
phpversion="$1"
;;
*)
echo "Error: first and only argument must be the wanted PHP version."
echo "Usage: $(basename $0) 8.1|8.3"
exit 1
;;
esac

exec docker build --build-arg "PHPVERSION=$phpversion" -f "$(realpath $(dirname $0)/Dockerfile)" -t "ghcr.io/pabzm/roundcubemail-testrunner:php$phpversion" "$(realpath $(dirname $0)/../../..)"
59 changes: 59 additions & 0 deletions .ci/run_browser_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash -ex

# The script is intended for use locally, as well as in the CI.
# It runs the browser-tests ("E2E" in the CI).
# It expects a running IMAP server (connection configured in
# `config-test.inc.php`, and a running Chrome/Chromium browser (connection
# hard-coded in code, overrideable via environment variables).

# Make temp and logs writeable to everyone.
chmod 777 temp logs

# Create downloads dir and ensure permissions (if it's set, the variable might
# be blank if tests are not run using containers).
if test -n "$TESTRUNNER_DOWNLOADS_DIR"; then
# Use sudo because in the Github action we apparently can't use a
# directory in $HOME or /tmp but another one for which we need
# superuser-rights.
install -m 777 -d "$TESTRUNNER_DOWNLOADS_DIR"
fi

if ! test -f config/config-test.inc.php; then
cp -v .ci/config-test.inc.php config/config-test.inc.php
fi

# Install dependencies for to remote control the browser.
composer require -n "nesbot/carbon:^2.62.1" --no-update
composer require -n "laravel/dusk:^7.9" --no-update

if $(echo $PHP_VERSION | grep -q '^8.3'); then
# Downgrade dependencies (for PHP 8.3 only)
composer update --prefer-dist --prefer-stable --prefer-lowest --no-interaction --no-progress --optimize-autoloader
else
composer update --prefer-dist --no-interaction --no-progress
fi

# Install development tools.
npm install

# Install javascript dependencies
bin/install-jsdeps.sh

# Compile Elastic's styles
npx lessc --clean-css="--s1 --advanced" skins/elastic/styles/styles.less > skins/elastic/styles/styles.min.css
npx lessc --clean-css="--s1 --advanced" skins/elastic/styles/print.less > skins/elastic/styles/print.min.css
npx lessc --clean-css="--s1 --advanced" skins/elastic/styles/embed.less > skins/elastic/styles/embed.min.css

# Use minified javascript files
bin/jsshrink.sh

# Run tests
echo "TESTS_MODE: DESKTOP"
TESTS_MODE=desktop vendor/bin/phpunit -c tests/Browser/phpunit.xml --fail-on-warning --fail-on-risky --exclude-group=failsonga

echo "TESTS_MODE: TABLET"
TESTS_MODE=tablet vendor/bin/phpunit -c tests/Browser/phpunit.xml --fail-on-warning --fail-on-risky --exclude-group=failsonga-tablet

# Mobile mode tests are unreliable on Github Actions
# echo "TESTS_MODE: PHONE"
# TESTS_MODE=phone vendor/bin/phpunit -c tests/Browser/phpunit.xml --fail-on-warning --fail-on-risky --exclude-group=failsonga-phone
19 changes: 19 additions & 0 deletions .ci/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash -ex

if ! test -f config/config-test.inc.php; then
cp -v .ci/config-test.inc.php config/config-test.inc.php
fi

composer require "kolab/net_ldap3:~1.1.4" --no-update

# Install dependencies, prefer highest.
composer update --prefer-dist --no-interaction --no-progress

# Execute tests.
vendor/bin/phpunit -c tests/phpunit.xml --fail-on-warning --fail-on-risky

# Downgrade dependencies to the lowest versions.
composer update --prefer-dist --prefer-stable --prefer-lowest --no-interaction --no-progress --optimize-autoloader

# Execute tests again.
vendor/bin/phpunit -c tests/phpunit.xml --fail-on-warning --fail-on-risky
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ module.exports = {
'/vendor',
'/public_html',
'/plugins/jqueryui/js',
'/plugins/managesieve/codemirror',
'/program/js/tinymce',
'/program/js/publickey.js',
'node_modules',
'*.min.js',
],
rules: {
'brace-style': ['error', '1tbs'],
Expand Down
39 changes: 0 additions & 39 deletions .github/run.sh

This file was deleted.

58 changes: 34 additions & 24 deletions .github/workflows/browser_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,30 @@ jobs:

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
Expand All @@ -31,12 +55,6 @@ jobs:
tools: composer:v2
coverage: none

- name: Set up JDK 1.8
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '8'

- name: Setup NPM
uses: actions/setup-node@v4
with:
Expand All @@ -48,22 +66,14 @@ jobs:
- name: Install Aspell
run: sudo apt-get -y install aspell aspell-en aspell-de

- name: Setup composer
run: |
composer require "nesbot/carbon:^2.62.1" --no-update
composer require "laravel/dusk:^7.9" --no-update

- name: Install dependencies
run: |
composer update --prefer-dist --no-interaction --no-progress
npm install

- name: Roundcube configuration
run: cp .github/config-test.inc.php config/config-test.inc.php

- name: Downgrade dependencies (for PHP 8.3 only)
if: matrix.php == '8.3'
run: composer update --prefer-dist --prefer-stable --prefer-lowest --no-interaction --no-progress --optimize-autoloader

- name: Execute tests
run: .github/run.sh
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

Loading