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