Continuous integration/Tutorials/Adding a MediaWiki extension

This tutorial is aimed at adding automatic tests for a new MediaWiki extension. You will learn how to verify the tests are going to work properly and how to edit the Wikimedia platform configuration to enable continuous testing.

We will base all our commands to adds jobs for the DonationInterface MediaWiki extension. That will include PHP and javascript linting, and running unit tests with a MediaWiki installation.

Prerequisites
You should have a working Jenkins job builder installation already. If not please follow the step by step guide to install Jenkins Job Builder.

A labs account to be able to submit your changes for review to Wikimedia Gerrit install.

Your extension does install using a SQLite backend.

Make sure all PHP files are valid:

As well has Javascript ones:

And of course the unit tests should pass.

Editing Zuul configuration
Once your jobs have been deployed in Jenkins, they need to be run whenever an action is made in Gerrit, such as a new patchset being submitted or a change being merged. That is the role of Zuul which is listen for Gerrit events and has a specification to trigger certain jobs on certain events.

The configuration is held in integration/config.git repository, in the file.

The file is made of four sections:

- pipelines : define event filtering and result handling behavior - jobs: finely adjust the behavior on a per job basis - project-templates : define common jobs triggering - projects: define, for a Gerrit repository, the pipelines to uses and the hierarchy of jobs being triggered.

We provide a template for MediaWiki extensions that will trigger PHPUnit tests:

As you can see, that is pretty similar to Jenkins Job Builder syntax.

To add the triggers for the DonationInterface extension, we should add a new entry in the project section and invoke the template:

The repository basename (in this case DonationInterface) is automatically passed to the template as the name parameter.

Save the file. That is all what is needed. You can then send it for review, a Jenkins job will validate your configuration and another job does a diff with the previous configuration.

To have it deployed, see the Zuul page, that requires shell access on the server running it.

For your own extension
The extension must be hosted on Wikimedia git infrastructure under the mediawiki/extensions/ git hierarchy. We do not support running tests hosted on foreign git repositories.

Your extension PHP entry point MUST be named the same as the extension, that is how Jenkins will load it up in the installed MediaWiki. For DonationInterface we had DonationInterface/DonationInterface.php.

The Jenkins job injects specific configuration at the end of MediaWiki LocalSettings.php. You can find them under integration/jenkins.git repository in directory /mediawiki/conf.d/. It set for example the global $wgWikimediaJenkinsCI which let you finely tweak your extension setting when running tests, for example to enable a feature which you want disabled by default but for which you have tests.