Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Travis integration: Difference between revisions

From MoodleDocs
(Initial docs for Travis-CI integration)
 
mNo edit summary
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
= Background =
== Moodle core ==
 
=== Background ===


Moodle is regularly tested against a matrix of Databases, PHP Versions, and operating systems, however many developers do not have the resources available to run on many of these combinations before pushing an issue for integration as they are time-consuming to both set up and to run.
Moodle is regularly tested against a matrix of Databases, PHP Versions, and operating systems, however many developers do not have the resources available to run on many of these combinations before pushing an issue for integration as they are time-consuming to both set up and to run.
Line 9: Line 11:
Note: Moodle HQ uses the Jenkins CI platform internally and this should be seen as the canonical CI server for Moodle. The Travis integration provided is to provide early warning to developers of any issues with their code.
Note: Moodle HQ uses the Jenkins CI platform internally and this should be seen as the canonical CI server for Moodle. The Travis integration provided is to provide early warning to developers of any issues with their code.


= Usage =
=== Usage ===


Travis-CI is freely available and is usually configured to run automatically when pushing code, but it must be configured before first use.
Travis-CI is freely available and is usually configured to run automatically when pushing code, but it must be configured before first use.
Line 15: Line 17:
For the purpose of this documentation, it is assumed that you are pushing to a public Moodle repository on GitHub. Other integrations are supported, but the free service available from Travis is only available to public repositories.
For the purpose of this documentation, it is assumed that you are pushing to a public Moodle repository on GitHub. Other integrations are supported, but the free service available from Travis is only available to public repositories.


== Setup ==
=== Setup ===


# [[https://travis-ci.org/auth Sign in to Travis CI]] using your GitHub account
# [https://travis-ci.org/auth Sign in to Travis CI] using your GitHub account
# Once you’re signed in, and the initial synchronisation of your GitHub repositories has completed, go to your [[https://travis-ci.org/profile profile page]]
# Once you’re signed in, and the initial synchronisation of your GitHub repositories has completed, go to your [https://travis-ci.org/profile profile page]
# Enable Travis CI for your clone of the Moodle repository [[File:moodle-travis-enable.png]]
# Enable Travis CI for your clone of the Moodle repository [[File:moodle-travis-enable.png]]
# Click on the cog icon to configure the Integration
# Click on the cog icon to configure the Integration
# Ensure that "Build only if .travis.yml is present" is enabled [[File:moodle-travis-settings.png]]
# Ensure that "Build only if .travis.yml is present" is enabled [[File:moodle-travis-settings.png]]


=== Additional setup ===
=== How do I start a build? ===
 
It won't build immediately after setup. Builds start automatically when you push a change.
 
== Moodle plugins ==
 
See [https://moodle.org/mod/forum/discuss.php?d=323384 Adding Travis CI support into your plugin] forum discussion.
 
=== Ignoring files and folders ===
 
For some of the code analysis tools, it is important to ignore some files within the plugin because they might not be fixable, like a third party library. The all code analysis commands in this project ignore files and directories listed in the thirdpartylibs.xml plugin file. See https://docs.moodle.org/dev/Plugin_files#thirdpartylibs.xml for more info.
 
==== Ignoring files ====
 
Specifically for the codechecker command, you can ignore a single line, a section of a file or the whole file by using specific PHP comments. For details see this [[CodeSniffer]] wiki page.
In addition, you can ignore additional files by defining IGNORE_PATHS and/or IGNORE_NAMES environment variables in your .travis.yml file. These environment variables wont work for Grunt tasks, but will for everything else. Example:
<code php>
env:
global:
  - MOODLE_BRANCH=MOODLE_35_STABLE
  - IGNORE_PATHS=vendor/widget,javascript/min-lib.js
  - IGNORE_NAMES=*-m.js,bad_lib.php
matrix:
  - DB=pgsql
  - DB=mysqli
</code>
Both environment variables take a CSV value. For IGNORE_PATHS, it takes relative file paths to ignore. File paths can be a simple string like foo/bar or a regular expression like /^foo\/bar/. For IGNORE_NAMES, it takes file names to ignore. File names can be a simple string like foo.php, a glob like *.php or a regular expression like /\.php$/.
 
If you need to specify ignore paths for a specific command, then you can define additional environment variables. The variable names are the same as above, but prefixed with COMMANDNAME_. Example:


As part of the setup process for Travis, we install a number of Composer dependencies. Since Composer uses GitHub, it is extremely easy to have your account rate-limited by GitHub. This can slow the build down.
<code php>
env:
global:
  - MOODLE_BRANCH=MOODLE_35_STABLE
  - IGNORE_PATHS=vendor/widget,javascript/min-lib.js
  - IGNORE_NAMES=*-m.js,bad_lib.php
  - PHPUNIT_IGNORE_PATHS=$IGNORE_PATHS,cli
matrix:
  - DB=pgsql
  - DB=mysqli
</code>
In the above example, we are adding the cli path to our ignore paths for the PHPUnit command (this is also how you can ignore files for code coverage). Please note that this is a complete override and there is no merging with IGNORE_PATHS and IGNORE_NAMES. So, in the above, the PHPUnit command would not ignore the file names defined in IGNORE_NAMES.


In order to increase the rate at which you are limited, you must identify your Composer install to GitHub using a GitHub personal token.


# Generate a Github Personal Access Token
== See also ==
## Log in to your GitHub account
## From the top-right, open the user menu and select "Settings"
## From the menu on the left, choose "Personal Access Tokens"
## At the top-right, choose "Generate new token" (you will be asked for your GitHub password to access this page)
## Enter a title for your token (e.g. travis-moodle)
## Untick all of the scopes except for "public_repo" [[File:github-pat.png]]
## Click Generate token
## Copy the token generated into your clipboard
# Hop on over to travis-ci.org
# Open the configuration for your Moodle Integration with Travis
# Under environment variables, add a new variable. The name should be "GITHUB_APITOKEN". Paste your token into the value, and click the Add button
# Ensure that "Display value in build log" remains off. [[File:moodle-travis-env.png]]


This will add your GitHub Personal Access token to the composer configuration during the build process. This can increase the speed of the build dramatically.
* [[Talk:Travis Integration]] for previous Travis dev docs


[[Category:Developer tools]]
[[Category:Developer tools]]

Revision as of 07:50, 13 September 2018

Moodle core

Background

Moodle is regularly tested against a matrix of Databases, PHP Versions, and operating systems, however many developers do not have the resources available to run on many of these combinations before pushing an issue for integration as they are time-consuming to both set up and to run.

There are many Continuous Integration tools available to developers, and Travis-CI is just one of those available freely to the Open Source community.

Since version 3.0, Moodle includes a Travis configuration file in its repository. This configuration file configures and controls a Travis build across a matrix of testing environments. This allows developers pushing patches to Moodle to have their code unit tested before it reaches integration. The hope is that the availability of this integration should reduce the number of unit test failures seen during Integration.

Note: Moodle HQ uses the Jenkins CI platform internally and this should be seen as the canonical CI server for Moodle. The Travis integration provided is to provide early warning to developers of any issues with their code.

Usage

Travis-CI is freely available and is usually configured to run automatically when pushing code, but it must be configured before first use.

For the purpose of this documentation, it is assumed that you are pushing to a public Moodle repository on GitHub. Other integrations are supported, but the free service available from Travis is only available to public repositories.

Setup

  1. Sign in to Travis CI using your GitHub account
  2. Once you’re signed in, and the initial synchronisation of your GitHub repositories has completed, go to your profile page
  3. Enable Travis CI for your clone of the Moodle repository moodle-travis-enable.png
  4. Click on the cog icon to configure the Integration
  5. Ensure that "Build only if .travis.yml is present" is enabled moodle-travis-settings.png

How do I start a build?

It won't build immediately after setup. Builds start automatically when you push a change.

Moodle plugins

See Adding Travis CI support into your plugin forum discussion.

Ignoring files and folders

For some of the code analysis tools, it is important to ignore some files within the plugin because they might not be fixable, like a third party library. The all code analysis commands in this project ignore files and directories listed in the thirdpartylibs.xml plugin file. See https://docs.moodle.org/dev/Plugin_files#thirdpartylibs.xml for more info.

Ignoring files

Specifically for the codechecker command, you can ignore a single line, a section of a file or the whole file by using specific PHP comments. For details see this CodeSniffer wiki page. In addition, you can ignore additional files by defining IGNORE_PATHS and/or IGNORE_NAMES environment variables in your .travis.yml file. These environment variables wont work for Grunt tasks, but will for everything else. Example: env:

global:
 - MOODLE_BRANCH=MOODLE_35_STABLE
 - IGNORE_PATHS=vendor/widget,javascript/min-lib.js
 - IGNORE_NAMES=*-m.js,bad_lib.php
matrix:
 - DB=pgsql
 - DB=mysqli

Both environment variables take a CSV value. For IGNORE_PATHS, it takes relative file paths to ignore. File paths can be a simple string like foo/bar or a regular expression like /^foo\/bar/. For IGNORE_NAMES, it takes file names to ignore. File names can be a simple string like foo.php, a glob like *.php or a regular expression like /\.php$/.

If you need to specify ignore paths for a specific command, then you can define additional environment variables. The variable names are the same as above, but prefixed with COMMANDNAME_. Example:

env:

global:
 - MOODLE_BRANCH=MOODLE_35_STABLE
 - IGNORE_PATHS=vendor/widget,javascript/min-lib.js
 - IGNORE_NAMES=*-m.js,bad_lib.php
 - PHPUNIT_IGNORE_PATHS=$IGNORE_PATHS,cli
matrix:
 - DB=pgsql
 - DB=mysqli

In the above example, we are adding the cli path to our ignore paths for the PHPUnit command (this is also how you can ignore files for code coverage). Please note that this is a complete override and there is no merging with IGNORE_PATHS and IGNORE_NAMES. So, in the above, the PHPUnit command would not ignore the file names defined in IGNORE_NAMES.


See also