Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[major] Refactor WP install scripts to use WP-CLI #3

Merged
merged 145 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
145 commits
Select commit Hold shift + click to select a range
629d644
add helpers.sh to provide functions to other scripts
jazzsequence Feb 8, 2024
3c77509
add composer diff
jazzsequence Feb 8, 2024
570ce31
address shellcheck feedback
jazzsequence Feb 8, 2024
214a70a
use our helpers and tweak the local test install
jazzsequence Feb 8, 2024
c3d6f17
remove functions sourced in helpers
jazzsequence Feb 8, 2024
09a911f
tweak the test script and run against nightly on single and multisite
jazzsequence Feb 8, 2024
9bd00e1
test for helpers, too
jazzsequence Feb 8, 2024
7043fb5
output wp version
jazzsequence Feb 8, 2024
89e926d
update download function
jazzsequence Feb 8, 2024
5821c6d
remove extra linebreak
jazzsequence Feb 8, 2024
bf4dad9
add a comment
jazzsequence Feb 8, 2024
32e9fe2
fix grep
jazzsequence Feb 8, 2024
33b3702
remove comment
jazzsequence Feb 8, 2024
2c5b5fa
bump checkout to v4
jazzsequence Feb 8, 2024
37692a5
turn debugging on
jazzsequence Feb 8, 2024
448c06d
allow a version to be passed to install-local-tests
jazzsequence Feb 8, 2024
3549721
add a download wp function
jazzsequence Feb 8, 2024
bf151ba
add a setup_wp function
jazzsequence Feb 8, 2024
531594b
remove set -e since this will only be sourced
jazzsequence Feb 9, 2024
52a3731
fix spacing
jazzsequence Feb 9, 2024
f5ed115
remove the install_wp function
jazzsequence Feb 9, 2024
cbe19b3
setup_wp_nightly uses setup_wp
jazzsequence Feb 9, 2024
92c3bff
install_db needs some params
jazzsequence Feb 9, 2024
4a2ec62
add a cleanup
jazzsequence Feb 9, 2024
a7960b7
also reset the db in the cleanup
jazzsequence Feb 9, 2024
abd890f
default to no db pass
jazzsequence Feb 9, 2024
31d6bdc
Refactor install-wp-tests.sh script
jazzsequence Feb 9, 2024
a32fbe0
use phpunit instead of test for consistency
jazzsequence Feb 9, 2024
5b2a480
use flags instead of args
jazzsequence Feb 9, 2024
e909edf
check if the json file exists before removing it
jazzsequence Feb 9, 2024
4cee493
use --version
jazzsequence Feb 9, 2024
e69a890
allow tmpdir to be passed, too
jazzsequence Feb 9, 2024
a02b953
remove the question
jazzsequence Feb 9, 2024
dc4f79d
fix spacing
jazzsequence Feb 9, 2024
4bc8d11
update usage
jazzsequence Feb 9, 2024
ba09fc4
set SKIP_DB to the value we pass along to install-wp-tests
jazzsequence Feb 9, 2024
4cfba1b
fix the syntax
jazzsequence Feb 9, 2024
f2045cf
fix the syntax
jazzsequence Feb 9, 2024
5644685
shellcheck all the things
jazzsequence Feb 9, 2024
c7c4b6e
add an empty phpunit script
jazzsequence Feb 9, 2024
621221a
run through the scripts
jazzsequence Feb 9, 2024
52ed16a
remove unused var
jazzsequence Feb 9, 2024
fc5d2ff
fix the passed args
jazzsequence Feb 9, 2024
a31c04a
there's no skip_db in this function
jazzsequence Feb 9, 2024
1e83a05
turn on debugging
jazzsequence Feb 9, 2024
aea0a92
set the tmpdir to install into
jazzsequence Feb 9, 2024
4caaa29
change the test name
jazzsequence Feb 9, 2024
fed284f
be more specific about the phpunit test
jazzsequence Feb 9, 2024
a59945b
fix the skip db bit
jazzsequence Feb 9, 2024
6ea9e39
install wp-cli
jazzsequence Feb 9, 2024
2536f5b
fix wp-cli install
jazzsequence Feb 9, 2024
27bae5a
echo where we're installing WordPress
jazzsequence Feb 9, 2024
abe1229
add the rest of the vars to the install script
jazzsequence Feb 9, 2024
bf5feae
turn debugging on for the install wp script, too
jazzsequence Feb 9, 2024
f217e07
pass all the params to setup_wp
jazzsequence Feb 9, 2024
3cc308b
create the database before installing wp
jazzsequence Feb 9, 2024
87354fb
debug helpers
jazzsequence Feb 9, 2024
4628d3f
match the order to what we're passing
jazzsequence Feb 9, 2024
3c02e81
echo what we're doing with the database
jazzsequence Feb 9, 2024
0cb334c
fix the conditional to install the db
jazzsequence Feb 9, 2024
abf26ec
actually add a database to connect to
jazzsequence Feb 9, 2024
dddba9d
try the test without a db pass
jazzsequence Feb 9, 2024
1504be2
fix db pass in install_db function
jazzsequence Feb 9, 2024
368568c
we actually want word splitting here
jazzsequence Feb 9, 2024
e59db62
add root password back
jazzsequence Feb 9, 2024
5396aa7
some tests to mysql to make sure it's running and we have the right u…
jazzsequence Feb 9, 2024
d469f54
move the shellcheck ignore
jazzsequence Feb 9, 2024
88a512c
we actually do need to get the version from the json file
jazzsequence Feb 9, 2024
5837731
pass the wp version into install_test_suite
jazzsequence Feb 9, 2024
4a02926
use flags for wp version and tmp dir
jazzsequence Feb 9, 2024
582782c
we need to also pass the tmpdir
jazzsequence Feb 9, 2024
1b8a18e
we also need wp tests dir and db info in install_test_suite
jazzsequence Feb 9, 2024
cda4202
pass those values in
jazzsequence Feb 9, 2024
04fcb42
fix the paths
jazzsequence Feb 9, 2024
e04653f
remove debugging
jazzsequence Feb 9, 2024
f2f4bbc
print the working directory
jazzsequence Feb 9, 2024
9e9159b
don't cd into the test directory
jazzsequence Feb 9, 2024
afa65d6
bash the script
jazzsequence Feb 9, 2024
f02764f
can we set the shell to bash and remove the bash command?
jazzsequence Feb 9, 2024
3bce375
give the robot permission to read
jazzsequence Feb 9, 2024
3fc4298
switch back
jazzsequence Feb 9, 2024
8590037
turn on debugging for nightly test
jazzsequence Feb 9, 2024
bb06c54
remove the shifts
jazzsequence Feb 9, 2024
8213d0b
remove unused usage function
jazzsequence Feb 9, 2024
aeb1688
remove all shifts
jazzsequence Feb 9, 2024
93b3ce8
remove moar shifts
jazzsequence Feb 9, 2024
96b637a
debug the actual command
jazzsequence Feb 9, 2024
92b776e
replace --no-db with --skip-db
jazzsequence Feb 9, 2024
21abb07
add right param to composer includes
jazzsequence Feb 9, 2024
c6f45fd
echo the passed args for debugging
jazzsequence Feb 9, 2024
c8d9540
move the passed args debugging line higher so we can see it for both …
jazzsequence Feb 9, 2024
6a326d0
move local tests to a script
jazzsequence Feb 9, 2024
0ddf5b4
remove the bash
jazzsequence Feb 9, 2024
30fcdfd
run chmod in the script
jazzsequence Feb 9, 2024
d019a3e
add permissions
jazzsequence Feb 9, 2024
0be1cbc
bail if the script doesn't exist
jazzsequence Feb 9, 2024
2846a40
change the shebang in all the things
jazzsequence Feb 9, 2024
494a358
handle line ending conversions appropriately
jazzsequence Feb 9, 2024
f32a01c
ls the bin folder after the chmod and chmod the right thing
jazzsequence Feb 9, 2024
f303055
don't bash the script
jazzsequence Feb 9, 2024
0f1571f
ignore problemmatic things
jazzsequence Feb 9, 2024
d786485
remove quotes
jazzsequence Feb 9, 2024
ed229e0
force the wp download
jazzsequence Feb 9, 2024
11cafcb
don't create the wp-config if it exists
jazzsequence Feb 9, 2024
1c22889
remove debug code and cleanup when the test is done
jazzsequence Feb 9, 2024
99d5bc0
move setup stuff to the top
jazzsequence Feb 9, 2024
5f57ae9
cleanup on the right thing
jazzsequence Feb 9, 2024
ec89ba1
add db values as env variables to reset the db
jazzsequence Feb 9, 2024
d122ed1
drop the database
jazzsequence Feb 9, 2024
c419d4a
remove debug code
jazzsequence Feb 9, 2024
1f9f6b2
move test file validation to a script
jazzsequence Feb 9, 2024
2a5bf86
add comments to helpers
jazzsequence Feb 9, 2024
aabd8f6
[major] Update readme
jazzsequence Feb 9, 2024
aa87381
shellcheck the test scripts, too
jazzsequence Feb 9, 2024
87a116b
fix nightly setup
jazzsequence Feb 9, 2024
f0736fe
run the nightly install if that's what was requested
jazzsequence Feb 9, 2024
bdfd96e
remove passed args debug code
jazzsequence Feb 9, 2024
e036b75
remove setup_wp_nightly in phpunit-test.sh
jazzsequence Feb 9, 2024
c120b21
remove gitattributes
jazzsequence Feb 9, 2024
6e37732
remove debug
jazzsequence Feb 12, 2024
9f6bb3f
fix dumb comment thing
jazzsequence Feb 12, 2024
45b6d75
add missing :
jazzsequence Feb 12, 2024
32c4371
loop over the files to check
jazzsequence Feb 13, 2024
bc4bd7e
set variables to local
jazzsequence Feb 13, 2024
2922922
make the file check test a loop
jazzsequence Feb 13, 2024
ae54b81
use string manipulation instead of parsing the string parts before/af…
jazzsequence Feb 13, 2024
ac256c4
better handling of EXTRA using an array
jazzsequence Feb 13, 2024
ef33b52
add to the EXTRA array
jazzsequence Feb 13, 2024
9488b34
apply the same logic to bash wp install args
jazzsequence Feb 13, 2024
fbebdda
allow variables to be overridden with env variables
jazzsequence Feb 13, 2024
bdb2251
remove local
jazzsequence Feb 13, 2024
961b481
add some logging
jazzsequence Feb 13, 2024
6687e1b
turn on debugging so we can see what values were passed in
jazzsequence Feb 13, 2024
b06ab34
remove defaults
jazzsequence Feb 13, 2024
a6ad13b
move debugging to install_db step
jazzsequence Feb 13, 2024
6da408f
revert string manipulation
jazzsequence Feb 13, 2024
aa84ed9
move the debugging
jazzsequence Feb 13, 2024
59f8bf2
remove debugging
jazzsequence Feb 13, 2024
ffc8079
remove --version from SETUP_ARGS
jazzsequence Feb 13, 2024
c8c99d7
remove test in loop
jazzsequence Feb 13, 2024
8ed9ff3
wrap install-local-tests and install-wp-tests in a function
jazzsequence Feb 13, 2024
75ac98a
Merge branch 'add-more-helpers' of github.com:pantheon-systems/wpunit…
jazzsequence Feb 13, 2024
f0f1f3c
use local variables in all helper functions
jazzsequence Feb 13, 2024
1df496a
let's put the phpunit-test script in a function, too
jazzsequence Feb 13, 2024
3c8fa1a
fix local DIRNAME for shellcheck
jazzsequence Feb 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/autotag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
tag-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: pantheon-systems/action-autotag@v0
with:
gh-token: ${{ github.token }}
28 changes: 28 additions & 0 deletions .github/workflows/composer-diff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Composer Diff
on:
pull_request:
paths:
- 'composer.lock'
permissions:
contents: write
pull-requests: write
jobs:
composer-diff:
name: Composer Diff
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate composer diff
id: composer_diff
uses: IonBazan/composer-diff-action@v1
- uses: marocchino/sticky-pull-request-comment@v2
if: ${{ steps.composer_diff.outputs.composer_diff_exit_code != 0 }}
with:
header: composer-diff
message: |
<summary>Composer Changes</summary>

${{ steps.composer_diff.outputs.composer_diff }}
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install dependencies
run: composer install
- name: Lint
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup barebones project
run: |
mkdir test_proj && cd test_proj
Expand All @@ -19,4 +19,5 @@ jobs:
test -f bin/install-wp-tests.sh || (echo "❌ bin/install-wp-tests.sh not found" >&2 && exit 1)
test -f bin/install-local-tests.sh || (echo "❌ bin/install-local-tests.sh not found" >&2 && exit 1)
test -f bin/phpunit-test.sh || (echo "❌ bin/phpunit-test.sh not found" >&2 && exit 1)
test -f bin/helpers.sh || (echo "❌ bin/helpers.sh not found" >&2 && exit 1)
jazzsequence marked this conversation as resolved.
Show resolved Hide resolved
echo "✅ All bin files found"
130 changes: 130 additions & 0 deletions bin/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/bin/bash

set -e
jazzsequence marked this conversation as resolved.
Show resolved Hide resolved

download() {
if which curl &> /dev/null; then
curl -s "$1" > "$2";
elif which wget &> /dev/null; then
wget -nv -O "$2" "$1"
else
echo "Missing curl or wget" >&2
exit 1
fi
}

setup_wp_nightly() {
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
echo "Creating wp-config.php"
wp config create --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=127.0.0.1 --dbprefix=wptests_ --path="/tmp/wordpress"
wp core install --url=localhost --title=Test --admin_user=admin --admin_password=password [email protected] --path="/tmp/wordpress"
# If nightly version of WP is installed, install latest Gutenberg plugin and activate it.
echo "Installing Gutenberg plugin"
wp plugin install gutenberg --activate --path="/tmp/wordpress"
jazzsequence marked this conversation as resolved.
Show resolved Hide resolved
}

install_wp() {

if [ -d "$WP_CORE_DIR" ]; then
return;
fi

mkdir -p "$WP_CORE_DIR"

if [[ "$WP_VERSION" == 'nightly' || "$WP_VERSION" == 'trunk' ]]; then
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

# Assign with string replacement, escaping dots
local VERSION_ESCAPED
VERSION_ESCAPED="${WP_VERSION//./\\.}"
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 "$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
}

install_test_suite() {
# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
local ioption='-i .bak'
else
local ioption='-i'
fi

# set up testing suite if it doesn't yet exist
if [ ! -d "$WP_TESTS_DIR" ]; then
# set up testing suite
mkdir -p "$WP_TESTS_DIR"
svn co --quiet --ignore-externals https://develop.svn.wordpress.org/"${WP_TESTS_TAG}"/tests/phpunit/includes/ "$WP_TESTS_DIR"/includes
svn co --quiet --ignore-externals https://develop.svn.wordpress.org/"${WP_TESTS_TAG}"/tests/phpunit/data/ "$WP_TESTS_DIR"/data
fi

if [ ! -f wp-tests-config.php ]; then
download https://develop.svn.wordpress.org/"${WP_TESTS_TAG}"/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
# remove all forward slashes in the end
WP_CORE_DIR="${WP_CORE_DIR%/}"
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
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

}

install_db() {

if [ "${SKIP_DB_CREATE}" = "true" ]; then
return 0
fi

# parse DB_HOST for port or socket references
IFS=':' read -ra PARTS <<< "${DB_HOST}"
local DB_HOSTNAME=${PARTS[0]};
local DB_SOCK_OR_PORT=${PARTS[1]};
jazzsequence marked this conversation as resolved.
Show resolved Hide resolved
local EXTRA=""

if [ -n "$DB_HOSTNAME" ] ; then
if echo "$DB_SOCK_OR_PORT" | grep -qe '^[0-9]\{1,\}$'; then
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
elif [ -n "$DB_SOCK_OR_PORT" ] ; then
EXTRA=" --socket=$DB_SOCK_OR_PORT"
elif [ -n "$DB_HOSTNAME" ] ; then
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
fi
fi

# create database
mysqladmin create "$DB_NAME" --user="$DB_USER" --password="$DB_PASS""$EXTRA"
}

# Display usage information
usage() {
echo "Usage:"
echo "$0 [--dbname=wordpress_test] [--dbuser=root] [--dbpass=''] [--dbhost=127.0.0.1] [--wpversion=latest] [--no-db]"
}
18 changes: 10 additions & 8 deletions bin/install-local-tests.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#!/bin/bash
set -e

# shellcheck disable=SC1091
source "$(dirname "$0")/helpers.sh"

# Request version.
echo "Which version of WordPress would you like to test against? (latest, nightly, or a version number) Leave blank for latest."
read -r WP_VERSION

# Initialize variables with default values
TMPDIR="/tmp"
DB_NAME="wordpress_test"
DB_USER="root"
DB_PASS=""
DB_HOST="127.0.0.1"
WP_VERSION="latest"
WP_VERSION=${WP_VERSION:-latest}
SKIP_DB=""

# Display usage information
usage() {
echo "Usage:"
echo "./install-local-tests.sh [--dbname=wordpress_test] [--dbuser=root] [--dbpass=''] [--dbhost=127.0.0.1] [--wpversion=latest] [--no-db]"
}

# Parse command-line arguments
for i in "$@"
do
Expand Down Expand Up @@ -46,14 +47,15 @@ case $i in
;;
*)
# unknown option
usage
usage "./install-local-tests.sh"
exit 1
;;
esac
done

# Run install-wp-tests.sh
echo "Installing local tests into ${TMPDIR}"
echo "Using WordPress version: ${WP_VERSION}"
bash "$(dirname "$0")/install-wp-tests.sh" "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" "$WP_VERSION" "$SKIP_DB"

# Run PHPUnit
Expand Down
112 changes: 5 additions & 107 deletions bin/install-wp-tests.sh
jazzsequence marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env bash
set -x
# shellcheck disable=SC1091
source "$(dirname "$0")/helpers.sh"

if [ $# -lt 3 ]; then
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
usage $0
exit 1
fi

Expand All @@ -16,14 +19,6 @@ TMPDIR=${TMPDIR-/tmp}
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/}

download() {
if [ `which curl` ]; then
curl -s "$1" > "$2";
elif [ `which wget` ]; then
wget -nv -O "$2" "$1"
fi
}

if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then
WP_TESTS_TAG="branches/$WP_VERSION"
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
Expand All @@ -38,7 +33,7 @@ elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
else
# http serves a single offer, whereas https serves multiple. we only want one
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
grep -Eo '"version":"[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json | sed 's/"version":"//'
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
if [[ -z "$LATEST_VERSION" ]]; then
echo "Latest WordPress version could not be found"
Expand All @@ -49,103 +44,6 @@ fi

set -e

install_wp() {

if [ -d $WP_CORE_DIR ]; then
return;
fi

mkdir -p $WP_CORE_DIR

if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
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 $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
}

install_test_suite() {
# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
local ioption='-i .bak'
else
local ioption='-i'
fi

# set up testing suite if it doesn't yet exist
if [ ! -d $WP_TESTS_DIR ]; then
# set up testing suite
mkdir -p $WP_TESTS_DIR
svn co --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn co --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
fi

if [ ! -f wp-tests-config.php ]; then
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
# remove all forward slashes in the end
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
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
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

}

install_db() {

if [ ${SKIP_DB_CREATE} = "true" ]; then
return 0
fi

# parse DB_HOST for port or socket references
local PARTS=(${DB_HOST//\:/ })
local DB_HOSTNAME=${PARTS[0]};
local DB_SOCK_OR_PORT=${PARTS[1]};
local EXTRA=""

if ! [ -z $DB_HOSTNAME ] ; then
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
EXTRA=" --socket=$DB_SOCK_OR_PORT"
elif ! [ -z $DB_HOSTNAME ] ; then
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
fi
fi

# create database
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
}

install_wp
install_test_suite
install_db
Loading