-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.travis.yml
144 lines (110 loc) · 6.2 KB
/
.travis.yml
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
sudo: required
language: php
notifications:
email: false
php:
- '7.0'
services:
# Require docker and docker-compose as we'll need them to manage the containers.
- docker
addons:
apt:
packages:
- libjpeg-dev
- libpng12-dev
# Disable the default submodule logic.
git:
submodules: false
cache:
directories:
# The composer user-level cache.
- $HOME/.composer/cache
before_install:
# Sourcing the .env file will make sure we use, in the environment configuration, the same variables the tests are using.
- set -o allexport; source .env; set +o allexport;
# Spin up the `db` container from the test stack.
# Between initialization and creation of the test database it might take
# some time (seconds); if we spin it up now it should be ready to run by
# the time we need it.
- docker-compose -f ${TRAVIS_BUILD_DIR}/dev/docker/ci-compose.yml up -d db
# Tweak git to correctly work with submodules.
#- sed -i 's/git@github.com:/git:\/\/github.com\//' .gitmodules
#- git submodule update --init --recursive
install:
# Disable XDebug to speed up the tests.
- phpenv config-rm xdebug.ini
# The installation will include wp-cli as well as it's a requirement of wp-browser.
- composer update --prefer-dist
# Install composer on common if it exists.
- if [[ -d "common" ]]; then cd common; composer update --prefer-dist; cd ../; fi;
# Tweak the path to look for binaries in `vendor/bin` first.
# Binaries installed in the `vendor/bin` folder, like `wp` and `codecept`, will be available system-wide.
- export PATH=${TRAVIS_BUILD_DIR}/vendor/bin:$PATH
# Create the WordPress root folder.
- mkdir -p ${WP_ROOT_FOLDER}
# Download, configure and install WordPress in the `wordpress` folder.
# To configure WordPress we use the configuration parameters that will be used by the Docker container.
# See `dev/docker/ci-compose.yml` for more information.
- cd ${WP_ROOT_FOLDER}
- wp core download --version=${WP_VERSION}
# Let's generate the wp-config.php file for the WordPress installation from a template.
- echo "WP_DB_NAME=${WP_DB_NAME} WP_DB_PORT=${WP_DB_PORT} WP_TABLE_PREFIX=${WP_TABLE_PREFIX}"
- envsubst '${WP_DB_NAME},${WP_DB_PORT},${WP_TABLE_PREFIX}' < ${TRAVIS_BUILD_DIR}/dev/docker/wp-config.template > ./wp-config.php
# Reset the WordPress installation database if set and then re-install it.
- wp db reset --yes
- wp core install --url="${WP_URL}" --title="Tribe Tests" --admin_user="${WP_ADMIN_USERNAME}" --admin_password="${WP_ADMIN_PASSWORD}" --admin_email="admin@tribe.localhost" --skip-email
# Create a wp-cli configuration file to allow it to write an .htaccess file.
- echo -e "apache_modules:\n\t- mod_rewrite" > wp-cli.yml
# Install WooCommerce and Easy Digital Downloads
- wp plugin install woocommerce easy-digital-downloads
# Now that it is we've got a wp-config.php in place start the WordPress Docker container to have WordPress.
- docker-compose -f ${TRAVIS_BUILD_DIR}/dev/docker/ci-compose.yml up -d wordpress
# Since we've bound the WordPress folder from the local filesystem let's clear any possible r/w access issue.
- docker-compose -f ${TRAVIS_BUILD_DIR}/dev/docker/ci-compose.yml exec wordpress bash -c "chmod -R 0777 /var/www/html/wp-content/uploads"
# Copy over a mu-plugin that will make it so that WordPress will be able to resolve `http://localhost:port`.
- mkdir -p ${WP_ROOT_FOLDER}/wp-content/mu-plugins && cp ${TRAVIS_BUILD_DIR}/dev/docker/redirect-localhost-requests.php ${WP_ROOT_FOLDER}/wp-content/mu-plugins
# Create the database we'll use in integration tests accessing the database container.
- mysql --user=root --host=127.0.0.1 --port=${WP_DB_PORT} -e "create database ${WP_TEST_DB_NAME}";
- mysql --user=root --host=127.0.0.1 --port=${WP_DB_PORT} -e "show databases";
# If there are required plugins, clone them.
- source ${TRAVIS_BUILD_DIR}/dev/functions.sh; git_clone_required_plugins
# Get back to the build folder, the one where the plugin has been cloned by the CI.
- cd ${TRAVIS_BUILD_DIR}
# Copy the plugin into the WordPress plugin folder.
# We also set two variables:
# `PLUGIN_BASENAME` is the name of the plugin folder, e.g. `the-events-calendar` or `events-pro`.
# `PLUGIN_DIR` is the absolute path to the plugin folder in the WordPress installation, e.g. `/tmp/wordpress/wp-content/plugins/the-events-calendar`.
- export PLUGIN_BASENAME=$(basename "$(pwd)") && echo "PLUGIN_BASENAME=${PLUGIN_BASENAME}"
- cp -r ${TRAVIS_BUILD_DIR} ${WP_ROOT_FOLDER}/wp-content/plugins/${PLUGIN_BASENAME}
- export PLUGIN_DIR="${WP_ROOT_FOLDER}/wp-content/plugins/${PLUGIN_BASENAME}" && echo "PLUGIN_DIR=${PLUGIN_DIR}"
# Get back to the WordPress installation root folder.
- cd ${WP_ROOT_FOLDER}; echo "pwd=$(pwd)"
# Obtain the IP address of the `wordpress` container we started before from the stack.
- export WP_CONTAINER_IP=`docker inspect -f '{{ .NetworkSettings.Networks.docker_default.IPAddress }}' ci_wordpress`
# Finally start the Selenium and Chromedriver container.
- docker-compose -f ${TRAVIS_BUILD_DIR}/dev/docker/ci-compose.yml up -d chromedriver
# Make sure bins are searched in the plugin vendor/bin, inside WordPress, to avoid autoload issues.
- export PATH=${PLUGIN_DIR}/vendor/bin:$PATH
before_script:
# Activate the plugin in WordPress.
- wp plugin activate ${required_plugins_slugs} ${PLUGIN_BASENAME}
# Skip any welcome screen.
- wp option set tribe_skip_welcome 1
# Flush rewrite rules to make sure we're using permalinks.
- wp rewrite structure '/%postname%/' --hard
# Export a dump of the just installed database to the _data folder.
- wp db export ${PLUGIN_DIR}/tests/_data/dump.sql
# Do the same for the starting database fixture for the `restv1` suite (EDD/WC).
# - wp db export $PLUGIN_DIR/tests/_data/restv1-dump.sql
# Get back to the plugin dir.
- cd ${PLUGIN_DIR}
script:
#- codecept run wpunit
#- codecept run restv1
- codecept run acceptance
after_failure:
# if the build failed let's see why
- sudo cat $(php -i | grep ^error_log | cut -d' ' -f 3)
- sudo cat /var/log/nginx/error.log
# for acceptance-like tests
- for file in /tmp/wordpress/wp-content/plugins/${PLUGIN_BASENAME}/tests/_output/*.html; do echo "\n\n\n============" && cat $file; done