Skip to content

Commit

Permalink
Mostly unified testing code
Browse files Browse the repository at this point in the history
This allows the tests to be run in three ways, with almost identical
setup code:

* in github-CI,
* locally via docker compose,
* locally on the host as a script.
  • Loading branch information
pabzm committed Jul 5, 2024
1 parent a71f204 commit 0e41cf1
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 147 deletions.
File renamed without changes.
14 changes: 2 additions & 12 deletions .ci/docker-images/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ RUN apt-get update \
libonig-dev \
libldap-common \
libenchant-2-dev \
tini \
nodejs \
npm \
aspell \
aspell-en \
aspell-de \
hunspell-en-us \
git \
&& apt-get clean

# TODO: Do we need the multiarch-args? What for?
Expand All @@ -44,15 +45,4 @@ COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
# Create working directory
WORKDIR /app

COPY . .

ENV TESTS_MODE desktop
VOLUME /app

# Run the entrypoint script from the mounted code to allow modifications.
# Use tini to pass on process signals correctly (required to abort with CTRL-C,
# etc.).
ENTRYPOINT ["tini", "--", "/app/.ci/docker-images/docker-entrypoint.sh"]

# By default run the browser tests.
CMD ["vendor/bin/phpunit", "-c", "tests/Browser/phpunit.xml", "--fail-on-warning", "--fail-on-risky", "--exclude-group=failsonga"]
2 changes: 1 addition & 1 deletion .ci/docker-images/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ case "$1" in
;;
esac

exec docker build --build-arg "PHPVERSION=$phpversion" -f "$(realpath $(dirname $0)/Dockerfile)" -t "ghcr.io/roundcube/roundcubemail-testrunner:php$phpversion" "$(realpath $(dirname $0)/../../..)"
exec docker build --build-arg "PHPVERSION=$phpversion" -f "$(realpath $(dirname $0)/Dockerfile)" -t "ghcr.io/pabzm/roundcubemail-testrunner:php$phpversion" "$(realpath $(dirname $0)/../../..)"
54 changes: 0 additions & 54 deletions .ci/docker-images/docker-entrypoint.sh

This file was deleted.

60 changes: 60 additions & 0 deletions .ci/run_browser_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/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 it's writeable to everyone (if it's set,
# the variable might be blank if tests are not run using containers).
if test -n "$DOWNLOADS_DIR"; then
# Create downloads dir and ensure everyone can write into it (it's being used
# from different containers).
mkdir -p "$DOWNLOADS_DIR"
chmod 777 "$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

# Export some variables used in the testing code.
#export WEBDRIVER_CONNECT_URL SERVER_URL SERVER_BIND DOWNLOADS_DIR

# 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
39 changes: 0 additions & 39 deletions .github/run.sh

This file was deleted.

34 changes: 20 additions & 14 deletions .github/workflows/browser_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ jobs:
php: ["8.1", "8.3"]

name: Linux / PHP ${{ matrix.php }}
container:
image: "ghcr.io/pabzm/roundcubemail-testrunner:php${{ matrix.php }}"
options: "--hostname=testrunner"
volumes:
- /tmp/downloads:/downloads
- ${{ runner.tool_cache }}:/tool_cache

services:
mailhost:
Expand All @@ -41,21 +35,33 @@ jobs:
DOWNLOADS_DIR: '/downloads'

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::/tool_cache/phpunit.json"
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
# Apparently we can't reference the default entrypoint and default
# command, so we have to repeat them.
run: ./.ci/docker-images/docker-entrypoint.sh vendor/bin/phpunit -c tests/Browser/phpunit.xml --fail-on-warning --fail-on-risky --exclude-group=failsonga
run: .github/run.sh

- name: Upload screenshots as artifacts
# Always run this step, even if previous steps failed.
if: always()
# Upload screenshot if the test suite failed.
if: failure()
uses: actions/upload-artifact@v4
with:
name: screenshots
path: tests/Browser/screenshots

19 changes: 2 additions & 17 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,8 @@ jobs:
- name: Install Aspell/Hunspell
run: sudo apt-get -y install aspell aspell-en aspell-de hunspell-en-us

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

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

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

- name: Execute tests (highest)
run: vendor/bin/phpunit -c tests/phpunit.xml --fail-on-warning --fail-on-risky
- name: Execute tests
run: .ci/run_tests.sh

- name: Upload artifacts
uses: actions/upload-artifact@master
Expand All @@ -56,12 +47,6 @@ jobs:
name: Logs
path: logs/errors.log

- name: Downgrade dependencies
run: composer update --prefer-dist --prefer-stable --prefer-lowest --no-interaction --no-progress --optimize-autoloader

- name: Execute tests (lowest)
run: vendor/bin/phpunit -c tests/phpunit.xml --fail-on-warning --fail-on-risky

tests_windows:
runs-on: windows-latest
if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[ci skip]')"
Expand Down
12 changes: 2 additions & 10 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,15 @@ services:
SERVER_URL: 'http://testrunner:8000'
SERVER_BIND: '0.0.0.0:8000'
DOWNLOADS_DIR: '/downloads'

command: .ci/run_browser_tests.sh

tests:
depends_on:
- mailhost
image: ghcr.io/pabzm/roundcubemail-testrunner:php8.3
volumes:
- '.:/app'
environment:
BROWSER_URL: 'http://browserhost:4444'
DOWNLOADS_DIR: '/downloads'
command:
- ./vendor/bin/phpunit
- -c
- tests/phpunit.xml
- --fail-on-warning
- --fail-on-risky
command: .ci/run_tests.sh

codespell:
image: ghcr.io/pabzm/roundcubemail-testrunner:php8.3
Expand Down

0 comments on commit 0e41cf1

Please sign in to comment.