Note:

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

Talk:Travis integration: Difference between revisions

From MoodleDocs
m (Text replacement - "</code>" to "</syntaxhighlight>")
 
(10 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{Note|This page contains previous Travis dev docs. Please move relevant content to [[Travis Integration]] then this page can be deleted.}}
[https://travis-ci.org Travis-ci] is a continuous integration server.
= Moodle core =
= Moodle core =
An example on how to run the full Moodle phpunit tests ([https://github.com/ds125v/moodle-travis/blob/master/.travis.yml the original file]):
 
<code bash>
Moodle 3.0 comes bundled with a [https://github.com/moodle/moodle/blob/master/.travis.yml .travis.yml file] which executes Moodle's unit tests suite and PHP lint. More checkings might be added in future.
 
For previous Moodle versions you can either use Moodle 3.0 .travis.yml file (you will probably have to adapt it) or use the following example ([https://github.com/ds125v/moodle-travis/blob/master/.travis.yml]) Signup on Travis, put the .travis.yml file into your repository, link the repository to Travis and Travis will run all your phpunit tests each time you push to your repository.
 
<syntaxhighlight lang="bash">
language: php
language: php
php:
php:
Line 22: Line 30:
  - mkdir -m777 $HOME/moodledata
  - mkdir -m777 $HOME/moodledata
  - php admin/tool/phpunit/cli/init.php
  - php admin/tool/phpunit/cli/init.php
</code>
</syntaxhighlight>


= Moodle plugins =
= Moodle plugins =
An example on how to run phpunit/behat tests on travis for a Moodle plugin (here the plugin is the [https://github.com/mouneyrac/moodle-auth_googleoauth2/blob/master/.travis.yml Oauth2 authentication plugin]):
An example on how to run phpunit/behat tests on travis for a Moodle plugin (here the plugin is the [https://github.com/mouneyrac/moodle-auth_googleoauth2/blob/master/.travis.yml Oauth2 authentication plugin]):
<code bash>
<syntaxhighlight lang="bash">
before_install:
before_install:
   - "export DISPLAY=:99.0"
   - "export DISPLAY=:99.0"
Line 59: Line 67:
  - mkdir -m777 $HOME/moodledata
  - mkdir -m777 $HOME/moodledata
  - php admin/tool/phpunit/cli/init.php
  - php admin/tool/phpunit/cli/init.php
  - "php -S localhost:8000 > /dev/null &"
  - "(php -S localhost:8000 &) 2> /dev/null > /dev/null"
  - "wget http://selenium.googlecode.com/files/selenium-server-standalone-2.31.0.jar"
  - "wget http://selenium.googlecode.com/files/selenium-server-standalone-2.31.0.jar"
  - "java -jar selenium-server-standalone-2.31.0.jar > /dev/null &"
  - "(java -jar selenium-server-standalone-2.31.0.jar &) 2> /dev/null > /dev/null"
  - php admin/tool/behat/cli/init.php
  - php admin/tool/behat/cli/init.php
script:
script:
  - if [ '$MOODLE_VERSION' = 'master' ]; then
  - if [ $MOODLE_VERSION = 'master' ]; then vendor/bin/behat --config /home/travis/bht_moodledata/behat/behat.yml --tags @auth_googleoauth2; fi
- vendor/bin/behat --config /home/travis/bht_moodledata/behat/behat.yml --tags @auth_googleoauth2
- fi
  - phpunit auth_googleoauth2_lib_testcase auth/googleoauth2/tests/lib_test.php
  - phpunit auth_googleoauth2_lib_testcase auth/googleoauth2/tests/lib_test.php
</code>
</syntaxhighlight>


= See also =
= See also =
[https://moodle.org/mod/forum/discuss.php?d=215998 The forum post with the original examples] from David Scotson and Jerome Mouneyrac.
[https://moodle.org/mod/forum/discuss.php?d=215998 The forum post with the original examples] from David Scotson and Jerome Mouneyrac.

Latest revision as of 20:27, 14 July 2021

Note: This page contains previous Travis dev docs. Please move relevant content to Travis Integration then this page can be deleted.


Travis-ci is a continuous integration server.

Moodle core

Moodle 3.0 comes bundled with a .travis.yml file which executes Moodle's unit tests suite and PHP lint. More checkings might be added in future.

For previous Moodle versions you can either use Moodle 3.0 .travis.yml file (you will probably have to adapt it) or use the following example ([1]) Signup on Travis, put the .travis.yml file into your repository, link the repository to Travis and Travis will run all your phpunit tests each time you push to your repository.

language: php
php:
  - "5.4"
  - "5.3"
env:
 - DB=mysqli
 - DB=pgsql
before_script:
 - pear channel-discover pear.phpunit.de
 - pear channel-discover pear.symfony.com
 - pear install pear.phpunit.de/DbUnit
 - phpenv rehash
 - cp config-dist.php config.php
 - sh -c "sed -i -e s/'password'/''/ -e s/example.com/localhost/ -e s%/home/example%$HOME% -e 's%\(\$CFG.*phpu\)%\n\1%' config.php"
 - sh -c "if [ '$DB' = 'mysqli' ]; then mysql -e 'create database moodle default character set UTF8 collate UTF8_bin;'; fi"
 - sh -c "if [ '$DB' = 'mysqli' ]; then sed -i -e s/\'pgsql\'/\'mysqli\'/ -e s/\'username\'/\'root\'/ config.php; fi"
 - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'create database moodle;' -U postgres; fi"
 - sh -c "if [ '$DB' = 'pgsql' ]; then sed -i s/\'username\'/\'postgres\'/ config.php; fi"
 - mkdir -m777 $HOME/moodledata
 - php admin/tool/phpunit/cli/init.php

Moodle plugins

An example on how to run phpunit/behat tests on travis for a Moodle plugin (here the plugin is the Oauth2 authentication plugin):

before_install:
  - "export DISPLAY=:99.0"
  - "sh -e /etc/init.d/xvfb start"
language: php
php:
  - "5.4"
env:
 - DB=mysqli MOODLE_VERSION=MOODLE_25_STABLE
 - DB=mysqli MOODLE_VERSION=master
 - DB=pgsql MOODLE_VERSION=MOODLE_25_STABLE
 - DB=pgsql MOODLE_VERSION=master
before_script:
 - git clone git://github.com/moodle/moodle ../moodle && cd ../moodle
 - git checkout $MOODLE_VERSION
 - sudo apt-get update > /dev/null
 - composer self-update
 - composer install --dev --prefer-dist
 - mv ../moodle-auth_googleoauth2 auth/googleoauth2
 - git clone git://github.com/mouneyrac/moodle-theme_easy theme/oauth2easy
 - pear channel-discover pear.phpunit.de
 - pear channel-discover pear.symfony.com
 - pear install pear.phpunit.de/DbUnit
 - phpenv rehash
 - cp config-dist.php config.php
 - sh -c "sed -i -e s/'password'/''/ -e s/example.com/localhost/ -e s%/home/example%$HOME% -e 's%\(\$CFG.*phpu\)%\n\1%' config.php"
 - sh -c "sed -i -e s/'password'/''/ -e s/example.com/localhost/ -e s%/home/example%$HOME% -e 's%\(\$CFG.*bht\)%\n\1%' config.php"
 - sh -c "if [ '$DB' = 'mysqli' ]; then mysql -e 'create database moodle default character set UTF8 collate UTF8_bin;'; fi"
 - sh -c "if [ '$DB' = 'mysqli' ]; then sed -i -e s/\'pgsql\'/\'mysqli\'/ -e s/\'username\'/\'root\'/ config.php; fi"
 - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'create database moodle;' -U postgres; fi"
 - sh -c "if [ '$DB' = 'pgsql' ]; then sed -i s/\'username\'/\'postgres\'/ config.php; fi"
 - mkdir -m777 $HOME/moodledata
 - php admin/tool/phpunit/cli/init.php
 - "(php -S localhost:8000 &) 2> /dev/null > /dev/null"
 - "wget http://selenium.googlecode.com/files/selenium-server-standalone-2.31.0.jar"
 - "(java -jar selenium-server-standalone-2.31.0.jar &) 2> /dev/null > /dev/null"
 - php admin/tool/behat/cli/init.php
script:
 - if [ $MOODLE_VERSION = 'master' ]; then vendor/bin/behat --config /home/travis/bht_moodledata/behat/behat.yml --tags @auth_googleoauth2; fi
 - phpunit auth_googleoauth2_lib_testcase auth/googleoauth2/tests/lib_test.php

See also

The forum post with the original examples from David Scotson and Jerome Mouneyrac.