weekly back-to-dev release 3.2dev
[moodle.git] / .travis.yml
CommitLineData
cf84a5d2
DP
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.
4
88ec0860
AN
5sudo: false
6
ab17b4f7
AN
7# We currently disable Travis notifications entirely until https://github.com/travis-ci/travis-ci/issues/4976
8# is fixed.
9notifications:
10 email: false
11
88ec0860
AN
12language: php
13
14php:
87b7314a
DP
15 # We only run the highest and lowest supported versions to reduce the load on travis-ci.org.
16 - 7.0
17 # - 5.6
88ec0860
AN
18 # - 5.5
19 - 5.4
20
88ec0860
AN
21env:
22 # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
23 # start first so that the total run time is not too high.
24 #
25 # We only run MySQL on PHP 5.6, so run that first.
26 # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
27 # Postgres is significantly is pretty reasonable in its run-time.
28
29 # Run unit tests on MySQL
30 - DB=mysqli PHPUNIT=true INSTALL=false CITEST=false
31
32 # Run CI Tests without running PHPUnit.
33 - DB=none PHPUNIT=false INSTALL=false CITEST=true
34
35 # Run unit tests on Postgres
36 - DB=pgsql PHPUNIT=true INSTALL=false CITEST=false
37
95b3ad67
AN
38 # Perform an upgrade test too.
39 - DB=pgsql PHPUNIT=false INSTALL=true CITEST=false UPGRADE=true
40
88ec0860
AN
41matrix:
42 # Enable fast finish.
43 # This will fail the build if a single job fails (except those in allow_failures).
44 # It will not stop the jobs from running.
45 fast_finish: true
46
88ec0860 47 exclude:
88ec0860 48 # MySQL - it's just too slow.
87b7314a
DP
49 # Exclude it on all versions except for 7.0
50 # - env: DB=mysqli PHPUNIT=true INSTALL=false CITEST=false
51 # php: 5.6
52 #
88ec0860
AN
53 # - env: DB=mysqli PHPUNIT=true INSTALL=false CITEST=false
54 # php: 5.5
55
56 - env: DB=mysqli PHPUNIT=true INSTALL=false CITEST=false
57 php: 5.4
58
95b3ad67
AN
59 # Moodle 2.7 is not compatible with PHP 7 for the upgrade test.
60 - env: DB=pgsql PHPUNIT=false INSTALL=true CITEST=false UPGRADE=true
61 php: 7.0
62
88ec0860
AN
63cache:
64 directories:
65 - $HOME/.composer/cache
66
67install:
eb474609
AN
68 # Disable xdebug. We aren't generating code coverage, and it has a huge impact upon test performance.
69 - rm /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
70
88ec0860
AN
71 # Set the encrypted GITHUB_TOKEN if it's available to raise the API limit.
72 - if [ -n "$GITHUB_APITOKEN" ]; then composer config github-oauth.github.com $GITHUB_APITOKEN; fi
73
74 # Install composer dependencies.
75 # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
76 # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
77 - travis_retry composer install --prefer-dist --no-interaction
78
79before_script:
80 - >
81 if [ "$INSTALL" = 'true' -o "$PHPUNIT" = 'true' ];
82 then
83 # Copy generic configuration in place.
84 cp config-dist.php config.php ;
85
86 # Create the moodledata directory.
87 mkdir -p "$HOME"/roots/base
88
89 # The database name and password.
90 sed -i \
91 -e "s%= 'moodle'%= 'travis_ci_test'%" \
92 -e "s%= 'password'%= ''%" \
93 config.php ;
94
95 # The wwwroot and dataroot.
96 sed -i \
97 -e "s%http://example.com/moodle%http://localhost%" \
98 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
99 config.php ;
100
101 if [ "$DB" = 'pgsql' ];
102 then
103 # Postgres-specific setup.
104 sed -i \
105 -e "s%= 'username'%= 'postgres'%" \
106 config.php ;
107
108 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
109 fi
110
111 if [ "$DB" = 'mysqli' ];
112 then
113 # MySQL-specific setup.
114 sed -i \
115 -e "s%= 'pgsql'%= 'mysqli'%" \
116 -e "s%= 'username'%= 'travis'%" \
117 config.php;
118
119 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
120 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
121 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;
122 fi
123
124 if [ "$PHPUNIT" = 'true' ];
125 then
126 # Create a directory for the phpunit dataroot.
127 mkdir -p "$HOME"/roots/phpunit
128
129 # The phpunit dataroot and prefix..
130 sed -i \
131 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
132 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
133 config.php ;
134
135 # Initialise PHPUnit for Moodle.
136 php admin/tool/phpunit/cli/init.php
137 fi
138 fi
139
140script:
141 ########################################################################
142 # PHPUnit
143 ########################################################################
144 - >
145 if [ "$PHPUNIT" = 'true' ];
146 then
147 vendor/bin/phpunit;
148 fi
149
150 ########################################################################
151 # CI Tests
152 ########################################################################
153 - >
154 if [ "$CITEST" = 'true' ];
155 then
156 # Note - this is deliberately placed in the script section as we
157 # should not add any code until after phpunit has run.
158
159 # The following repositories are required.
160 # The local_ci repository does the actual checking.
161 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
162
88ec0860
AN
163 # We need the official upstream for comparison
164 git remote add upstream https://github.com/moodle/moodle.git;
5459e754 165
b2e859bc 166 git fetch upstream master;
88ec0860
AN
167 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
168 export GIT_COMMIT="$TRAVIS_COMMIT";
169 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
170
171 # Variables required by our linter.
172 export gitcmd=`which git`;
173 export gitdir="$TRAVIS_BUILD_DIR";
174 export phpcmd=`which php`;
175 fi
176
88ec0860
AN
177 # Actually run the CI Tests - do this outside of the main test to make output clearer.
178 - >
179 if [ "$CITEST" = 'true' ];
180 then
181 bash local/ci/php_lint/php_lint.sh;
182 fi
95b3ad67
AN
183
184 ########################################################################
185 # Upgrade test
186 ########################################################################
187 - >
188 if [ "$UPGRADE" = 'true' ];
189 then
190 # We need the official upstream.
191 git remote add upstream https://github.com/moodle/moodle.git;
192
193 # Checkout 27 STABLE branch.
194 git fetch upstream MOODLE_27_STABLE;
195 git checkout MOODLE_27_STABLE;
196
197 # Perform the upgrade
198 php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
199
200 # Return to the previous commit
201 git checkout -;
202
203 # Perform the upgrade
204 php admin/cli/upgrade.php --non-interactive --allow-unstable ;
205
206 # The local_ci repository can be used to check upgrade savepoints.
207 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
208
209 cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
210 result=`php check_upgrade_savepoints.php`;
211 # Check if there are problems
212 count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;
213 if (($count > 0));
214 then
215 echo "$result"
216 exit 1 ;
217 fi
218 fi