Changes to travis, globally install phpunit and wpcs when required, cache vendor and composer cache directories

This commit is contained in:
Gerhard 2019-03-19 13:14:42 +02:00
parent 986375862e
commit b105550b47
6 changed files with 60 additions and 31 deletions

View File

@ -1,4 +1,5 @@
language: php
dist: trusty
addons:
chrome: stable
@ -8,6 +9,11 @@ addons:
sudo: false
cache:
directories:
- vendor
- $HOME/.composer/cache
# Test main supported versions of PHP against latest WP.
php:
- 5.6
@ -45,6 +51,7 @@ matrix:
env: WP_VERSION=latest WP_MULTISITE=0 RUN_CODE_COVERAGE=1
before_script:
- export PATH="$HOME/.composer/vendor/bin:$PATH"
- |
# Remove Xdebug for a huge performance increase:
if [ -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ]; then
@ -52,9 +59,18 @@ before_script:
else
echo "xdebug.ini does not exist"
fi
- export PATH="$HOME/.config/composer/vendor/bin:$PATH"
- bash tests/bin/install.sh woocommerce_test root '' localhost $WP_VERSION
- bash tests/bin/travis.sh before
- |
# Install WP Test suite, install PHPUnit globally if needed:
if [[ ! -z "$WP_VERSION" ]] ; then
bash tests/bin/install.sh woocommerce_test root '' localhost $WP_VERSION
composer global require "phpunit/phpunit=4.8.*|5.7.*"
fi
- |
# Install wpcs globally if needed:
if [[ ${RUN_PHPCS} == 1 ]]; then
composer global require wp-coding-standards/wpcs
phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs
fi
script:
- bash tests/bin/phpunit.sh

View File

@ -13,8 +13,10 @@ DB_HOST=${4-localhost}
WP_VERSION=${5-latest}
SKIP_DB_CREATE=${6-false}
WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
TMPDIR=${TMPDIR-/tmp}
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/}
download() {
if [ `which curl` ]; then
@ -24,8 +26,15 @@ download() {
fi
}
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)?(^-) ]]; then
WP_TESTS_TAG="tags/$WP_VERSION"
if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then
WP_TESTS_TAG="branches/$WP_VERSION"
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
WP_TESTS_TAG="tags/${WP_VERSION%??}"
else
WP_TESTS_TAG="tags/$WP_VERSION"
fi
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
WP_TESTS_TAG="trunk"
else
@ -51,18 +60,34 @@ install_wp() {
mkdir -p $WP_CORE_DIR
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
mkdir -p /tmp/wordpress-nightly
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
mkdir -p $TMPDIR/wordpress-nightly
download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip
unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/
mv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR
else
if [ $WP_VERSION == 'latest' ]; then
local ARCHIVE_NAME='latest'
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then
# https serves multiple offers, whereas http serves single.
download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
LATEST_VERSION=${WP_VERSION%??}
else
# otherwise, scan the releases and get the most up to date minor version of the major release
local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'`
LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1)
fi
if [[ -z "$LATEST_VERSION" ]]; then
local ARCHIVE_NAME="wordpress-$WP_VERSION"
else
local ARCHIVE_NAME="wordpress-$LATEST_VERSION"
fi
else
local ARCHIVE_NAME="wordpress-$WP_VERSION"
fi
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz
tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR
fi
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
@ -91,9 +116,7 @@ install_test_suite() {
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
# escape the regex delim if not already escaped (i.e. if preceded by an even number of backslashes)
E_DB_PASS=$(echo $DB_PASS | sed -E -e 's%([/&\\])%\\\1%g')
sed $ioption "s/yourpasswordhere/${E_DB_PASS}/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
fi

View File

@ -6,6 +6,6 @@ if [[ ${RUN_PHPCS} == 1 ]]; then
if [ "$CHANGED_FILES" != "" ]; then
echo "Running Code Sniffer."
./vendor/bin/phpcs --ignore=$IGNORE --encoding=utf-8 -s -n -p $CHANGED_FILES
phpcs --ignore=$IGNORE --encoding=utf-8 -s -n -p $CHANGED_FILES
fi
fi

View File

@ -5,7 +5,7 @@ if [[ ${RUN_PHPCS} == 1 ]] || [[ ${RUN_E2E} == 1 ]]; then
fi
if [[ ${RUN_CODE_COVERAGE} == 1 ]]; then
phpdbg -qrr -d memory_limit=-1 $HOME/.composer/vendor/bin/phpunit -c phpunit.xml --coverage-clover=coverage.clover --exclude-group=timeout
phpdbg -qrr -d memory_limit=-1 phpunit -c phpunit.xml --coverage-clover=coverage.clover --exclude-group=timeout
else
phpunit -c phpunit.xml
fi

View File

@ -7,7 +7,7 @@ if [[ ${RUN_E2E} == 1 ]]; then
export BASE_URL="$WP_SITE_URL"
export DISPLAY=:99.0
sh -e /etc/init.d/xvfb start
sleep 3
sleep 3
# Run the tests
npm test

View File

@ -1,16 +1,6 @@
#!/usr/bin/env bash
# usage: travis.sh before|after
if [ $1 == 'before' ]; then
composer global require "phpunit/phpunit=6.*"
if [[ ${RUN_PHPCS} == 1 ]]; then
composer install
fi
fi
if [ $1 == 'after' ]; then
if [[ ${RUN_CODE_COVERAGE} == 1 ]]; then
@ -22,9 +12,9 @@ if [ $1 == 'after' ]; then
if [[ ${RUN_E2E} == 1 && $(ls -A $TRAVIS_BUILD_DIR/screenshots) ]]; then
if [[ -z "${ARTIFACTS_KEY}" ]]; then
echo "Screenshots were not uploaded. Please run the e2e tests locally to see failures."
echo "Screenshots were not uploaded. Please run the e2e tests locally to see failures."
else
curl -sL https://raw.githubusercontent.com/travis-ci/artifacts/master/install | bash
curl -sL https://raw.githubusercontent.com/travis-ci/artifacts/master/install | bash
artifacts upload
fi
fi