Skip to content

Commit

Permalink
feat: add WPTL feature
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Oct 30, 2023
1 parent 91709e5 commit 9ff4b72
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
13 changes: 13 additions & 0 deletions features/src/setup-wptl/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"id": "setup-wptl",
"name": "WordPress with Test Library",
"description": "Sets up WordPress and WordPress Test Library",
"version": "0.0.1",
"options": {
"versions": {
"type": "string",
"default": "",
"description": "Versions to install"
}
}
}
60 changes: 60 additions & 0 deletions features/src/setup-wptl/install-wptl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh

set -e

download_wp() {
VERSION="$1"
if [ "${VERSION}" = "nightly" ] || [ "${VERSION}" = "trunk" ]; then
TESTS_TAG="trunk"
elif [ "${VERSION}" = "latest" ]; then
VERSIONS=$(wget https://api.wordpress.org/core/version-check/1.7/ -q -O - )
LATEST=$(echo "${VERSIONS}" | jq -r '.offers | map(select( .response == "upgrade")) | .[0].version')
if [ -z "${LATEST}" ]; then
echo "Unable to detect the latest WP version"
exit 1
fi

download_wp "${LATEST}"
ln -sf "/usr/share/wptl/wordpress-${LATEST}" /usr/share/wptl/wordpress-latest
ln -sf "/usr/share/wptl/wordpress-tests-lib-${LATEST}" /usr/share/wptl/wordpress-tests-lib-latest
return
elif [ "${VERSION%.x}" != "${VERSION}" ]; then
VER="${VERSION}"
LATEST=$(wget https://api.wordpress.org/core/version-check/1.7/ -q -O - | jq --arg version "${VERSION%.x}" -r '.offers | map(select(.version | startswith($version))) | sort_by(.version) | reverse | .[0].version')
download_wp "${LATEST}"
ln -sf "/usr/share/wptl/wordpress-${LATEST}" "/usr/share/wptl/wordpress-${VER}"
ln -sf "/usr/share/wptl/wordpress-tests-lib-${LATEST}" "/usr/share/wptl/wordpress-tests-lib-${VER}"
return
else
TESTS_TAG="tags/${VERSION}"
fi

if [ ! -d "/usr/share/wptl/wordpress-${VERSION}" ]; then
if [ "${VERSION}" = "nightly" ]; then
cd /wordpress
wget -q https://wordpress.org/nightly-builds/wordpress-latest.zip
unzip -q wordpress-latest.zip
mv /usr/share/wptl/wordpress /usr/share/wptl/wordpress-nightly
rm -f wordpress-latest.zip
cd -
else
mkdir -p "/usr/share/wptl/wordpress-${VERSION}"
wget -q "https://wordpress.org/wordpress-${VERSION}.tar.gz" -O - | tar --strip-components=1 -zxm -f - -C "/usr/share/wptl/wordpress-${VERSION}"
fi
wget -q https://raw.github.com/markoheijnen/wp-mysqli/master/db.php -O "/usr/share/wptl/wordpress-${VERSION}/wp-content/db.php"
else
echo "Skipping WordPress download"
fi

if [ ! -d "/usr/share/wptl/wordpress-tests-lib-${VERSION}" ]; then
mkdir -p "/usr/share/wptl/wordpress-tests-lib-${VERSION}"
svn co --quiet --ignore-externals "https://develop.svn.wordpress.org/${TESTS_TAG}/tests/phpunit/includes/" "/usr/share/wptl/wordpress-tests-lib-${VERSION}/includes"
svn co --quiet --ignore-externals "https://develop.svn.wordpress.org/${TESTS_TAG}/tests/phpunit/data/" "/usr/share/wptl/wordpress-tests-lib-${VERSION}/data"
rm -f "/usr/share/wptl/wordpress-tests-lib-${VERSION}/wp-tests-config-sample.php"
wget -q "https://develop.svn.wordpress.org/${TESTS_TAG}/wp-tests-config-sample.php" -O "/usr/share/wptl/wordpress-tests-lib-${VERSION}/wp-tests-config-sample.php"
else
echo "Skipping WordPress test library download"
fi
}

download_wp "${1:-latest}"
32 changes: 32 additions & 0 deletions features/src/setup-wptl/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

set -e

PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin

if [ "$(id -u || true)" -ne 0 ]; then
echo 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
fi

echo '(*) Setting up WordPress and Test Library...'

if [ -z "${_REMOTE_USER}" ] || [ "${_REMOTE_USER}" = "root" ]; then
WEB_USER="${CONTAINER_USER:-www-data}"
else
WEB_USER="${_REMOTE_USER}"
fi

install -d -m 0755 -o "${WEB_USER}" -g "${WEB_USER}" /usr/share/wptl
install -m 0755 -o root -g root install-wptl.sh /usr/local/bin/install-wptl

if [ -z "${VERSIONS}" ]; then
VERSIONS="$(wget https://api.wordpress.org/core/version-check/1.7/ -q -O - | jq -r '[.offers[].version] | unique | map(select( . >= "5.5")) | .[]') nightly"
fi

for version in ${VERSIONS} latest; do
install-wptl "${version}" &
done
wait

echo 'Done!'

0 comments on commit 9ff4b72

Please sign in to comment.