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