Moodle release 3.8.9
[moodle.git] / .travis.yml
blobc3267adc065a52f681c21d6ee709784589fbac54
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 notifications:
6   email:
7     if: env(MOODLE_EMAIL) != no
9 language: php
11 os: linux
13 dist: xenial
15 services:
16     - mysql
17     - docker
19 addons:
20   postgresql: "9.6"
22 jobs:
23     # Enable fast finish.
24     # This will fail the build if a single job fails (except those in allow_failures).
25     # It will not stop the jobs from running.
26     fast_finish: true
28     include:
29         # First all the lowest php ones (7.1.30)
30         # Make this sticky because current default version (7.1.11) has a bug with redis-extension output (MDL-66062)
31         - php: 7.1.30
32           env: DB=none     TASK=CITEST
33         - php: 7.1.30
34           env: DB=none     TASK=GRUNT    NVM_VERSION='lts/carbon'
36         - if: env(MOODLE_DATABASE) = "pgsql" OR env(MOODLE_DATABASE) = "all" OR env(MOODLE_DATABASE) IS NOT present
37           php: 7.1.30
38           env: DB=pgsql    TASK=PHPUNIT
40         - if: env(MOODLE_DATABASE) = "mysqli" OR env(MOODLE_DATABASE) = "all"
41           php: 7.1.30
42           env: DB=mysqli   TASK=PHPUNIT
44         # Then, conditionally, all the highest php ones (7.4)
45         - if: env(MOODLE_PHP) = "all"
46           php: 7.4
47           env: DB=none     TASK=CITEST
48         - if: env(MOODLE_PHP) = "all"
49           php: 7.4
50           env: DB=none     TASK=GRUNT    NVM_VERSION='lts/carbon'
52         - if: env(MOODLE_PHP) = "all" AND (env(MOODLE_DATABASE) = "pgsql" OR env(MOODLE_DATABASE) = "all" OR env(MOODLE_DATABASE) IS NOT present)
53           php: 7.4
54           env: DB=pgsql    TASK=PHPUNIT
56         - if: env(MOODLE_PHP) = "all" AND (env(MOODLE_DATABASE) = "mysqli" OR env(MOODLE_DATABASE) = "all")
57           php: 7.4
58           env: DB=mysqli   TASK=PHPUNIT
60 cache:
61     directories:
62       - $HOME/.composer/cache
63       - $HOME/.npm
65 before_install:
66     - docker run -d -p 127.0.0.1:8080:80 --name exttests moodlehq/moodle-exttests
67     # Avoid IPv6 default binding as service (causes redis not to start).
68     - sudo service redis-server start --bind 127.0.0.1
70 install:
71     - >
72         if [ "$DB" = 'mysqli' ];
73         then
74             sudo mkdir /mnt/ramdisk
75             sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
76             sudo service mysql stop
77             sudo mv /var/lib/mysql /mnt/ramdisk
78             sudo ln -s /mnt/ramdisk/mysql /var/lib/mysql
79             sudo service mysql restart
80         fi
81     - >
82         if [ "$DB" = 'pgsql' ];
83         then
84             sudo mkdir /mnt/ramdisk
85             sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
86             sudo service postgresql stop
87             sudo mv /var/lib/postgresql /mnt/ramdisk
88             sudo ln -s /mnt/ramdisk/postgresql /var/lib/postgresql
89             sudo service postgresql start 9.6
90         fi
91     - >
92         if [ "$TASK" = 'PHPUNIT' ];
93         then
94             if [ -n "$GITHUB_APITOKEN" ]; then
95                 composer config github-oauth.github.com $GITHUB_APITOKEN;
96                 echo 'auth.json' >> .git/info/exclude
97             fi
99             echo 'extension="redis.so"' > /tmp/redis.ini
100             phpenv config-add /tmp/redis.ini
102             # Install composer dependencies.
103             # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
104             # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
105             travis_retry composer install --prefer-dist --no-interaction;
106         fi
108     - >
109         if [ "$TASK" = 'GRUNT' ];
110         then
111             nvm install $NVM_VERSION ;
112             nvm use $NVM_VERSION ;
113         fi
115 before_script:
116     - phpenv config-rm xdebug.ini
117     - >
118       if [ "$TASK" = 'PHPUNIT' ];
119       then
120         # Copy generic configuration in place.
121         cp config-dist.php config.php ;
123         # Create the moodledata directory.
124         mkdir -p "$HOME"/roots/base
126         # The database name and password.
127         sed -i \
128           -e "s%= 'moodle'%= 'travis_ci_test'%" \
129           -e "s%= 'password'%= ''%" \
130           config.php ;
132         # The wwwroot and dataroot.
133         sed -i \
134           -e "s%http://example.com/moodle%https://localhost%" \
135           -e "s%/home/example/moodledata%/home/travis/roots/base%" \
136           config.php ;
138         if [ "$DB" = 'pgsql' ];
139         then
140           # Postgres-specific setup.
141           sed -i \
142             -e "s%= 'username'%= 'postgres'%" \
143             config.php ;
145           psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
146         fi
148         if [ "$DB" = 'mysqli' ];
149         then
150           # MySQL-specific setup.
151           sed -i \
152             -e "s%= 'pgsql'%= 'mysqli'%" \
153             -e "s%= 'username'%= 'travis'%" \
154             -e "s%=> 'utf8mb4_unicode_ci'%=> 'utf8mb4_bin'%" \
155             config.php;
157           mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
158           mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
159           mysql -u root -e 'SET GLOBAL innodb_large_prefix=ON;' ;
160           mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_bin;' ;
161         fi
162       fi
164     - >
165       if [ "$TASK" = 'PHPUNIT' ];
166       then
167         # Create a directory for the phpunit dataroot.
168         mkdir -p "$HOME"/roots/phpunit
170         # The phpunit dataroot and prefix..
171         sed -i \
172           -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
173           -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
174           config.php ;
175         # Enable test external resources
176         sed -i \
177           -e "/require_once/i \\define('TEST_EXTERNAL_FILES_HTTP_URL', 'http://127.0.0.1:8080');" \
178           -e "/require_once/i \\define('TEST_EXTERNAL_FILES_HTTPS_URL', 'http://127.0.0.1:8080');" \
179           config.php ;
181         # Redis cache store tests
182         sed -i \
183           -e "/require_once/i \\define('TEST_CACHESTORE_REDIS_TESTSERVERS', '127.0.0.1');" \
184           config.php ;
185         # Redis session tests, but not for PHP 7.2 and up. See MDL-60978 for more info.
186         redissession="define('TEST_SESSION_REDIS_HOST', '127.0.0.1');"
187         sed -i \
188           -e "/require_once/i \\${redissession}" \
189           config.php ;
191         # Initialise PHPUnit for Moodle.
192         php admin/tool/phpunit/cli/init.php
193       fi
195     - >
196       if [ "$TASK" = 'GRUNT' ];
197       then
198         npm install --no-spin;
199         npm install --no-spin -g grunt ;
200       fi
202     ########################################################################
203     # CI Tests
204     ########################################################################
205     - >
206       if [ "$TASK" = 'CITEST' ];
207       then
208         # Note - this is deliberately placed in the script section as we
209         # should not add any code until after phpunit has run.
211         # The following repositories are required.
212         # The local_ci repository does the actual checking.
213         git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
215         # We need the official upstream for comparison
216         git remote add upstream https://github.com/moodle/moodle.git;
218         git fetch upstream MOODLE_38_STABLE;
219         export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
220         export GIT_COMMIT="$TRAVIS_COMMIT";
221         export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
223         # Variables required by our linter.
224         export gitcmd=`which git`;
225         export gitdir="$TRAVIS_BUILD_DIR";
226         export phpcmd=`which php`;
227       fi
229 script:
230     - >
231       if [ "$TASK" = 'PHPUNIT' ];
232       then
233         vendor/bin/phpunit --fail-on-risky --disallow-test-output --verbose;
234       fi
236     - >
237       if [ "$TASK" = 'CITEST' ];
238       then
239         bash local/ci/php_lint/php_lint.sh;
240       fi
242     - >
243       if [ "$TASK" = 'GRUNT' ];
244       then
245         grunt ;
246         # Add all files to the git index and then run diff --cached to see all changes.
247         # This ensures that we get the status of all files, including new files.
248         # We ignore npm-shrinkwrap.json to make the tasks immune to npm changes.
249         git add . ;
250         git reset -- npm-shrinkwrap.json ;
251         git diff --cached --exit-code ;
252       fi
254 after_script:
255     - >
256       if [ "$TASK" = 'PHPUNIT' ];
257       then
258         EXTTESTS_HITS=$(docker logs exttests 2>&1 | grep -Fv -e 'AH00558' -e '[pid 1]' | wc -l)
259         echo -e "\nTest local resources number of hits: ${EXTTESTS_HITS}.\n"
260       fi