Skip to content

Commit 2ba0550

Browse files
[TASK] Rework chapter about the runTests.sh and build/testing mechanism (#340)
* [TASK] Rework chapter about the runTests.sh and build/testing mechanism * Update Documentation/HandlingAPatch/CherryPick.rst * [TASK] Code review changes * Apply suggestions from code review --------- Co-authored-by: Stefan Frömken <[email protected]>
1 parent d7c63c4 commit 2ba0550

File tree

7 files changed

+220
-109
lines changed

7 files changed

+220
-109
lines changed

Documentation/HandlingAPatch/CherryPick.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,20 @@ to cherry-pick it from the review system into your local git repository.
5151

5252
4. Clean up your local repository
5353

54-
Save your local changes beforehand, if you have any.
55-
54+
Save your local changes beforehand, if you have any. Otherwise the
55+
`git reset` performed after that would delete local changes, which
56+
may happen if you work on different patches simultaneously with the
57+
same repository directory.
58+
5659
.. code-block:: bash
5760
5861
git stash save 'comment-your-changes'
5962
6063
.. code-block:: bash
6164
65+
git fetch --all
6266
git reset --hard origin/main
63-
git pull
67+
git pull --rebase
6468
6569
5. Execute the command (git cherry-pick)
6670

@@ -77,5 +81,7 @@ to cherry-pick it from the review system into your local git repository.
7781
6. Cleanup your TYPO3 installation
7882

7983
Depending on the changes made by the patch, you may have to apply some changes
80-
to your TYPO3 installation: see :ref:`cleanup-typo3`.
84+
to your TYPO3 installation as well. Also, if the last time you pulled from the
85+
GitHub repository is some time ago, you may need to pull the most recent
86+
dependencies. And you may need to rebuild the CSS/JS assets. See :ref:`cleanup-typo3`.
8187

Documentation/HandlingAPatch/CleanupTypo3.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ Before :ref:`Cherry-picking a patch <cherry-pick-a-patch>` or starting a new pat
1919
.. code-block:: bash
2020
:caption: shell command
2121
22+
git fetch --all
2223
git reset --hard origin/main
23-
git pull
24+
git pull --rebase
2425
2526
2627
.. _cleanup-typo3:
@@ -40,7 +41,9 @@ any case or if in doubt, you can safely perform all steps.
4041
:caption: shell command
4142
4243
Build/Scripts/runTests.sh -s clean
44+
# For DDEV environments, prefix with `ddev ...`
4345
bin/typo3 cache:flush
46+
bin/typo3 cache:warmup
4447
4548
**Changes in composer.json**:
4649

@@ -64,9 +67,16 @@ Delete browser cache or
6467
`hard refresh <https://www.filecloud.com/blog/2015/03/tech-tip-how-to-do-hard-refresh-in-browsers/>`__
6568
(e.g. CTRL + F5)
6669

70+
Also you may need to create the JS/CSS assets:
71+
72+
.. code-block:: bash
73+
74+
./Build/Scripts/runTests.sh -s buildCss
75+
./Build/Scripts/runTests.sh -s buildJavascript
76+
6777
**Changes in DB schema (ext_tables.sql)**:
6878

69-
Maintenance: Analyze Database Structure, Apply selected changes.
79+
:guilabel:`Maintenance: Analyze Database Structure, Apply selected changes.`
7080

7181
.. image:: /Images/ManualScreenshots/analyze.svg
7282
:class: with-shadow

Documentation/Setup/Prerequisites.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ Required:
1212

1313
* Git
1414
* Once you have setup the Git repository, it is advised to look at the listed
15-
dependencies for :file:`runTests.sh` by running
16-
:bash:`Build/Scripts/runTests.sh -h` (see :ref:`runTests_sh`).
15+
dependencies (basically: Docker) for :file:`runTests.sh` (see :ref:`runTests_sh`).
1716

1817
Recommended:
1918

2019
* IDE with TYPO3 plugins, such as PhpStorm or Visual Studio Code. While you
2120
can also use a simple editor, a properly setup IDE will help with
2221
code-completion, marking errors and applying coding guidelines.
23-
* DDEV for setting up the TYPO3 installation. Alternative methods
24-
are possible, e.g. using a locally installed web server and database. DDEV
22+
* `DDEV <https://ddev.com>`__ for setting up the PHP/Database web environment as a base for the TYPO3
23+
installation. Alternative methods
24+
are possible (XAMPP, LAMP, MAMP, WAMP, custom docker-compose) or even using a custom
25+
locally installed web server and database. DDEV
2526
provides custom configurations for TYPO3 which can be used for core
26-
development as well.
27+
development as well, and is an easy-to-use layer on top of docker-compose.
2728

2829
Information on using these tools is covered in detail later on this chapter.

Documentation/Setup/SetupTypo3.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,17 @@ composer install
3737
Run composer install in the same directory you cloned the TYPO3 CMS core
3838
repository.
3939

40-
It is recommended to use runTests.sh for this. The "direct command" is an
41-
alternative. You only need to run one of these!
40+
It is recommended to use :file:`runTests.sh` for this (see :ref:`testing-core`). The "direct command" is an
41+
alternative, but it requires your local system to have proper PHP and Composer versions ready to use.
42+
You only need to run one of these!
4243

4344

4445
.. note::
4546

46-
While working with the TYPO3 sources composer can not detect the TYPO3 version of your
47+
While working with the TYPO3 sources, Composer may not detect the TYPO3 version of your
4748
cloned project because there was none. Before you run `composer install` may need to export
4849
the `COMPOSER_ROOT_VERSION environment variable <https://getcomposer.org/doc/03-cli.md#composer-root-version>`__.
49-
Here you need to set a full version string matching the TYPO3 version of your clone.
50+
Here you need to set a full version string matching the TYPO3 version of your Git clone.
5051

5152
Example:
5253

Documentation/Testing/CoreTesting.rst

Lines changed: 81 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ you a better understanding of testing within TYPO3's Core. A full Core git check
1414
to run tests in TYPO3.
1515

1616
Core development is most likely bound to the Core `main` branch - backporting patches to older
17-
branches are usually handled by Core maintainers and often don't affect other Core contributors.
17+
branches is usually handled by Core maintainers ("Mergers") and often doesn't affect other Core contributors.
1818

19-
Note, the main script
20-
`Build/Scripts/runTests.sh <https://github.com/typo3/typo3/blob/main/Build/Scripts/runTests.sh>`_
21-
is relatively new. It works best when executed on a Linux based host but can be run under macOS and
22-
Windows with some performance drawbacks on macOS.
19+
The main entry point to perform testing and build-related actions is the helper
20+
`Build/Scripts/runTests.sh <https://github.com/typo3/typo3/blob/main/Build/Scripts/runTests.sh>`_.
21+
It works best when executed on a Linux based host but can be run under macOS and
22+
Windows with some filesystem performance drawbacks on macOS. It utilizes Docker containers,
23+
and more details can be found in :ref:`Using runTests.sh <t3contribute:runTests_sh>`.
2324

2425
Additionally, it *is* possible to execute tests on a local system without using Docker. Depending on
2526
which test suite is executed, developers may need to configure their environments to run the
@@ -37,7 +38,7 @@ Many developers are familiar with `Docker <https://www.docker.com/>`_. As outlin
3738
reliable environment to run tests and also remove the need to manage niche dependencies on your local
3839
environment for tests such as "execute functional test 'X' using PostgreSQL with xdebug".
3940

40-
Git, docker and docker-compose are all required. For standalone test execution, a local installation of
41+
Git and docker (or podman) are required. For standalone test execution, a local installation of
4142
PHP is not required. You can even `composer install` a Core by calling `Build/Scripts/runTests.sh -s
4243
composerInstall` in a container.
4344

@@ -57,7 +58,7 @@ Windows can rely on WSL to have a decent docker version, too.
5758
Quick start
5859
===========
5960

60-
From now on, it is assumed that git, docker and docker-compose are available with the most up-to-date release
61+
From now on, it is assumed that git and docker (or podman) are available with the most up-to-date release
6162
running on the host system. Executing the basic Core unit test suite boils down to:
6263

6364
.. code-block:: shell
@@ -80,27 +81,25 @@ Overview
8081
So what just happened? We cloned a Core, Composer installed dependencies and executed Core
8182
unit tests. Let's have a look at some more details: :file:`runTests.sh` is a shell script that figures out
8283
which test suite with which options a user wants to execute, does some error handling for broken
83-
combinations, writes the file `Build/testing-docker/local/.env` according to its findings and then executes a
84-
couple of `docker-compose` commands to prepare containers, runs tests and stops containers after execution
85-
again.
86-
87-
A Core developer doing this for the first time may notice `docker-compose` pulling several container images
88-
before continuing. These are the dependent images needed to execute certain jobs. For instance the
89-
container `typo3gmbh/php74 <https://hub.docker.com/r/typo3gmbh/php72/>`_ may be fetched. Its definition
90-
can be found at `TYPO3 GmbH GitHub <https://github.com/TYPO3GmbH/infra-bamboo-remote-agent>`_.
91-
These are the exact same containers Bamboo based testing is executed in. In Bamboo, the combination of
92-
:file:`Build/bamboo/src/main/java/core/PreMergeSpec.java` and :file:`Build/testing-docker/bamboo/docker-compose.yml`
93-
specifies what Bamboo executes for patches pushed to the review system. On local testing, this is the
94-
combination of :file:`Build/Scripts/runTests.sh`, :file:`Build/testing-docker/local/.env` (created by
95-
runTests.sh) and
96-
`Build/testing-docker/local/docker-compose.yml <https://github.com/typo3/typo3/blob/main/Build/testing-docker/local/docker-compose.yml>`_.
97-
98-
Whats impressive is that :file:`runTests.sh` can do everything locally that Bamboo executes as `pre-merge
99-
<https://bamboo.typo3.com/browse/CORE-GTC>`_ tests at the same time. It's just that the combinations of tests
100-
and splitting to different jobs is slightly different, for instance Bamboo does multiple tests in
101-
the "integration" test at once that are single "check" suites in :file:`runTests.sh`. But if a patch is
102-
pushed to Bamboo and it complains about something being broken, it is possible to replay and fix the
103-
failing suite locally, then push an updated patch and hopefully enable the Bamboo test to pass.
84+
combinations and then uses local docker commands to run specific containers with specific options. Using
85+
these containers, the actions are performed, and the containers are stopped after execution.
86+
87+
A Core developer doing this for the first time may notice that several container images
88+
will be pulled before continuing. These are the dependent images needed to execute certain jobs. For instance,
89+
a container providing the specific PHP-version may be fetched. The same containers are used for the
90+
TYPO3 CI GitLab Pipeline, even utilizing the same `runTests.sh` script. What's impressive is that
91+
you can locally run the same tests like a fully-fledged CI server..
92+
93+
The GitLab CI Pipeline is maintained through the Ansible infrastructure found on
94+
`https://git.typo3.org/typo3/CI/testing-infrastructure/-/tree/main/ansible?ref_type=heads`__, and the Pipeline
95+
itself is set up through `https://github.com/TYPO3/typo3/tree/main/Build/gitlab-ci/`__.
96+
97+
Compared to your local execution it's just that the combinations of tests
98+
and splitting to different jobs which is slightly different, for instance GitLab CI paralelly performs multiple
99+
tests with more complex version matrixes (PHP and Databases).
100+
101+
If a patch is pushed to GitLab and it complains about something being broken, it is possible to replay and fix the
102+
failing suite locally, then push an updated patch and hopefully enable the tests to pass.
104103

105104

106105
A runTests.sh run
@@ -111,37 +110,23 @@ Let's pick a :file:`runTests.sh` example and have a closer look:
111110
.. code-block:: shell
112111
113112
lolli@apoc /var/www/local/cms/Web $ Build/Scripts/runTests.sh -s functional typo3/sysext/core/Tests/Functional/Authentication/
114-
Using driver: mysqli
115-
Creating network "local_default" with the default driver
116-
Creating local_mariadb_1 ... done
117-
Creating local_memcached1-5_1 ... done
118-
Creating local_redis4_1 ... done
119-
Creating local_prepare_functional_mariadb_run ... done
120-
Waiting for database start...
121-
Database is up
122-
Creating local_functional_mariadb_run ... done
123-
PHP 8.0.14 (cli) (built: Dec 18 2021 02:58:33) ( NTS )
124-
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.
125-
126-
........................................................ 56 / 56 (100%)
127-
128-
Time: 00:24.864, Memory: 101.00 MB
129-
130-
OK (56 tests, 162 assertions)
131-
Stopping local_redis4_1 ... done
132-
Stopping local_mariadb_1 ... done
133-
Stopping local_memcached1-5_1 ... done
134-
Removing local_functional_mariadb_run_d03a24bcf25c ... done
135-
Removing local_prepare_functional_mariadb_run_4648d92e8e32 ... done
136-
Removing local_redis4_1 ... done
137-
Removing local_mariadb_1 ... done
138-
Removing local_memcached1-5_1 ... done
139-
Removing network local_default
113+
PHPUnit 11.2.5 by Sebastian Bergmann and contributors.
114+
115+
Runtime: PHP 8.2.19
116+
Configuration: /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/Build/phpunit/FunctionalTests.xml
117+
118+
................................................................. 65 / 67 ( 97%)
119+
.. 67 / 67 (100%)
120+
121+
Time: 00:12.077, Memory: 103.00 MB
122+
123+
OK (67 tests, 176 assertions)
140124
141125
###########################################################################
142126
Result of functional
143-
PHP: 8.0
144-
DBMS: mariadb version 10.3 driver mysqli
127+
Container runtime: docker
128+
PHP: 8.2
129+
DBMS: sqlite
145130
SUCCESS
146131
###########################################################################
147132
@@ -152,11 +137,12 @@ Let's pick a :file:`runTests.sh` example and have a closer look:
152137
153138
The command asks :file:`runTests.sh` to execute the "functional" test suite `-s functional` and to not execute all
154139
available tests but only those within `typo3/sysext/core/Tests/Functional/Authentication/`. The script first
155-
starts the containers it needs: Redis, memcached and a MariaDB. All in one network. It then waits until
156-
the MariaDB container opens its database port, then starts a PHP 8.0 container and calls phpunit to execute
157-
the tests. phpunit executes only one test in this case, that one is green. The containers and networks are then
158-
removed again. Note the exit code of :file:`runTests.sh` (`echo $?`) is identical to the exit code of the phpunit
159-
call: If phpunit reports green, :file:`runTests.sh` returns 0, and if phpunit is red, the exit code would be non zero.
140+
starts the containers it needs: Redis, memcached (previously also MariaDB by default, which is now using
141+
SQLite instead, due to less dependencies). All in one network. It then starts a PHP 8.2 container and calls
142+
phpunit from there to execute the tests. phpunit executes only one test in this case, that one is green. The containers
143+
and networks are then removed again. Note the exit code of :file:`runTests.sh` (`echo $?`) is identical to the exit
144+
code of the phpunit call: If phpunit reports green, :file:`runTests.sh` returns 0, and if phpunit is red, the exit code
145+
would be non zero.
160146

161147

162148
.. _testing-core-examples:
@@ -172,7 +158,7 @@ are not valid:
172158
173159
lolli@apoc /var/www/local/cms/Web $ Build/Scripts/runTests.sh -h
174160
TYPO3 Core test runner. Execute acceptance, unit, functional and other test suites in
175-
a docker based test environment. Handles execution of single test files, sending
161+
a container based test environment. Handles execution of single test files, sending
176162
xdebug information to a local IDE and more.
177163
...
178164
@@ -181,14 +167,14 @@ tests, but there is more:
181167

182168
.. code-block:: shell
183169
184-
# Execute the unit test suite with PHP 7.4
185-
Build/Scripts/runTests.sh -s unit -p 7.4
170+
# Execute the unit test suite with PHP 8.3
171+
Build/Scripts/runTests.sh -s unit -p 8.3
186172
187173
# Execute some backend acceptance tests
188174
Build/Scripts/runTests.sh -s acceptance typo3/sysext/core/Tests/Acceptance/Backend/Topbar/
189175
190-
# Execute some functional tests with PHP 8.0 and postgres DBMS
191-
Build/Scripts/runTests.sh -s functional -p 8.0 -d postgres typo3/sysext/core/Tests/Functional/Package/
176+
# Execute some functional tests with PHP 8.2 and postgres DBMS
177+
Build/Scripts/runTests.sh -s functional -p 8.2 -d postgres typo3/sysext/core/Tests/Functional/Package/
192178
193179
# Execute the cgl fixer
194180
Build/Scripts/runTests.sh -s cglGit
@@ -199,8 +185,11 @@ tests, but there is more:
199185
As shown there are various combinations available. Just go ahead, read the help output and play around.
200186
There are tons of further test suites to try.
201187

202-
One interesting detail should be mentioned: :file:`runTests.sh` uses `typo3gmbh/phpXY <https://hub.docker.com/r/typo3gmbh/>`_
203-
as main PHP containers. Those are loosely maintained and may be updated. Use the command
188+
Also note that you can use the `-b` option to switch between `docker` and `podman` container execution,
189+
with `podman` being the default (when available).
190+
191+
One interesting detail should be mentioned: :file:`runTests.sh` uses several containers from
192+
`https://github.com/orgs/TYPO3/packages`_ for PHP and JavaScript environments. Use the command
204193
`Build/Scripts/runTests.sh -u` to fetch the latest versions of these containers.
205194

206195
.. index::
@@ -216,9 +205,9 @@ To speed up test execution, the PHP extension `xdebug` is not usually loaded.
216205
However, to allow debugging tests and system under tests, it is possible to
217206
activate xdebug and send debug output to a local IDE. We'll use PhpStorm for this example.
218207

219-
Let's verify our PhpStorm debug settings first. Go to File > Settings > Languages & Frameworks > PHP
220-
> Debug. Make sure "Can accept external connections" is enabled, remember the port if it is not the
221-
default port(9000) and also raise "Max. simultaneous connections" to two or three. Note remote debugging
208+
Let's verify our PhpStorm debug settings first. Go to :guilabel:`File > Settings > Languages & Frameworks > PHP
209+
> Debug`. Make sure "Can accept external connections" is enabled, remember the port if it is not the
210+
default port (9000) and also raise "Max. simultaneous connections" to two or three. Note remote debugging
222211
may impose a security risk since everyone on the network can send debug streams to your host.
223212

224213
.. figure:: PhpstormXdebugSettings.png
@@ -243,7 +232,7 @@ stops at this line and opens the debug window.
243232

244233
.. code-block:: shell
245234
246-
Build/Scripts/runTests.sh -x -s functional -p 7.4 -d postgres typo3/sysext/core/Tests/Functional/Package/RuntimeActivatedPackagesTest.php
235+
Build/Scripts/runTests.sh -x -s functional -p 8.1 -d postgres typo3/sysext/core/Tests/Functional/Package/RuntimeActivatedPackagesTest.php
247236
248237
The important flag here is `-x`! This is available for unit and functional testing. It enables xdebug
249238
in the PHP container and sends all debug information to port 9000 of the host system. If a local PhpStorm
@@ -256,3 +245,23 @@ Additionally, it may be useful to activate "Break at first line in PHP scripts"
256245
mounts the local path to the same location within the container, so path mapping is not needed. PhpStorm
257246
also comes with a `guide <https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html>`_ how to set up
258247
debugging.
248+
249+
Building
250+
========
251+
252+
Luckily, `runTests.sh` also helps us to build JavaScript and CSS assets:
253+
254+
.. code-block:: shell
255+
256+
Build/Scripts/runTests.sh -s buildJavaScript
257+
Build/Scripts/runTests.sh -s buildCss
258+
259+
Again, this utilizes all the needed containers for the proper NodeJS environment, so you have
260+
zero local dependencies on properly building.
261+
262+
You can also run a watch task thanks to the full integration of npm command execution:
263+
264+
.. code-block:: shell
265+
266+
Build/Scripts/runTests.sh -s npm -- run watch
267+

Documentation/Testing/History.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,15 @@ major pre-condition, the broken constant TYPO3_MODE is finally gone (deprecated
309309
Further core versions can drop that constant and extensions will have to drop their usage, too.
310310
So with v12, TYPO3_MODE will be gone, and TYPO3 can create cool features from this. So again, the
311311
core testing paved the way for new opportunities and TYPO3 usages.
312+
313+
2024
314+
====
315+
316+
TYPO3 currently uses 4 dedicated "bare bone" Servers to perform CI tasks. This hardware performs
317+
11.513 unit tets in ~15 seconds. A typical pre-merge pipeline runtime is at ~5 minutes with 2 permutations
318+
of acceptance tests, 3 permutations of ~7500 functional tests, 3 permutations of unit tests plus
319+
statical code analysis, linting, build checks.
320+
321+
The 4 servers are provisioned using Ansible:
322+
`https://git.typo3.org/typo3/CI/testing-infrastructure/-/tree/main/ansible?ref_type=heads`__ and
323+
Pipelines configured in `https://github.com/TYPO3/typo3/tree/main/Build/gitlab-ci/`__.

0 commit comments

Comments
 (0)