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
A labs account to be able to submit your changes for review to Wikimedia Gerrit install.

Your extension does install using a MySQL backend.

Make sure you have composer/npm entry points, if not check the BoilerPlate extension for predefined 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 repository, in the file.

The file is made of four sections:


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

We provide several templates for MediaWiki extensions that will trigger PHPUnit tests, one that install dependencies using :

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

You will want to add triggers for  and  :

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.