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