Merge branch 'MDL-52983_29' of git://github.com/aolley/moodle into MOODLE_29_STABLE
[moodle.git] / .travis.yml
blob66ca648912d782f179ea980d79587db21342d81c
1 # PLEASE NOTE: Travis is not currently utilised by the Moodle core integration
2 # process (which uses our internal CI system) this file is here for the benefit
3 # of community developers git clones - see MDL-51458.
5 sudo: false
7 # We currently disable Travis notifications entirely until https://github.com/travis-ci/travis-ci/issues/4976
8 # is fixed.
9 notifications:
10   email: false
12 language: php
14 php:
15     # We only run the highest and lowest supported versions to reduce the load on travis-ci.org.
16     - 5.6
17     # - 5.5
18     - 5.4
20 env:
21     # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
22     # start first so that the total run time is not too high.
23     #
24     # We only run MySQL on PHP 5.6, so run that first.
25     # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
26     # Postgres is significantly is pretty reasonable in its run-time.
28     # Run unit tests on MySQL
29     - DB=mysqli   PHPUNIT=true    INSTALL=false   CITEST=false
31     # Run CI Tests without running PHPUnit.
32     - DB=none     PHPUNIT=false   INSTALL=false   CITEST=true
34     # Run unit tests on Postgres
35     - DB=pgsql    PHPUNIT=true    INSTALL=false   CITEST=false
37 matrix:
38     # Enable fast finish.
39     # This will fail the build if a single job fails (except those in allow_failures).
40     # It will not stop the jobs from running.
41     fast_finish: true
43     exclude:
44         # MySQL - it's just too slow.
45         # Exclude it on all versions except for latest.
46         # - env: DB=mysqli   PHPUNIT=true    INSTALL=false   CITEST=false
47         #   php: 5.6
48         #
49         # - env: DB=mysqli   PHPUNIT=true    INSTALL=false   CITEST=false
50         #   php: 5.5
52         - env: DB=mysqli   PHPUNIT=true    INSTALL=false   CITEST=false
53           php: 5.4
55 cache:
56     directories:
57       - $HOME/.composer/cache
59 install:
60     # Disable xdebug. We aren't generating code coverage, and it has a huge impact upon test performance.
61     - rm /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
63     # Set the encrypted GITHUB_TOKEN if it's available to raise the API limit.
64     - if [ -n "$GITHUB_APITOKEN" ]; then composer config github-oauth.github.com $GITHUB_APITOKEN; fi
66     # Install composer dependencies.
67     # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
68     # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
69     - travis_retry composer install --prefer-dist --no-interaction
71 before_script:
72     - >
73       if [ "$INSTALL" = 'true' -o "$PHPUNIT" = 'true' ];
74       then
75         # Copy generic configuration in place.
76         cp config-dist.php config.php ;
78         # Create the moodledata directory.
79         mkdir -p "$HOME"/roots/base
81         # The database name and password.
82         sed -i \
83           -e "s%= 'moodle'%= 'travis_ci_test'%" \
84           -e "s%= 'password'%= ''%" \
85           config.php ;
87         # The wwwroot and dataroot.
88         sed -i \
89           -e "s%http://example.com/moodle%http://localhost%" \
90           -e "s%/home/example/moodledata%/home/travis/roots/base%" \
91           config.php ;
93         if [ "$DB" = 'pgsql' ];
94         then
95           # Postgres-specific setup.
96           sed -i \
97             -e "s%= 'username'%= 'postgres'%" \
98             config.php ;
100           psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
101         fi
103         if [ "$DB" = 'mysqli' ];
104         then
105           # MySQL-specific setup.
106           sed -i \
107             -e "s%= 'pgsql'%= 'mysqli'%" \
108             -e "s%= 'username'%= 'travis'%" \
109             config.php;
111           mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
112           mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
113           mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;
114         fi
116         if [ "$PHPUNIT" = 'true' ];
117         then
118           # Create a directory for the phpunit dataroot.
119           mkdir -p "$HOME"/roots/phpunit
121           # The phpunit dataroot and prefix..
122           sed -i \
123             -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
124             -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
125             config.php ;
127           # Initialise PHPUnit for Moodle.
128           php admin/tool/phpunit/cli/init.php
129         fi
130       fi
132 script:
133     ########################################################################
134     # PHPUnit
135     ########################################################################
136     - >
137       if [ "$PHPUNIT" = 'true' ];
138       then
139         vendor/bin/phpunit;
140       fi
142     ########################################################################
143     # CI Tests
144     ########################################################################
145     - >
146       if [ "$CITEST" = 'true' ];
147       then
148         # Note - this is deliberately placed in the script section as we
149         # should not add any code until after phpunit has run.
151         # The following repositories are required.
152         # The local_ci repository does the actual checking.
153         git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
155         # We need the official upstream for comparison
156         git remote add upstream https://github.com/moodle/moodle.git;
158         git fetch upstream MOODLE_29_STABLE;
159         export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
160         export GIT_COMMIT="$TRAVIS_COMMIT";
161         export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
163         # Variables required by our linter.
164         export gitcmd=`which git`;
165         export gitdir="$TRAVIS_BUILD_DIR";
166         export phpcmd=`which php`;
167       fi
169     # Actually run the CI Tests - do this outside of the main test to make output clearer.
170     - >
171       if [ "$CITEST" = 'true' ];
172       then
173         bash local/ci/php_lint/php_lint.sh;
174       fi