weekly release 3.4dev
[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 15 # We only run the highest and lowest supported versions to reduce the load on travis-ci.org.
3720bd7d 16 - 7.1
9f29c651 17 - 5.6
88ec0860 18
6e6a768c
EL
19addons:
20 postgresql: "9.3"
21
8ad2afd3
AN
22services:
23 - redis-server
24
88ec0860
AN
25env:
26 # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
27 # start first so that the total run time is not too high.
28 #
3720bd7d 29 # We only run MySQL on PHP 7.1, so run that first.
88ec0860
AN
30 # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
31 # Postgres is significantly is pretty reasonable in its run-time.
32
33 # Run unit tests on MySQL
a24aff4e 34 - DB=mysqli TASK=PHPUNIT
88ec0860
AN
35
36 # Run CI Tests without running PHPUnit.
a24aff4e 37 - DB=none TASK=CITEST
88ec0860
AN
38
39 # Run unit tests on Postgres
a24aff4e 40 - DB=pgsql TASK=PHPUNIT
88ec0860 41
95b3ad67 42 # Perform an upgrade test too.
a24aff4e 43 - DB=pgsql TASK=UPGRADE
95b3ad67 44
88ec0860
AN
45matrix:
46 # Enable fast finish.
47 # This will fail the build if a single job fails (except those in allow_failures).
48 # It will not stop the jobs from running.
49 fast_finish: true
50
7402479c
DP
51 include:
52 # Run grunt/npm install on lowest supported npm version
3720bd7d 53 - php: 7.1
7402479c
DP
54 env: DB=none TASK=GRUNT NVM_VERSION='4'
55 # Run grunt/npm install on highest version ('node' is an alias for the latest node.js version.)
3720bd7d 56 - php: 7.1
7402479c
DP
57 env: DB=none TASK=GRUNT NVM_VERSION='node'
58
88ec0860 59 exclude:
88ec0860 60 # MySQL - it's just too slow.
3720bd7d 61 # Exclude it on all versions except for 7.1
88ec0860 62
a24aff4e 63 - env: DB=mysqli TASK=PHPUNIT
6981a039 64 php: 5.6
88ec0860 65
95b3ad67 66 # Moodle 2.7 is not compatible with PHP 7 for the upgrade test.
a24aff4e 67 - env: DB=pgsql TASK=UPGRADE
3720bd7d 68 php: 7.1
95b3ad67 69
88ec0860
AN
70cache:
71 directories:
72 - $HOME/.composer/cache
c366cb08 73 - $HOME/.npm
88ec0860
AN
74
75install:
7402479c
DP
76 - >
77 if [ "$TASK" = 'PHPUNIT' ];
78 then
79 if [ -n "$GITHUB_APITOKEN" ]; then
80 composer config github-oauth.github.com $GITHUB_APITOKEN;
81 echo 'auth.json' >> .git/info/exclude
82 fi
83
8ad2afd3
AN
84 # Enable Redis.
85 echo 'extension="redis.so"' > /tmp/redis.ini
86 phpenv config-add /tmp/redis.ini
87
7402479c
DP
88 # Install composer dependencies.
89 # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
90 # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
91 travis_retry composer install --prefer-dist --no-interaction;
92 fi
88ec0860 93
7402479c
DP
94 - >
95 if [ "$TASK" = 'GRUNT' ];
96 then
97 nvm install $NVM_VERSION ;
98 nvm use $NVM_VERSION ;
99 fi
88ec0860
AN
100
101before_script:
189d6ea8 102 - phpenv config-rm xdebug.ini
88ec0860 103 - >
a24aff4e 104 if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
88ec0860
AN
105 then
106 # Copy generic configuration in place.
107 cp config-dist.php config.php ;
108
109 # Create the moodledata directory.
110 mkdir -p "$HOME"/roots/base
111
112 # The database name and password.
113 sed -i \
114 -e "s%= 'moodle'%= 'travis_ci_test'%" \
115 -e "s%= 'password'%= ''%" \
116 config.php ;
117
118 # The wwwroot and dataroot.
119 sed -i \
6e6a768c 120 -e "s%http://example.com/moodle%https://localhost%" \
88ec0860
AN
121 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
122 config.php ;
123
124 if [ "$DB" = 'pgsql' ];
125 then
126 # Postgres-specific setup.
127 sed -i \
128 -e "s%= 'username'%= 'postgres'%" \
129 config.php ;
130
131 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
132 fi
133
134 if [ "$DB" = 'mysqli' ];
135 then
136 # MySQL-specific setup.
137 sed -i \
138 -e "s%= 'pgsql'%= 'mysqli'%" \
139 -e "s%= 'username'%= 'travis'%" \
0bbefd81 140 -e "s%=> 'utf8mb4_unicode_ci'%=> 'utf8mb4_bin'%" \
88ec0860
AN
141 config.php;
142
143 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
144 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
0bbefd81
AG
145 mysql -u root -e 'SET GLOBAL innodb_large_prefix=ON;' ;
146 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_bin;' ;
88ec0860 147 fi
88ec0860
AN
148 fi
149
88ec0860 150 - >
a24aff4e 151 if [ "$TASK" = 'PHPUNIT' ];
88ec0860 152 then
a24aff4e
AN
153 # Create a directory for the phpunit dataroot.
154 mkdir -p "$HOME"/roots/phpunit
155
156 # The phpunit dataroot and prefix..
157 sed -i \
158 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
159 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
8ad2afd3 160 -e "/require_once/i \\define('TEST_SESSION_REDIS_HOST', '127.0.0.1');" \
a24aff4e
AN
161 config.php ;
162
163 # Initialise PHPUnit for Moodle.
164 php admin/tool/phpunit/cli/init.php
88ec0860
AN
165 fi
166
c366cb08
AN
167 - >
168 if [ "$TASK" = 'GRUNT' ];
169 then
7402479c
DP
170 npm install --no-spin;
171 npm install --no-spin -g grunt ;
c366cb08
AN
172 fi
173
88ec0860
AN
174 ########################################################################
175 # CI Tests
176 ########################################################################
177 - >
a24aff4e 178 if [ "$TASK" = 'CITEST' ];
88ec0860
AN
179 then
180 # Note - this is deliberately placed in the script section as we
181 # should not add any code until after phpunit has run.
182
183 # The following repositories are required.
184 # The local_ci repository does the actual checking.
185 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
186
88ec0860
AN
187 # We need the official upstream for comparison
188 git remote add upstream https://github.com/moodle/moodle.git;
5459e754 189
8f568743 190 git fetch upstream master;
88ec0860
AN
191 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
192 export GIT_COMMIT="$TRAVIS_COMMIT";
193 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
194
195 # Variables required by our linter.
196 export gitcmd=`which git`;
197 export gitdir="$TRAVIS_BUILD_DIR";
198 export phpcmd=`which php`;
199 fi
200
95b3ad67
AN
201 ########################################################################
202 # Upgrade test
203 ########################################################################
204 - >
a24aff4e 205 if [ "$TASK" = 'UPGRADE' ];
95b3ad67
AN
206 then
207 # We need the official upstream.
208 git remote add upstream https://github.com/moodle/moodle.git;
209
210 # Checkout 27 STABLE branch.
211 git fetch upstream MOODLE_27_STABLE;
212 git checkout MOODLE_27_STABLE;
213
214 # Perform the upgrade
215 php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
216
217 # Return to the previous commit
218 git checkout -;
219
220 # Perform the upgrade
221 php admin/cli/upgrade.php --non-interactive --allow-unstable ;
222
223 # The local_ci repository can be used to check upgrade savepoints.
224 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
a24aff4e
AN
225 fi
226
227script:
228 - >
229 if [ "$TASK" = 'PHPUNIT' ];
230 then
231 vendor/bin/phpunit;
232 fi
233
234 - >
235 if [ "$TASK" = 'CITEST' ];
236 then
237 bash local/ci/php_lint/php_lint.sh;
238 fi
95b3ad67 239
c366cb08
AN
240 - >
241 if [ "$TASK" = 'GRUNT' ];
242 then
7402479c 243 grunt ;
c366cb08
AN
244 # Add all files to the git index and then run diff --cached to see all changes.
245 # This ensures that we get the status of all files, including new files.
246 git add . ;
247 git diff --cached --exit-code ;
248 fi
249
a24aff4e
AN
250 ########################################################################
251 # Upgrade test
252 ########################################################################
253 - >
254 if [ "$TASK" = 'UPGRADE' ];
255 then
95b3ad67
AN
256 cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
257 result=`php check_upgrade_savepoints.php`;
258 # Check if there are problems
259 count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;
260 if (($count > 0));
261 then
262 echo "$result"
263 exit 1 ;
264 fi
265 fi