MDL-57268 auth_db: Unit tests for deletion from a large user set
[moodle.git] / .travis.yml
blob59dd90881d0d37a39c6236c47f5c86f2b03bae36
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: false
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 services:
20     - redis-server
22 env:
23     # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
24     # start first so that the total run time is not too high.
25     #
26     # We only run MySQL on PHP 7.1, so run that first.
27     # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
28     # Postgres is significantly is pretty reasonable in its run-time.
30     # Run unit tests on MySQL
31     - DB=mysqli   TASK=PHPUNIT
33     # Run CI Tests without running PHPUnit.
34     - DB=none     TASK=CITEST
36     # Run unit tests on Postgres
37     - DB=pgsql    TASK=PHPUNIT
39     # Perform an upgrade test too.
40     - DB=pgsql    TASK=UPGRADE
42 matrix:
43     # Enable fast finish.
44     # This will fail the build if a single job fails (except those in allow_failures).
45     # It will not stop the jobs from running.
46     fast_finish: true
48     include:
49           # Run grunt/npm install on lowest supported npm version
50         - php: 7.1
51           env: DB=none     TASK=GRUNT   NVM_VERSION='4'
52           # Run grunt/npm install on highest version ('node' is an alias for the latest node.js version.)
53         - php: 7.1
54           env: DB=none     TASK=GRUNT   NVM_VERSION='node'
56     exclude:
57         # MySQL - it's just too slow.
58         # Exclude it on all versions except for 7.1
60         - env: DB=mysqli   TASK=PHPUNIT
61           php: 5.6
63         # Moodle 2.7 is not compatible with PHP 7 for the upgrade test.
64         - env: DB=pgsql    TASK=UPGRADE
65           php: 7.1
67 cache:
68     directories:
69       - $HOME/.composer/cache
70       - $HOME/.npm
72 install:
73     - >
74         if [ "$TASK" = 'PHPUNIT' ];
75         then
76             if [ -n "$GITHUB_APITOKEN" ]; then
77                 composer config github-oauth.github.com $GITHUB_APITOKEN;
78                 echo 'auth.json' >> .git/info/exclude
79             fi
81             # Enable Redis.
82             echo 'extension="redis.so"' > /tmp/redis.ini
83             phpenv config-add /tmp/redis.ini
85             # Install composer dependencies.
86             # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
87             # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
88             travis_retry composer install --prefer-dist --no-interaction;
89         fi
91     - >
92         if [ "$TASK" = 'GRUNT' ];
93         then
94             nvm install $NVM_VERSION ;
95             nvm use $NVM_VERSION ;
96         fi
98 before_script:
99     - phpenv config-rm xdebug.ini
100     - >
101       if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
102       then
103         # Copy generic configuration in place.
104         cp config-dist.php config.php ;
106         # Create the moodledata directory.
107         mkdir -p "$HOME"/roots/base
109         # The database name and password.
110         sed -i \
111           -e "s%= 'moodle'%= 'travis_ci_test'%" \
112           -e "s%= 'password'%= ''%" \
113           config.php ;
115         # The wwwroot and dataroot.
116         sed -i \
117           -e "s%http://example.com/moodle%http://localhost%" \
118           -e "s%/home/example/moodledata%/home/travis/roots/base%" \
119           config.php ;
121         if [ "$DB" = 'pgsql' ];
122         then
123           # Postgres-specific setup.
124           sed -i \
125             -e "s%= 'username'%= 'postgres'%" \
126             config.php ;
128           psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
129         fi
131         if [ "$DB" = 'mysqli' ];
132         then
133           # MySQL-specific setup.
134           sed -i \
135             -e "s%= 'pgsql'%= 'mysqli'%" \
136             -e "s%= 'username'%= 'travis'%" \
137             config.php;
139           mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
140           mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
141           mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;
142         fi
143       fi
145     - >
146       if [ "$TASK" = 'PHPUNIT' ];
147       then
148         # Create a directory for the phpunit dataroot.
149         mkdir -p "$HOME"/roots/phpunit
151         # The phpunit dataroot and prefix..
152         sed -i \
153           -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
154           -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
155           -e "/require_once/i \\define('TEST_SESSION_REDIS_HOST', '127.0.0.1');" \
156           config.php ;
158         # Initialise PHPUnit for Moodle.
159         php admin/tool/phpunit/cli/init.php
160       fi
162     - >
163       if [ "$TASK" = 'GRUNT' ];
164       then
165         npm install --no-spin;
166         npm install --no-spin -g grunt ;
167       fi
169     ########################################################################
170     # CI Tests
171     ########################################################################
172     - >
173       if [ "$TASK" = 'CITEST' ];
174       then
175         # Note - this is deliberately placed in the script section as we
176         # should not add any code until after phpunit has run.
178         # The following repositories are required.
179         # The local_ci repository does the actual checking.
180         git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
182         # We need the official upstream for comparison
183         git remote add upstream https://github.com/moodle/moodle.git;
185         git fetch upstream MOODLE_32_STABLE;
186         export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
187         export GIT_COMMIT="$TRAVIS_COMMIT";
188         export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
190         # Variables required by our linter.
191         export gitcmd=`which git`;
192         export gitdir="$TRAVIS_BUILD_DIR";
193         export phpcmd=`which php`;
194       fi
196     ########################################################################
197     # Upgrade test
198     ########################################################################
199     - >
200       if [ "$TASK" = 'UPGRADE' ];
201       then
202         # We need the official upstream.
203         git remote add upstream https://github.com/moodle/moodle.git;
205         # Checkout 27 STABLE branch.
206         git fetch upstream MOODLE_27_STABLE;
207         git checkout MOODLE_27_STABLE;
209         # Perform the upgrade
210         php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
212         # Return to the previous commit
213         git checkout -;
215         # Perform the upgrade
216         php admin/cli/upgrade.php --non-interactive --allow-unstable ;
218         # The local_ci repository can be used to check upgrade savepoints.
219         git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
220       fi
222 script:
223     - >
224       if [ "$TASK" = 'PHPUNIT' ];
225       then
226         vendor/bin/phpunit;
227       fi
229     - >
230       if [ "$TASK" = 'CITEST' ];
231       then
232         bash local/ci/php_lint/php_lint.sh;
233       fi
235     - >
236       if [ "$TASK" = 'GRUNT' ];
237       then
238         grunt ;
239         # Add all files to the git index and then run diff --cached to see all changes.
240         # This ensures that we get the status of all files, including new files.
241         git add . ;
242         git diff --cached --exit-code ;
243       fi
245     ########################################################################
246     # Upgrade test
247     ########################################################################
248     - >
249       if [ "$TASK" = 'UPGRADE' ];
250       then
251         cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
252         result=`php check_upgrade_savepoints.php`;
253         # Check if there are problems
254         count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;
255         if (($count > 0));
256         then
257           echo "$result"
258           exit 1 ;
259         fi
260       fi