/
travis-ci.sh
executable file
·275 lines (221 loc) · 7.63 KB
/
travis-ci.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/bin/bash
COMMAND=$1
BUILD_TOP=`dirname $TRAVIS_BUILD_DIR`
EXIT_VALUE=0
export PATH="$HOME/.composer/vendor/bin:$PATH"
export DISPLAY=:99.0
export CHROME_SANDBOX=/opt/google/chrome/chrome-sandbox
##
# SCRIPT COMMANDS
##
# system-install
#
# This is meant to setup the server on Travis-CI so that it can run the tests.
#
system_install() {
# Add the Google Chrome packages.
header Setting up APT
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update > /dev/null
# Increase PHP memory limit.
phpenv config-add wet-boew-drupal/scripts/travis.php.ini
# Create a database for our Drupal site.
if [[ "$DB" == "pgsql" ]]; then psql -c 'create database drupal_db;' -U postgres; fi
if [[ "$DB" == "mysql" ]]; then mysql -e 'create database IF NOT EXISTS drupal_db;'; fi
# Install the latest Drush 6.
header Installing Drush
composer global require --prefer-source --no-interaction drush/drush:6.*
drush dl -y drupalorg_drush-7.x-1.x-dev --destination=$HOME/.drush
drush cc drush
# Build Codebase
mkdir profiles
mv wet-boew-drupal wetkit
mv wetkit profiles/
mkdir drupal
mv profiles drupal/
# Build the current branch.
header Building WxT from current branch
cd drupal
drush make --yes profiles/wetkit/drupal-org-core.make --prepare-install
drush make --yes profiles/wetkit/drupal-org.make --no-core --contrib-destination=profiles/wetkit
mkdir sites/default/private
mkdir sites/default/private/files
mkdir sites/default/private/temp
# Build Behat dependencies
cd profiles/wetkit/modules/custom/wetkit_test/tests
composer install --prefer-source --no-interaction
cd ../../../../../../../
# Verify that all the .make files will work on Drupal.org.
header Verifying .make file
drush verify-makefile drupal/profiles/wetkit/drupal-org.make
find drupal/profiles/wetkit/modules -name \*.make -print0 | xargs -0 -n1 drush verify-makefile
find drupal/profiles/wetkit/themes -name \*.make ! -name libraries.make -print0 | xargs -0 -n1 drush verify-makefile
# Download an old version to test upgrading from.
if [[ "$UPGRADE" != none ]]; then
header Downloading WxT $UPGRADE
drush dl wetkit-$UPGRADE
fi
# Setup files
sudo chmod -R 777 drupal/sites/all
# Setup display for Selenium
header Starting X
sh -e /etc/init.d/xvfb start
sleep 5
# Get Chrome and ChromeDriver
header Installing Google Chrome
sudo apt-get install google-chrome-stable
wget http://chromedriver.storage.googleapis.com/2.9/chromedriver_linux64.zip
unzip -a chromedriver_linux64.zip
# Insane hack from jsdevel:
# https://github.com/jsdevel/travis-debugging/blob/master/shim.bash
# This allows chrome-sandbox to work in side of OpenVZ, because I can't
# figure out how to start chrome with --no-sandbox.
sudo rm -f $CHROME_SANDBOX
sudo wget https://googledrive.com/host/0B5VlNZ_Rvdw6NTJoZDBSVy1ZdkE -O $CHROME_SANDBOX
sudo chown root:root $CHROME_SANDBOX
sudo chmod 4755 $CHROME_SANDBOX
sudo md5sum $CHROME_SANDBOX
# Get Selenium
header Downloading Selenium
wget http://selenium-release.storage.googleapis.com/2.41/selenium-server-standalone-2.41.0.jar
# Disable sendmail
echo sendmail_path=`which true` >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
# Enable APC
if [[ $TRAVIS_PHP_VERSION < "5.5" ]]; then
echo "extension=apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
echo "apc.shm_size=256M" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
fi
# Increase the MySQL connection timeout on the PHP end.
echo "mysql.connect_timeout=3000" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
echo "default_socket_timeout=3000" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
# Increase the MySQL server timetout and packet size.
mysql -e "SET GLOBAL wait_timeout = 36000;"
mysql -e "SET GLOBAL max_allowed_packet = 33554432;"
}
# before_tests
#
# Setup Drupal to run the tests.
#
before_tests() {
# Do the site install (either the current revision or old for the upgrade).
header Installing Drupal
if [[ "$UPGRADE" == none ]]; then
cd drupal
else
cd wetkit-$UPGRADE
fi
if [[ "$DB" == "postgres" ]]; then
drush si wetkit wetkit_theme_selection_form.theme=wetkit_bootstrap install_configure_form.demo_content=TRUE --sites-subdir=default --db-url=pgsql://postgres:@127.0.0.1:5432/drupal_db --account-name=admin --account-pass=WetKit@2012 --site-mail=admin@example.com --site-name='Web Experience Toolkit' --yes;
fi
if [[ "$DB" == "mysql" ]]; then
drush si wetkit wetkit_theme_selection_form.theme=wetkit_bootstrap install_configure_form.demo_content=TRUE --sites-subdir=default --db-url=mysql://root:@127.0.0.1:3306/drupal_db --account-name=admin --account-pass=WetKit@2012 --site-mail=admin@example.com --site-name='Web Experience Toolkit' --yes;
fi
drush dis -y dblog
drush cc all
drush vset -y file_private_path "sites/default/private/files"
drush vset -y file_temporary_path "sites/default/private/temp"
# Switch to the WetKit platform built from Git (if we aren't there already).
cd ../drupal
# If we're an upgrade test, run the upgrade process.
if [[ "$UPGRADE" != none ]]; then
header Upgrading to latest version
cp -a ../wetkit-$UPGRADE/sites/default/* sites/default/ && drush updb --yes
drush cc all
fi
# Our tests depend on wetkit_test.
drush en -y wetkit_test
# Run the webserver
header Starting webserver
drush runserver --server=builtin 8888 > /dev/null 2>&1 &
echo $! > /tmp/web-server-pid
sleep 3
cd ..
# Run the selenium server
header Starting selenium
java -jar selenium-server-standalone-2.41.0.jar -Dwebdriver.chrome.driver=`pwd`/chromedriver > /dev/null 2>&1 &
echo $! > /tmp/selenium-server-pid
sleep 5
}
# before_tests
#
# Run the tests.
#
run_tests() {
header Running tests
# Make the Travis tests repos agnostic by injecting drupal_root with BEHAT_PARAMS
export BEHAT_PARAMS="extensions[Drupal\\DrupalExtension\\Extension][drupal][drupal_root]=$BUILD_TOP/drupal"
cd drupal/profiles/wetkit/modules/custom/wetkit_test/tests
# If this isn't an upgrade, we test if any features are overridden.
if [[ "$UPGRADE" == none ]]; then
run_test ../../../../scripts/check-overridden.sh
fi
# First, run all the tests in Firefox.
run_test ./bin/behat --config behat.travis.yml
# Then run some Chrome-only tests.
run_test ./bin/behat --config behat.travis.yml -p chrome
}
# after_tests
#
# Clean up after the tests.
#
after_tests() {
header Cleaning up after tests
WEB_SERVER_PID=`cat /tmp/webserver-server-pid`
SELENIUM_SERVER_PID=`cat /tmp/selenium-server-pid`
# Stop the servers we started
kill $WEB_SERVER_PID
kill $SELENIUM_SERVER_PID
}
##
# UTILITY FUNCTIONS:
##
# Prints a message about the section of the script.
header() {
set +xv
echo
echo "** $@"
echo
set -xv
}
# Sets the exit level to error.
set_error() {
EXIT_VALUE=1
}
# Runs a command and sets an error if it fails.
run_test() {
if ! $@; then
set_error
fi
}
# Runs a command showing all the lines executed
run_command() {
set -xv
$@
set +xv
}
##
# SCRIPT MAIN:
##
# Capture all errors and set our overall exit value.
trap 'set_error' ERR
# We want to always start from the same directory:
cd $BUILD_TOP
case $COMMAND in
system-install)
run_command system_install
;;
drupal-install)
run_command drupal_install
;;
before-tests)
run_command before_tests
;;
run-tests)
run_command run_tests
;;
after-tests)
run_command after_tests
;;
esac
exit $EXIT_VALUE