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