From 629d6441ae9f54a54d71b4d2a0aae64096fcb7c5 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 14:21:42 -0700 Subject: [PATCH 001/144] add helpers.sh to provide functions to other scripts --- bin/helpers.sh | 124 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100755 bin/helpers.sh diff --git a/bin/helpers.sh b/bin/helpers.sh new file mode 100755 index 0000000..4866a60 --- /dev/null +++ b/bin/helpers.sh @@ -0,0 +1,124 @@ +#!/bin/bash + +set -e + +download() { + if [ "$(which curl)" ]; then + curl -s "$1" > "$2"; + elif [ "$(which wget)" ]; then + wget -nv -O "$2" "$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 --admin_email=test@dev.null --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" +} + +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 +} + +# Display usage information +usage() { + echo "Usage:" + echo "$0 [--dbname=wordpress_test] [--dbuser=root] [--dbpass=''] [--dbhost=127.0.0.1] [--wpversion=latest] [--no-db]" +} From 3c77509bf43572202192cf8ddfbd138e39e30d1b Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 14:44:40 -0700 Subject: [PATCH 002/144] add composer diff --- .github/workflows/composer-diff.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/composer-diff.yml diff --git a/.github/workflows/composer-diff.yml b/.github/workflows/composer-diff.yml new file mode 100644 index 0000000..35e28dd --- /dev/null +++ b/.github/workflows/composer-diff.yml @@ -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: | + Composer Changes + + ${{ steps.composer_diff.outputs.composer_diff }} From 570ce314931c91a31f8f6226f2f95539f1f56626 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 14:44:54 -0700 Subject: [PATCH 003/144] address shellcheck feedback --- bin/helpers.sh | 71 ++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 4866a60..37406fe 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -22,30 +22,33 @@ setup_wp_nightly() { install_wp() { - if [ -d $WP_CORE_DIR ]; then + if [ -d "$WP_CORE_DIR" ]; then return; fi - mkdir -p $WP_CORE_DIR + 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 + 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 + if [ "$WP_VERSION" == 'latest' ]; then local ARCHIVE_NAME='latest' - elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then + 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 + 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) + + # 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" @@ -55,11 +58,11 @@ install_wp() { 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 + 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 + download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php "$WP_CORE_DIR"/wp-content/db.php } install_test_suite() { @@ -71,50 +74,50 @@ install_test_suite() { fi # set up testing suite if it doesn't yet exist - if [ ! -d $WP_TESTS_DIR ]; then + 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 + 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 + 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 + 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 + if [ "${SKIP_DB_CREATE}" = "true" ]; then return 0 fi # parse DB_HOST for port or socket references - local PARTS=(${DB_HOST//\:/ }) + IFS=':' read -ra 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 + 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 ! [ -z $DB_SOCK_OR_PORT ] ; then + elif [ -n "$DB_SOCK_OR_PORT" ] ; then EXTRA=" --socket=$DB_SOCK_OR_PORT" - elif ! [ -z $DB_HOSTNAME ] ; then + 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 + mysqladmin create "$DB_NAME" --user="$DB_USER" --password="$DB_PASS""$EXTRA" } # Display usage information From 214a70a7cf01dfa74716ecb29a2476b8c48f3dac Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 14:45:25 -0700 Subject: [PATCH 004/144] use our helpers and tweak the local test install --- bin/install-local-tests.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index c1f8cc5..e636154 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -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 @@ -46,7 +47,7 @@ case $i in ;; *) # unknown option - usage + usage "./install-local-tests.sh" exit 1 ;; esac From c3d6f17de884cc3b3d8edd764bc2a56a06e09812 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 14:46:19 -0700 Subject: [PATCH 005/144] remove functions sourced in helpers --- bin/install-wp-tests.sh | 111 ++-------------------------------------- 1 file changed, 5 insertions(+), 106 deletions(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 675dd97..9e3d994 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -1,10 +1,14 @@ #!/usr/bin/env bash +# shellcheck disable=SC1091 +source "$(dirname "$0")/helpers.sh" + if [ $# -lt 3 ]; then - echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" + usage $0 exit 1 fi + DB_NAME=$1 DB_USER=$2 DB_PASS=$3 @@ -16,14 +20,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 @@ -49,103 +45,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 From 09a911ff7c6bd59a8267482f8d9d590624ad365f Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 14:47:02 -0700 Subject: [PATCH 006/144] tweak the test script and run against nightly on single and multisite --- bin/phpunit-test.sh | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/bin/phpunit-test.sh b/bin/phpunit-test.sh index 450c3a8..45f2836 100755 --- a/bin/phpunit-test.sh +++ b/bin/phpunit-test.sh @@ -2,17 +2,45 @@ set -e +# shellcheck disable=SC1091 +source "$(dirname "$0")/helpers.sh" + DIRNAME=$(dirname "$0") +echo "๐Ÿค” Installing WP Unit tests..." bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 latest -echo "Running PHPUnit on Single Site" -composer phpunit + +echo "๐Ÿ“„ Copying wp-latest.json..." +cp /tmp/wp-latest.json "${DIRNAME}/../tests/wp-latest.json" + +echo '------------------------------------------' +echo "๐Ÿƒโ€โ™‚๏ธ [Run 1]: Running PHPUnit on Single Site" +composer phpunit --ansi + +echo "๐Ÿงน Removing files before testing WPMS..." +rm "${DIRNAME}/../tests/wp-latest.json" rm -rf "$WP_TESTS_DIR" "$WP_CORE_DIR" +bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 latest true +echo '------------------------------------------' +echo "๐Ÿƒโ€โ™‚๏ธ [Run 2]: Running PHPUnit on Multisite" +WP_MULTISITE=1 composer test --ansi + +echo "๐Ÿงน Removing files before testing nightly WP..." + +echo "๐Ÿค” Installing WP Unit tests with WP nightly version..." bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 nightly true -echo "Running PHPUnit on Single Site (Nightly WordPress)" -composer phpunit +echo "๐Ÿ“„ Copying wp-latest.json..." +cp /tmp/wp-latest.json "${DIRNAME}/../tests/wp-latest.json" -bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 latest true -echo "Running PHPUnit on Multisite" -WP_MULTISITE=1 composer phpunit +setup_wp_nightly + +echo '------------------------------------------' +echo "๐Ÿƒโ€โ™‚๏ธ [Run 3]: Running PHPUnit on Single Site (Nightly WordPress)" +composer phpunit --ansi + +echo '------------------------------------------' +echo "๐Ÿƒโ€โ™‚๏ธ [Run 4]: Running PHPUnit on Multisite (Nightly WordPress)" +WP_MULTISITE=1 composer phpunit --ansi + +echo "Done! โœ…" From 9bd00e1f463fedecf44e576738334871f7ed92e0 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 14:48:49 -0700 Subject: [PATCH 007/144] test for helpers, too --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 97cb7de..3bacc0e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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) echo "โœ… All bin files found" From 7043fb5094581d18786c23edb301efd084197804 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 14:52:43 -0700 Subject: [PATCH 008/144] output wp version --- bin/install-local-tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index e636154..f1f2078 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -55,6 +55,7 @@ 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 From 89e926df8d970d2557c965e3bd8e8146698b5339 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 14:52:51 -0700 Subject: [PATCH 009/144] update download function --- bin/helpers.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 37406fe..ef72458 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -3,11 +3,14 @@ set -e download() { - if [ "$(which curl)" ]; then - curl -s "$1" > "$2"; - elif [ "$(which wget)" ]; then - wget -nv -O "$2" "$1" - fi + 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() { From 5821c6d67121475200f727f30050f87143c26c02 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 14:53:25 -0700 Subject: [PATCH 010/144] remove extra linebreak --- bin/install-wp-tests.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 9e3d994..26b90ca 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -8,7 +8,6 @@ if [ $# -lt 3 ]; then exit 1 fi - DB_NAME=$1 DB_USER=$2 DB_PASS=$3 From bf4dad9db9e8961a24513affa796250f42b26e07 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 14:53:39 -0700 Subject: [PATCH 011/144] add a comment --- bin/install-wp-tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 26b90ca..ef12c7b 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -44,6 +44,7 @@ fi set -e +echo "Installing WordPress test suite into ${TMPDIR}" install_wp install_test_suite install_db From 32e9fe241404b379b4a75fb5d0cbb387cb476a1b Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 15:02:02 -0700 Subject: [PATCH 012/144] fix grep --- bin/install-wp-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index ef12c7b..bcc4899 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -33,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" From 33b3702d3f656d390fbb1816c3002e87dde25457 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 15:03:14 -0700 Subject: [PATCH 013/144] remove comment --- bin/install-wp-tests.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index bcc4899..dbe41ba 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -44,7 +44,6 @@ fi set -e -echo "Installing WordPress test suite into ${TMPDIR}" install_wp install_test_suite install_db From 2c5b5faf4dc4c80507d440628afc2412182c0047 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 15:15:25 -0700 Subject: [PATCH 014/144] bump checkout to v4 --- .github/workflows/autotag.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/test.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/autotag.yml b/.github/workflows/autotag.yml index 77c79cf..8f75f16 100644 --- a/.github/workflows/autotag.yml +++ b/.github/workflows/autotag.yml @@ -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 }} \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 455a1f2..3e2a65f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3bacc0e..e622e64 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 From 37692a51547b94ce89b36a2358975e408cb43959 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 15:16:32 -0700 Subject: [PATCH 015/144] turn debugging on so we can debug this in the mu-plugin --- bin/install-wp-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index dbe41ba..da35515 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash - +set -x # shellcheck disable=SC1091 source "$(dirname "$0")/helpers.sh" From 448c06de9eca271ba8e91ab9605e3024fbf444b6 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 16:17:03 -0700 Subject: [PATCH 016/144] allow a version to be passed to install-local-tests --- bin/install-local-tests.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index f1f2078..34ed35c 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -4,9 +4,14 @@ 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 +# Check if a version was provided as an argument. +if [ $# -gt 0 ]; then + WP_VERSION=$1 +else + # 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 +fi # Initialize variables with default values TMPDIR="/tmp" From 35497213dc60fe82f32cc6abcebd310bc10b70b3 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 16:45:08 -0700 Subject: [PATCH 017/144] add a download wp function --- bin/helpers.sh | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index ef72458..ea58f92 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -13,8 +13,36 @@ download() { fi } -setup_wp_nightly() { - download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json +download_wp() { + TMPDIR="/tmp" + WP_VERSION="latest" + + for i in "$@"; do + case $i in + --wpversion=*) + WP_VERSION="${i#*=}" + shift + ;; + --tmpdir=*) + TMPDIR="${i#*=}" + shift + ;; + *) + # unknown option + echo "Unknown option: $i. Usage: download_wp --wpversion=latest --tmpdir=/tmp" + exit 1 + ;; + esac + + # Check for WP-CLI. If the wp command does not exist, exit. + if ! which wp &> /dev/null; then + echo "WP-CLI is not installed. Exiting." + exit 1 + fi + + echo "Downloading WordPress version: ${WP_VERSION}" + wp core download --version="$WP_VERSION" --path="${TMPDIR}/wordpress" +} 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 --admin_email=test@dev.null --path="/tmp/wordpress" From bf151baa02ac7eed763ec5c75ebac69c93823b8b Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 16:45:39 -0700 Subject: [PATCH 018/144] add a setup_wp function --- bin/helpers.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index ea58f92..563cb40 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -43,9 +43,62 @@ download_wp() { echo "Downloading WordPress version: ${WP_VERSION}" wp core download --version="$WP_VERSION" --path="${TMPDIR}/wordpress" } + +setup_wp() { + # Initialize variables with default values + TMPDIR="/tmp" + DB_NAME="wordpress_test" + DB_USER="root" + DB_PASS="root" + DB_HOST="127.0.0.1" + WP_VERSION=${WP_VERSION:-latest} + SKIP_DB="" + + # Parse command-line arguments + for i in "$@" + do + case $i in + --dbname=*) + DB_NAME="${i#*=}" + shift + ;; + --dbuser=*) + DB_USER="${i#*=}" + shift + ;; + --dbpass=*) + DB_PASS="${i#*=}" + shift + ;; + --dbhost=*) + DB_HOST="${i#*=}" + shift + ;; + --wpversion=*) + WP_VERSION="${i#*=}" + shift + ;; + --no-db) + SKIP_DB="true" + shift + ;; + --tmpdir=*) + TMPDIR="${i#*=}" + shift + ;; + *) + # unknown option + echo "Unknown option: $i. Usage: setup_wp --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --wpversion=latest --tmpdir=/tmp --no-db" + exit 1 + ;; + esac + done + + download http://api.wordpress.org/core/version-check/1.7/ "$TMPDIR"/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 --admin_email=test@dev.null --path="/tmp/wordpress" + wp config create --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" --dbprefix="wptests_" --path="${TMPDIR}/wordpress" + wp core install --url=localhost --title=Test --admin_user=admin --admin_password=password --admin_email=test@dev.null --path="${TMPDIR}/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" From 531594be29b3e90e9e4708738f4d270934373acc Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:08:51 -0700 Subject: [PATCH 019/144] remove set -e since this will only be sourced --- bin/helpers.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 563cb40..41dbb19 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -1,7 +1,5 @@ #!/bin/bash -set -e - download() { if which curl &> /dev/null; then curl -s "$1" > "$2"; @@ -19,7 +17,7 @@ download_wp() { for i in "$@"; do case $i in - --wpversion=*) + --version=*) WP_VERSION="${i#*=}" shift ;; @@ -29,10 +27,11 @@ download_wp() { ;; *) # unknown option - echo "Unknown option: $i. Usage: download_wp --wpversion=latest --tmpdir=/tmp" + echo "Unknown option: $i. Usage: download_wp --version=latest --tmpdir=/tmp" exit 1 ;; esac + done # Check for WP-CLI. If the wp command does not exist, exit. if ! which wp &> /dev/null; then From 52a3731acda000ea96d446f0b0926fe899c6d0f0 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:09:14 -0700 Subject: [PATCH 020/144] fix spacing --- bin/helpers.sh | 73 +++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 41dbb19..0a890c6 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -54,43 +54,42 @@ setup_wp() { SKIP_DB="" # Parse command-line arguments - for i in "$@" - do - case $i in - --dbname=*) - DB_NAME="${i#*=}" - shift - ;; - --dbuser=*) - DB_USER="${i#*=}" - shift - ;; - --dbpass=*) - DB_PASS="${i#*=}" - shift - ;; - --dbhost=*) - DB_HOST="${i#*=}" - shift - ;; - --wpversion=*) - WP_VERSION="${i#*=}" - shift - ;; - --no-db) - SKIP_DB="true" - shift - ;; - --tmpdir=*) - TMPDIR="${i#*=}" - shift - ;; - *) - # unknown option - echo "Unknown option: $i. Usage: setup_wp --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --wpversion=latest --tmpdir=/tmp --no-db" - exit 1 - ;; - esac + for i in "$@"; do + case $i in + --dbname=*) + DB_NAME="${i#*=}" + shift + ;; + --dbuser=*) + DB_USER="${i#*=}" + shift + ;; + --dbpass=*) + DB_PASS="${i#*=}" + shift + ;; + --dbhost=*) + DB_HOST="${i#*=}" + shift + ;; + --version=*) + WP_VERSION="${i#*=}" + shift + ;; + --no-db) + SKIP_DB="true" + shift + ;; + --tmpdir=*) + TMPDIR="${i#*=}" + shift + ;; + *) + # unknown option + echo "Unknown option: $i. Usage: setup_wp --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --version=latest --tmpdir=/tmp --no-db" + exit 1 + ;; + esac done download http://api.wordpress.org/core/version-check/1.7/ "$TMPDIR"/wp-latest.json From f5ed11528e4bad88b5aee3ae763a867cf4fd27a2 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:10:08 -0700 Subject: [PATCH 021/144] remove the install_wp function replacing with our own using wpcli --- bin/helpers.sh | 47 +---------------------------------------------- 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 0a890c6..d7eba46 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -99,52 +99,7 @@ setup_wp() { } # 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" -} - -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 + wp plugin install gutenberg --activate --path="$WP_DIR" } install_test_suite() { From cbe19b31af82d9412ba96302af1ae321dcc62f92 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:10:27 -0700 Subject: [PATCH 022/144] setup_wp_nightly uses setup_wp --- bin/helpers.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bin/helpers.sh b/bin/helpers.sh index d7eba46..01c6247 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -97,6 +97,25 @@ setup_wp() { wp config create --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" --dbprefix="wptests_" --path="${TMPDIR}/wordpress" wp core install --url=localhost --title=Test --admin_user=admin --admin_password=password --admin_email=test@dev.null --path="${TMPDIR}/wordpress" } + +setup_wp_nightly() { + WP_DIR="/tmp/wordpress" + + for i in "$@"; do + case $i in + --wpdir=*) + WP_DIR="${i#*=}" + shift + ;; + *) + # unknown option + echo "Unknown option: $i. Usage: setup_wp_nightly --wpdir=/tmp/wordpress" + exit 1 + ;; + esac + done + + setup_wp --version="nightly" # If nightly version of WP is installed, install latest Gutenberg plugin and activate it. echo "Installing Gutenberg plugin" wp plugin install gutenberg --activate --path="$WP_DIR" From 92c3bfff13624121c93f287ee662dc197d69fb3c Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:10:43 -0700 Subject: [PATCH 023/144] install_db needs some params --- bin/helpers.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 01c6247..4a40f5a 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -147,10 +147,14 @@ install_test_suite() { 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() { + DB_HOST=${1:-"127.0.0.1"} + DB_NAME=${2:-"wordpress_test"} + DB_USER=${3:-"root"} + DB_PASS=${4:-""} + SKIP_DB=${5:-""} if [ "${SKIP_DB_CREATE}" = "true" ]; then return 0 From 4a2ec62e5b153671e727297b9cfe276e88b668a4 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:10:54 -0700 Subject: [PATCH 024/144] add a cleanup --- bin/helpers.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bin/helpers.sh b/bin/helpers.sh index 4a40f5a..ff52753 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -180,6 +180,16 @@ install_db() { mysqladmin create "$DB_NAME" --user="$DB_USER" --password="$DB_PASS""$EXTRA" } +cleanup() { + WPDIR=${1:-"/tmp/wordpress"} + WP_TESTS_DIR=${2:-"/tmp/wordpress-tests-lib"} + WP_VERSION_JSON=${3:-"/tmp/wp-latest.json"} + + rm -rf "$WPDIR" + rm -rf "$WP_TESTS_DIR" + rm -f "$WP_VERSION_JSON" +} + # Display usage information usage() { echo "Usage:" From a7960b747aa77fb93489e02295a94c4d99d472d1 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:11:32 -0700 Subject: [PATCH 025/144] also reset the db in the cleanup --- bin/helpers.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/helpers.sh b/bin/helpers.sh index ff52753..e9cd3ad 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -185,6 +185,7 @@ cleanup() { WP_TESTS_DIR=${2:-"/tmp/wordpress-tests-lib"} WP_VERSION_JSON=${3:-"/tmp/wp-latest.json"} + wp db reset --yes --path="$WPDIR" rm -rf "$WPDIR" rm -rf "$WP_TESTS_DIR" rm -f "$WP_VERSION_JSON" From abd890f4fefb3a5937229c09e72cdf1921dd6ce8 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:11:50 -0700 Subject: [PATCH 026/144] default to no db pass for local install --- bin/helpers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index e9cd3ad..3dc1ec1 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -48,7 +48,7 @@ setup_wp() { TMPDIR="/tmp" DB_NAME="wordpress_test" DB_USER="root" - DB_PASS="root" + DB_PASS="" DB_HOST="127.0.0.1" WP_VERSION=${WP_VERSION:-latest} SKIP_DB="" From 31d6bdc8e2637f997dab8efa1eebc61b32e06e90 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:12:23 -0700 Subject: [PATCH 027/144] Refactor install-wp-tests.sh script --- bin/install-wp-tests.sh | 57 ++++++++++++----------------------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index da35515..c7c96c6 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -1,49 +1,24 @@ #!/usr/bin/env bash -set -x +set -e + # shellcheck disable=SC1091 source "$(dirname "$0")/helpers.sh" -if [ $# -lt 3 ]; then - usage $0 - exit 1 -fi - -DB_NAME=$1 -DB_USER=$2 -DB_PASS=$3 -DB_HOST=${4-localhost} -WP_VERSION=${5-latest} -SKIP_DB_CREATE=${6-false} - -TMPDIR=${TMPDIR-/tmp} +WP_VERSION=${1:-latest} +TMPDIR=${2:-/tmp} +DB_NAME=${3:-"wordpress_test"} +DB_USER=${4:-"root"} +DB_PASS=${5:-""} +DB_HOST=${6:-"127.0.0.1"} +SKIP_DB=${7:-""} WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} -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 - # 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 -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" - exit 1 - fi - WP_TESTS_TAG="tags/$LATEST_VERSION" -fi - -set -e - -install_wp +download_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" +setup_wp --version="$WP_VERSION" install_test_suite -install_db + +# Maybe install the database. +if [ -n "$SKIP_DB" ]; then + install_db "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" +fi From a32fbe002c418dbdc99cf94bb2a0a2765762d1af Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:12:45 -0700 Subject: [PATCH 028/144] use phpunit instead of test for consistency --- bin/phpunit-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/phpunit-test.sh b/bin/phpunit-test.sh index 45f2836..bba7825 100755 --- a/bin/phpunit-test.sh +++ b/bin/phpunit-test.sh @@ -24,7 +24,7 @@ rm -rf "$WP_TESTS_DIR" "$WP_CORE_DIR" bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 latest true echo '------------------------------------------' echo "๐Ÿƒโ€โ™‚๏ธ [Run 2]: Running PHPUnit on Multisite" -WP_MULTISITE=1 composer test --ansi +WP_MULTISITE=1 composer phpunit --ansi echo "๐Ÿงน Removing files before testing nightly WP..." From 5b2a480c4edfcdfc688c94206e3a232653cec11c Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:25:37 -0700 Subject: [PATCH 029/144] use flags instead of args --- bin/install-wp-tests.sh | 55 +++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index c7c96c6..6701920 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -4,13 +4,54 @@ set -e # shellcheck disable=SC1091 source "$(dirname "$0")/helpers.sh" -WP_VERSION=${1:-latest} -TMPDIR=${2:-/tmp} -DB_NAME=${3:-"wordpress_test"} -DB_USER=${4:-"root"} -DB_PASS=${5:-""} -DB_HOST=${6:-"127.0.0.1"} -SKIP_DB=${7:-""} +# Initialize variables with default values +TMPDIR="/tmp" +DB_NAME="wordpress_test" +DB_USER="root" +DB_PASS="" +DB_HOST="127.0.0.1" +WP_VERSION=${WP_VERSION:-latest} +SKIP_DB="" + +# Parse command-line arguments +for i in "$@"; do + case $i in + --dbname=*) + DB_NAME="${i#*=}" + shift + ;; + --dbuser=*) + DB_USER="${i#*=}" + shift + ;; + --dbpass=*) + DB_PASS="${i#*=}" + shift + ;; + --dbhost=*) + DB_HOST="${i#*=}" + shift + ;; + --version=*) + WP_VERSION="${i#*=}" + shift + ;; + --no-db) + SKIP_DB="true" + shift + ;; + --tmpdir=*) + TMPDIR="${i#*=}" + shift + ;; + *) + # unknown option + echo "Unknown option: $i. Usage: ./bin/install-wp-tests.sh --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --version=latest --tmpdir=/tmp --no-db" + exit 1 + ;; + esac +done + WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} From e909edfbf44e080daa3e7733c320fe70640345b8 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:25:55 -0700 Subject: [PATCH 030/144] check if the json file exists before removing it --- bin/helpers.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 3dc1ec1..755ea69 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -188,7 +188,12 @@ cleanup() { wp db reset --yes --path="$WPDIR" rm -rf "$WPDIR" rm -rf "$WP_TESTS_DIR" - rm -f "$WP_VERSION_JSON" + + # Check if the file exists + if [ -f "$WP_VERSION_JSON" ]; then + # Remove the files + rm -f "$WP_VERSION_JSON" + fi } # Display usage information From 4cee493370210b4abd160aab4588a907e2c1a252 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:26:19 -0700 Subject: [PATCH 031/144] use --version --- bin/install-local-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index 34ed35c..e5f905c 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -42,7 +42,7 @@ case $i in DB_HOST="${i#*=}" shift ;; - --wpversion=*) + --version=*) WP_VERSION="${i#*=}" shift ;; From e69a89071716937eb82b1ee6826aff97bcc03708 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:26:33 -0700 Subject: [PATCH 032/144] allow tmpdir to be passed, too --- bin/install-local-tests.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index e5f905c..f3ef79c 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -50,6 +50,10 @@ case $i in SKIP_DB="true" shift ;; + --tmpdir=*) + TMPDIR="${i#*=}" + shift + ;; *) # unknown option usage "./install-local-tests.sh" From a02b953417f66dca04301c9850c8225f9115bede Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:26:44 -0700 Subject: [PATCH 033/144] remove the question --- bin/install-local-tests.sh | 9 --------- 1 file changed, 9 deletions(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index f3ef79c..d4c7dad 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -4,15 +4,6 @@ set -e # shellcheck disable=SC1091 source "$(dirname "$0")/helpers.sh" -# Check if a version was provided as an argument. -if [ $# -gt 0 ]; then - WP_VERSION=$1 -else - # 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 -fi - # Initialize variables with default values TMPDIR="/tmp" DB_NAME="wordpress_test" From dc4f79d12d33d9a6110bbf19bacb56aa6debffec Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:26:53 -0700 Subject: [PATCH 034/144] fix spacing --- bin/install-local-tests.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index d4c7dad..4d5824f 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -14,9 +14,8 @@ WP_VERSION=${WP_VERSION:-latest} SKIP_DB="" # Parse command-line arguments -for i in "$@" -do -case $i in +for i in "$@"; do + case $i in --dbname=*) DB_NAME="${i#*=}" shift From 4bc8d112ca3d661d87b63b672fae69043daa0c5b Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:27:22 -0700 Subject: [PATCH 035/144] update usage --- bin/install-local-tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index 4d5824f..a841aa0 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -46,10 +46,10 @@ for i in "$@"; do ;; *) # unknown option - usage "./install-local-tests.sh" + echo "Unknown option: $i. Usage: ./bin/install-local-tests.sh --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --version=latest --tmpdir=/tmp --no-db" exit 1 ;; -esac + esac done # Run install-wp-tests.sh From ba09fc456362bffdd3510d0e3170efc02f561c83 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:29:04 -0700 Subject: [PATCH 036/144] set SKIP_DB to the value we pass along to install-wp-tests --- bin/install-local-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index a841aa0..ef771d8 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -37,7 +37,7 @@ for i in "$@"; do shift ;; --no-db) - SKIP_DB="true" + SKIP_DB="--no-db" shift ;; --tmpdir=*) From 4cfba1bc0265a14cafb34050186f485436855a5c Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:29:15 -0700 Subject: [PATCH 037/144] fix the syntax --- bin/install-local-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index ef771d8..f9f50ee 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -55,7 +55,7 @@ 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" +bash "$(dirname "$0")/install-wp-tests.sh" --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" "$SKIP_DB" # Run PHPUnit echo "Running PHPUnit" From f2045cfc4817100e9da274dbfe094400e682d5bb Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:29:26 -0700 Subject: [PATCH 038/144] fix the syntax --- bin/phpunit-test.sh | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/bin/phpunit-test.sh b/bin/phpunit-test.sh index bba7825..bedd2f9 100755 --- a/bin/phpunit-test.sh +++ b/bin/phpunit-test.sh @@ -8,30 +8,22 @@ source "$(dirname "$0")/helpers.sh" DIRNAME=$(dirname "$0") echo "๐Ÿค” Installing WP Unit tests..." -bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 latest - -echo "๐Ÿ“„ Copying wp-latest.json..." -cp /tmp/wp-latest.json "${DIRNAME}/../tests/wp-latest.json" +bash "${DIRNAME}/install-wp-tests.sh" --dbpass=root echo '------------------------------------------' echo "๐Ÿƒโ€โ™‚๏ธ [Run 1]: Running PHPUnit on Single Site" composer phpunit --ansi -echo "๐Ÿงน Removing files before testing WPMS..." -rm "${DIRNAME}/../tests/wp-latest.json" -rm -rf "$WP_TESTS_DIR" "$WP_CORE_DIR" - -bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 latest true +bash "${DIRNAME}/install-wp-tests.sh" --dbpass=root --no-db echo '------------------------------------------' echo "๐Ÿƒโ€โ™‚๏ธ [Run 2]: Running PHPUnit on Multisite" WP_MULTISITE=1 composer phpunit --ansi echo "๐Ÿงน Removing files before testing nightly WP..." +cleanup echo "๐Ÿค” Installing WP Unit tests with WP nightly version..." -bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 nightly true -echo "๐Ÿ“„ Copying wp-latest.json..." -cp /tmp/wp-latest.json "${DIRNAME}/../tests/wp-latest.json" +bash "${DIRNAME}/install-wp-tests.sh" --dbpass=root --version=nightly --no-db setup_wp_nightly From 56446854a615682cc03adbf77d7a49abf62f9ff9 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:29:37 -0700 Subject: [PATCH 039/144] shellcheck all the things --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c495d9c..e260dbf 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "class": "Pantheon\\WPUnitHelpers\\Plugin" }, "scripts": { - "shellcheck": "find bin/ -name \"*.sh\" | grep -v \"install-wp-tests.sh\" | xargs shellcheck", + "shellcheck": "shellcheck bin/*", "phpcs": "phpcs --standard=PSR2 src/", "phplint": "find src/ -name '*.php' -exec php -l {} \\;", "lint": [ From c7c4b6e28c59c95ba650e5f9455102d4f2683ce7 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:30:12 -0700 Subject: [PATCH 040/144] add an empty phpunit script this lets us run the tests ourselves in the future we could add some files to run tests on but for now this doesn't do anything --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e260dbf..e6baa2f 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "@shellcheck", "@phpcs", "@phplint" - ] + ], + "phpunit": "echo 'Nothing to see here.'" } } From 621221aee3ece44ae557391417065c71ec9bf0e0 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:30:42 -0700 Subject: [PATCH 041/144] run through the scripts --- .github/workflows/test.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e622e64..68fb592 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,3 +21,13 @@ jobs: 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) echo "โœ… All bin files found" + - name: Run local install + run: | + echo "Testing latest install..." + mkdir -p ${{ github.workspace }}/local_tests && cd ${{ github.workspace }}/local_tests + bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh latest + echo "Testing nightly install..." + ${{ github.workspace }}/test_proj/bin/install-local-tests.sh nightly --no-db + - name: Run PHPUnit Tests + run: bash ${{ github.workspace }}/test_proj/bin/phpunit-test.sh + From 52ed16a60af40cd0dd46c3526973dc195bc810e1 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:32:27 -0700 Subject: [PATCH 042/144] remove unused var --- bin/helpers.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 755ea69..8cca934 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -154,7 +154,6 @@ install_db() { DB_NAME=${2:-"wordpress_test"} DB_USER=${3:-"root"} DB_PASS=${4:-""} - SKIP_DB=${5:-""} if [ "${SKIP_DB_CREATE}" = "true" ]; then return 0 From fc5d2fff57dbd91ae5bb374e0a2e175f261d880d Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:33:47 -0700 Subject: [PATCH 043/144] fix the passed args --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 68fb592..2bae472 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,9 +25,9 @@ jobs: run: | echo "Testing latest install..." mkdir -p ${{ github.workspace }}/local_tests && cd ${{ github.workspace }}/local_tests - bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh latest + bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --dbpass=root echo "Testing nightly install..." - ${{ github.workspace }}/test_proj/bin/install-local-tests.sh nightly --no-db + ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --version=nightly --no-db - name: Run PHPUnit Tests run: bash ${{ github.workspace }}/test_proj/bin/phpunit-test.sh From a31c04acb9c355a8bf84d98bc44565afd043e040 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:35:11 -0700 Subject: [PATCH 044/144] there's no skip_db in this function --- bin/helpers.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 8cca934..664aa32 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -51,7 +51,6 @@ setup_wp() { DB_PASS="" DB_HOST="127.0.0.1" WP_VERSION=${WP_VERSION:-latest} - SKIP_DB="" # Parse command-line arguments for i in "$@"; do @@ -76,17 +75,13 @@ setup_wp() { WP_VERSION="${i#*=}" shift ;; - --no-db) - SKIP_DB="true" - shift - ;; --tmpdir=*) TMPDIR="${i#*=}" shift ;; *) # unknown option - echo "Unknown option: $i. Usage: setup_wp --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --version=latest --tmpdir=/tmp --no-db" + echo "Unknown option: $i. Usage: setup_wp --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --version=latest --tmpdir=/tmp" exit 1 ;; esac From 1e83a059ac0aee86f0c8d36c7a9110e38577a853 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:38:50 -0700 Subject: [PATCH 045/144] turn on debugging --- bin/install-local-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index f9f50ee..f1ef4af 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -ex # shellcheck disable=SC1091 source "$(dirname "$0")/helpers.sh" From aea0a9216a7c08f3882c90de7e1938316495c786 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:39:04 -0700 Subject: [PATCH 046/144] set the tmpdir to install into --- .github/workflows/test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2bae472..2495219 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,9 +25,9 @@ jobs: run: | echo "Testing latest install..." mkdir -p ${{ github.workspace }}/local_tests && cd ${{ github.workspace }}/local_tests - bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --dbpass=root + bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir=${{ github.workspace }}/local_tests echo "Testing nightly install..." - ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --version=nightly --no-db + ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --version=nightly --no-db --tmpdir=${{ github.workspace }}/local_tests - name: Run PHPUnit Tests - run: bash ${{ github.workspace }}/test_proj/bin/phpunit-test.sh + run: bash ${{ github.workspace }}/test_proj/bin/phpunit-test.sh --tmpdir=${{ github.workspace }}/local_tests From 4caaa292e3625d2a124edcf7794a5f66335d90c5 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:39:16 -0700 Subject: [PATCH 047/144] change the test name --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2495219..a7a8c15 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Test Plugin +name: Test on: [pull_request] jobs: test: From fed284f969d8c573f9871021c266a4e69f2c1511 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:41:37 -0700 Subject: [PATCH 048/144] be more specific about the phpunit test --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a7a8c15..55a1e6e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,6 +28,6 @@ jobs: bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir=${{ github.workspace }}/local_tests echo "Testing nightly install..." ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --version=nightly --no-db --tmpdir=${{ github.workspace }}/local_tests - - name: Run PHPUnit Tests + - name: Run PHPUnit Test Install run: bash ${{ github.workspace }}/test_proj/bin/phpunit-test.sh --tmpdir=${{ github.workspace }}/local_tests From a59945bf1d6d7dc6978e780598716281ea93e71f Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:43:45 -0700 Subject: [PATCH 049/144] fix the skip db bit --- bin/install-local-tests.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index f1ef4af..f7b1ca0 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -37,7 +37,7 @@ for i in "$@"; do shift ;; --no-db) - SKIP_DB="--no-db" + SKIP_DB="true" shift ;; --tmpdir=*) @@ -55,7 +55,12 @@ 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" --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" "$SKIP_DB" + +if [ -z "$SKIP_DB" ]; then + bash "$(dirname "$0")/install-wp-tests.sh" --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" +else + bash "$(dirname "$0")/install-wp-tests.sh" bash "$(dirname "$0")/install-wp-tests.sh" --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" --no-db +fi # Run PHPUnit echo "Running PHPUnit" From 6ea9e396016ec383b9e4834b2421a7c0aa3d12ec Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:45:13 -0700 Subject: [PATCH 050/144] install wp-cli --- .github/workflows/test.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 55a1e6e..702b684 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,6 +21,11 @@ jobs: 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) echo "โœ… All bin files found" + - name: Install WP-CLI + run: | + curl -0 https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar + chmod +x wp-cli.phar + sudo mv wp-cli.phar /usr/local/bin/wp - name: Run local install run: | echo "Testing latest install..." From 2536f5bf07672f59e040c38ddab4ab668fdace5f Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 8 Feb 2024 17:46:22 -0700 Subject: [PATCH 051/144] fix wp-cli install --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 702b684..5d16f19 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: echo "โœ… All bin files found" - name: Install WP-CLI run: | - curl -0 https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar + curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp - name: Run local install From 27bae5aa2b375023bde122faba4f11220ac5ea80 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:05:30 -0700 Subject: [PATCH 052/144] echo where we're installing WordPress --- bin/helpers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 664aa32..2f373fb 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -39,7 +39,7 @@ download_wp() { exit 1 fi - echo "Downloading WordPress version: ${WP_VERSION}" + echo "Downloading WordPress version: ${WP_VERSION} to ${TMPDIR}/wordpress" wp core download --version="$WP_VERSION" --path="${TMPDIR}/wordpress" } From abe1229a105ef380581e25e377a248e9374b1754 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:06:40 -0700 Subject: [PATCH 053/144] add the rest of the vars to the install script --- bin/install-local-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index f7b1ca0..cd662b5 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -57,7 +57,7 @@ echo "Installing local tests into ${TMPDIR}" echo "Using WordPress version: ${WP_VERSION}" if [ -z "$SKIP_DB" ]; then - bash "$(dirname "$0")/install-wp-tests.sh" --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" + bash "$(dirname "$0")/install-wp-tests.sh" --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" else bash "$(dirname "$0")/install-wp-tests.sh" bash "$(dirname "$0")/install-wp-tests.sh" --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" --no-db fi From bf5feae5e971d6befea45774a6a54cfe3fa363c0 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:06:55 -0700 Subject: [PATCH 054/144] turn debugging on for the install wp script, too --- bin/install-wp-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 6701920..0ae667f 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -e +set -ex # shellcheck disable=SC1091 source "$(dirname "$0")/helpers.sh" From f217e075a399f1eb47ebbb722baba2bd04793d94 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:19:20 -0700 Subject: [PATCH 055/144] pass all the params to setup_wp --- bin/install-wp-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 0ae667f..150f3da 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -56,7 +56,7 @@ WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} download_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" -setup_wp --version="$WP_VERSION" +setup_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" install_test_suite # Maybe install the database. From 3cc308bcc7a1c50663adb6c1d2474e8debd75572 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:20:36 -0700 Subject: [PATCH 056/144] create the database before installing wp --- bin/install-wp-tests.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 150f3da..cb37503 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -55,11 +55,12 @@ done WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} -download_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" -setup_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" -install_test_suite - # Maybe install the database. if [ -n "$SKIP_DB" ]; then install_db "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" fi + +download_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" +setup_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" +install_test_suite + From 87354fbbabe86048f420396b45511b3d200b3da1 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:21:35 -0700 Subject: [PATCH 057/144] debug helpers --- bin/helpers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 2f373fb..d432f83 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -1,5 +1,5 @@ #!/bin/bash - +set -x download() { if which curl &> /dev/null; then curl -s "$1" > "$2"; From 4628d3f03c10450a59e5dae94df552dd8ba7d4d4 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:22:50 -0700 Subject: [PATCH 058/144] match the order to what we're passing --- bin/helpers.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index d432f83..8053fa3 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -145,10 +145,10 @@ install_test_suite() { } install_db() { - DB_HOST=${1:-"127.0.0.1"} - DB_NAME=${2:-"wordpress_test"} - DB_USER=${3:-"root"} - DB_PASS=${4:-""} + DB_NAME=${1:-"wordpress_test"} + DB_USER=${2:-"root"} + DB_PASS=${3:-""} + DB_HOST=${4:-"127.0.0.1"} if [ "${SKIP_DB_CREATE}" = "true" ]; then return 0 From 3c02e81f21f519d97b989605a6aa55ca0032cad8 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:25:17 -0700 Subject: [PATCH 059/144] echo what we're doing with the database --- bin/helpers.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 8053fa3..dd5af59 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -150,9 +150,7 @@ install_db() { DB_PASS=${3:-""} DB_HOST=${4:-"127.0.0.1"} - if [ "${SKIP_DB_CREATE}" = "true" ]; then - return 0 - fi + echo "Creating database: $1 on $4..." # parse DB_HOST for port or socket references IFS=':' read -ra PARTS <<< "${DB_HOST}" From 0cb334c878476670488be93cfc01281482699499 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:28:29 -0700 Subject: [PATCH 060/144] fix the conditional to install the db --- bin/install-wp-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index cb37503..6055a9b 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -56,7 +56,7 @@ WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} # Maybe install the database. -if [ -n "$SKIP_DB" ]; then +if [ -z "$SKIP_DB" ]; then install_db "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" fi From abf26ecdde81319466f260f63efbb2327e11588d Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:30:56 -0700 Subject: [PATCH 061/144] actually add a database to connect to --- .github/workflows/test.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5d16f19..5da743b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,6 +3,9 @@ on: [pull_request] jobs: test: runs-on: ubuntu-latest + services: + mariadb: + image: mariadb:10.6 steps: - uses: actions/checkout@v4 - name: Setup barebones project @@ -21,6 +24,8 @@ jobs: 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) echo "โœ… All bin files found" + - name: Start MySQL + run: sudo systemctl start mysql - name: Install WP-CLI run: | curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar From dddba9dddc5b7ebb5c18fb68471ff4089e9313f5 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:35:15 -0700 Subject: [PATCH 062/144] try the test without a db pass --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5da743b..ac163ed 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,7 +35,7 @@ jobs: run: | echo "Testing latest install..." mkdir -p ${{ github.workspace }}/local_tests && cd ${{ github.workspace }}/local_tests - bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir=${{ github.workspace }}/local_tests + bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --tmpdir=${{ github.workspace }}/local_tests echo "Testing nightly install..." ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --version=nightly --no-db --tmpdir=${{ github.workspace }}/local_tests - name: Run PHPUnit Test Install From 1504be26c241af7f64cb9926b070cdbb13934aa0 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:38:23 -0700 Subject: [PATCH 063/144] fix db pass in install_db function --- bin/helpers.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index dd5af59..0a116df 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -168,8 +168,12 @@ install_db() { fi fi + if [ -n "$DB_PASS" ] ; then + EXTRA="$EXTRA --password=$DB_PASS" + fi + # create database - mysqladmin create "$DB_NAME" --user="$DB_USER" --password="$DB_PASS""$EXTRA" + mysqladmin create "$DB_NAME" --user="$DB_USER" "$EXTRA" } cleanup() { From 368568c36ab3eb9a2a07ddf2c885beb55f409dfe Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:40:38 -0700 Subject: [PATCH 064/144] we actually want word splitting here --- bin/helpers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 0a116df..66f84ec 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -173,7 +173,7 @@ install_db() { fi # create database - mysqladmin create "$DB_NAME" --user="$DB_USER" "$EXTRA" + mysqladmin create "$DB_NAME" --user="$DB_USER" $EXTRA # shellcheck disable=SC2086 } cleanup() { From e59db623ca68cf7aad6814183de510ed56ec1862 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:41:46 -0700 Subject: [PATCH 065/144] add root password back --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ac163ed..5da743b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,7 +35,7 @@ jobs: run: | echo "Testing latest install..." mkdir -p ${{ github.workspace }}/local_tests && cd ${{ github.workspace }}/local_tests - bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --tmpdir=${{ github.workspace }}/local_tests + bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir=${{ github.workspace }}/local_tests echo "Testing nightly install..." ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --version=nightly --no-db --tmpdir=${{ github.workspace }}/local_tests - name: Run PHPUnit Test Install From 5396aa7f987ff9c5356f53e3cf1548327016ad97 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:43:20 -0700 Subject: [PATCH 066/144] some tests to mysql to make sure it's running and we have the right un/pw --- .github/workflows/test.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5da743b..4fdab1b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,7 +25,12 @@ jobs: test -f bin/helpers.sh || (echo "โŒ bin/helpers.sh not found" >&2 && exit 1) echo "โœ… All bin files found" - name: Start MySQL - run: sudo systemctl start mysql + run: | + sudo systemctl start mysql + # Validate that MySQL is running + sudo systemctl status mysql + # Connect to MySQL to test auth. + mysql -e "SELECT 1" -uroot -proot - name: Install WP-CLI run: | curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar From d469f54fdece9107d8de287ccbe2afdbb011db09 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:55:20 -0700 Subject: [PATCH 067/144] move the shellcheck ignore --- bin/helpers.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 66f84ec..afa8eb3 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -172,8 +172,8 @@ install_db() { EXTRA="$EXTRA --password=$DB_PASS" fi - # create database - mysqladmin create "$DB_NAME" --user="$DB_USER" $EXTRA # shellcheck disable=SC2086 + # shellcheck disable=SC2086 + mysqladmin create "$DB_NAME" --user="$DB_USER" $EXTRA } cleanup() { From 88a512ca315c4647eadc2cc4468970d7e1804825 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:55:33 -0700 Subject: [PATCH 068/144] we actually do need to get the version from the json file --- bin/helpers.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bin/helpers.sh b/bin/helpers.sh index afa8eb3..15d50d5 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -116,7 +116,24 @@ setup_wp_nightly() { wp plugin install gutenberg --activate --path="$WP_DIR" } +get_wp_version_num() { + WP_VERSION=${WP_VERSION:-latest} + WP_VERSION_JSON="/tmp/wp-latest.json" + + # Get latest version from JSON if latest was passed. + if [ "$WP_VERSION" == "latest" ]; then + WP_VERSION=$(grep -o '"version":"[^"]*' "$WP_VERSION_JSON" | cut -d'"' -f4) + fi + + if [ "$WP_VERSION" == "nightly" ]; then + WP_VERSION="trunk" + fi + + echo "$WP_VERSION" +} + install_test_suite() { + WP_VERSION=$(get_wp_version_num "$@") # portable in-place argument for both GNU sed and Mac OSX sed if [[ $(uname -s) == 'Darwin' ]]; then local ioption='-i .bak' From 583773101a766b57af49cb143c0c799a3ceda8ed Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 09:55:46 -0700 Subject: [PATCH 069/144] pass the wp version into install_test_suite --- bin/install-wp-tests.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 6055a9b..5ab5350 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -62,5 +62,4 @@ fi download_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" setup_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" -install_test_suite - +install_test_suite "$WP_VERSION" From 4a02926ac426e3b3366356557a2f1527587fb8c7 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 10:06:56 -0700 Subject: [PATCH 070/144] use flags for wp version and tmp dir --- bin/helpers.sh | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 15d50d5..2c952c9 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -117,10 +117,29 @@ setup_wp_nightly() { } get_wp_version_num() { - WP_VERSION=${WP_VERSION:-latest} - WP_VERSION_JSON="/tmp/wp-latest.json" + WP_VERSION="latest" + TMPDIR="/tmp/wp-latest.json" + + for i in "$@"; do + case $i in + --version=*) + WP_VERSION="${i#*=}" + shift + ;; + --tmpdir=*) + TMPDIR="${i#*=}" + shift + ;; + *) + # unknown option + echo "Unknown option: $i. Usage: get_wp_version_num --version=latest --tmpdir=/tmp/wp-latest.json" + exit 1 + ;; + esac + done # Get latest version from JSON if latest was passed. + WP_VERSION_JSON="${TMPDIR}/wp-latest.json" if [ "$WP_VERSION" == "latest" ]; then WP_VERSION=$(grep -o '"version":"[^"]*' "$WP_VERSION_JSON" | cut -d'"' -f4) fi @@ -133,7 +152,9 @@ get_wp_version_num() { } install_test_suite() { - WP_VERSION=$(get_wp_version_num "$@") + WP_VERSION=${1:-"latest"} + TMPDIR=${2:-"/tmp"} + WP_VERSION=$(get_wp_version_num --version="$WP_VERSION" --tmpdir="$TMPDIR") # portable in-place argument for both GNU sed and Mac OSX sed if [[ $(uname -s) == 'Darwin' ]]; then local ioption='-i .bak' From 582782cea0b5462b0faf323107d3bc276e7d21f2 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 10:07:05 -0700 Subject: [PATCH 071/144] we need to also pass the tmpdir --- bin/install-wp-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 5ab5350..c855b60 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -62,4 +62,4 @@ fi download_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" setup_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" -install_test_suite "$WP_VERSION" +install_test_suite "$WP_VERSION" "$TMPDIR" From 1b8a18eec1e852c13e75c12093fb4f89ba696866 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 10:11:29 -0700 Subject: [PATCH 072/144] we also need wp tests dir and db info in install_test_suite --- bin/helpers.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 2c952c9..11b8fd4 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -154,7 +154,12 @@ get_wp_version_num() { install_test_suite() { WP_VERSION=${1:-"latest"} TMPDIR=${2:-"/tmp"} + DB_NAME=${3:-"wordpress_test"} + DB_USER=${4:-"root"} + DB_PASS=${5:-""} + DB_HOST=${6:-"127.0.0.1"} WP_VERSION=$(get_wp_version_num --version="$WP_VERSION" --tmpdir="$TMPDIR") + WP_TESTS_DIR=${WP_TESTS_DIR-"$TMPDIR/wordpress-tests-lib"} # portable in-place argument for both GNU sed and Mac OSX sed if [[ $(uname -s) == 'Darwin' ]]; then local ioption='-i .bak' @@ -166,12 +171,12 @@ install_test_suite() { 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 + svn co --quiet --ignore-externals https://develop.svn.wordpress.org/"${WP_VERSION}"/tests/phpunit/includes/ "$WP_TESTS_DIR"/includes + svn co --quiet --ignore-externals https://develop.svn.wordpress.org/"${WP_VERSION}"/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 + download https://develop.svn.wordpress.org/"${WP_VERSION}"/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 From cda4202334c9b392a69a1d2acf12d32e79c50d70 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 10:11:36 -0700 Subject: [PATCH 073/144] pass those values in --- bin/install-wp-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index c855b60..126d7c2 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -62,4 +62,4 @@ fi download_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" setup_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" -install_test_suite "$WP_VERSION" "$TMPDIR" +install_test_suite "$WP_VERSION" "$TMPDIR" "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" From 04fcb42c5c6df3b9f9735a40b1f8fbe58e91463c Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 10:16:48 -0700 Subject: [PATCH 074/144] fix the paths --- bin/helpers.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 11b8fd4..468ae3d 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -160,6 +160,14 @@ install_test_suite() { DB_HOST=${6:-"127.0.0.1"} WP_VERSION=$(get_wp_version_num --version="$WP_VERSION" --tmpdir="$TMPDIR") WP_TESTS_DIR=${WP_TESTS_DIR-"$TMPDIR/wordpress-tests-lib"} + + # If we're using trunk, there is no tests tag. + if [ "$WP_VERSION" == "trunk" ]; then + WP_TESTS_TAG="trunk" + else + WP_TESTS_TAG="tags/${WP_VERSION}" + fi + # portable in-place argument for both GNU sed and Mac OSX sed if [[ $(uname -s) == 'Darwin' ]]; then local ioption='-i .bak' @@ -171,12 +179,12 @@ install_test_suite() { 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_VERSION}"/tests/phpunit/includes/ "$WP_TESTS_DIR"/includes - svn co --quiet --ignore-externals https://develop.svn.wordpress.org/"${WP_VERSION}"/tests/phpunit/data/ "$WP_TESTS_DIR"/data + 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_VERSION}"/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php + 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 From e04653f29ed176f0abfa21462c0ef9b6d9c18985 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 10:19:14 -0700 Subject: [PATCH 075/144] remove debugging --- bin/helpers.sh | 2 +- bin/install-local-tests.sh | 2 +- bin/install-wp-tests.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 468ae3d..331ccfb 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -x + download() { if which curl &> /dev/null; then curl -s "$1" > "$2"; diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index cd662b5..17dd152 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -ex +set -e # shellcheck disable=SC1091 source "$(dirname "$0")/helpers.sh" diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 126d7c2..c3f8ba4 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -e # shellcheck disable=SC1091 source "$(dirname "$0")/helpers.sh" From f2f4bbc112bc8edb72ff5809c5ef2b07d788cc85 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 10:19:42 -0700 Subject: [PATCH 076/144] print the working directory wanna see where we are so we know where to run composer script from --- bin/install-local-tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index 17dd152..2e0e6a1 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -63,5 +63,6 @@ else fi # Run PHPUnit +pwd echo "Running PHPUnit" composer phpunit From 9e9159b80e4c859d5912ad7f21730ed2238cb6cb Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 10:22:12 -0700 Subject: [PATCH 077/144] don't cd into the test directory --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4fdab1b..f8b5d01 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,7 +39,7 @@ jobs: - name: Run local install run: | echo "Testing latest install..." - mkdir -p ${{ github.workspace }}/local_tests && cd ${{ github.workspace }}/local_tests + mkdir -p ${{ github.workspace }}/local_tests bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir=${{ github.workspace }}/local_tests echo "Testing nightly install..." ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --version=nightly --no-db --tmpdir=${{ github.workspace }}/local_tests From afa65d63bff3ea0946bf55f7cb21a946afd03c5c Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 10:24:29 -0700 Subject: [PATCH 078/144] bash the script --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f8b5d01..f74ceef 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,7 +42,7 @@ jobs: mkdir -p ${{ github.workspace }}/local_tests bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir=${{ github.workspace }}/local_tests echo "Testing nightly install..." - ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --version=nightly --no-db --tmpdir=${{ github.workspace }}/local_tests + bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --version=nightly --no-db --tmpdir=${{ github.workspace }}/local_tests - name: Run PHPUnit Test Install run: bash ${{ github.workspace }}/test_proj/bin/phpunit-test.sh --tmpdir=${{ github.workspace }}/local_tests From f02764f9aa8d501392a4e864ab4ccab992ec2685 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 10:27:20 -0700 Subject: [PATCH 079/144] can we set the shell to bash and remove the bash command? --- .github/workflows/test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f74ceef..1c2f734 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,12 +37,13 @@ jobs: chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp - name: Run local install + shell: bash run: | echo "Testing latest install..." mkdir -p ${{ github.workspace }}/local_tests - bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir=${{ github.workspace }}/local_tests + ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir=${{ github.workspace }}/local_tests echo "Testing nightly install..." - bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --version=nightly --no-db --tmpdir=${{ github.workspace }}/local_tests + ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --version=nightly --no-db --tmpdir=${{ github.workspace }}/local_tests - name: Run PHPUnit Test Install run: bash ${{ github.workspace }}/test_proj/bin/phpunit-test.sh --tmpdir=${{ github.workspace }}/local_tests From 3bce37595fdc492ee8c61d7eaab189c4dcb77ef4 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 10:28:27 -0700 Subject: [PATCH 080/144] give the robot permission to read --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1c2f734..0e34d04 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,7 @@ name: Test on: [pull_request] +permissions: + contents: read jobs: test: runs-on: ubuntu-latest From 3fc429872c1aa1b06ceee22919f5c444da4b0f59 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 10:30:21 -0700 Subject: [PATCH 081/144] switch back --- .github/workflows/test.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0e34d04..e7fcfcc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,5 @@ name: Test on: [pull_request] -permissions: - contents: read jobs: test: runs-on: ubuntu-latest @@ -43,9 +41,9 @@ jobs: run: | echo "Testing latest install..." mkdir -p ${{ github.workspace }}/local_tests - ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir=${{ github.workspace }}/local_tests + bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir=${{ github.workspace }}/local_tests echo "Testing nightly install..." - ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --version=nightly --no-db --tmpdir=${{ github.workspace }}/local_tests + bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --version=nightly --no-db --tmpdir=${{ github.workspace }}/local_tests - name: Run PHPUnit Test Install run: bash ${{ github.workspace }}/test_proj/bin/phpunit-test.sh --tmpdir=${{ github.workspace }}/local_tests From 8590037c1463fc80a04d7a659430d0ea35690e44 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 10:51:00 -0700 Subject: [PATCH 082/144] turn on debugging for nightly test --- bin/install-wp-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index c3f8ba4..126d7c2 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -e +set -ex # shellcheck disable=SC1091 source "$(dirname "$0")/helpers.sh" From bb06c5435da20bef440359d17c4da13b28227533 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 10:55:41 -0700 Subject: [PATCH 083/144] remove the shifts --- bin/install-wp-tests.sh | 7 ------- 1 file changed, 7 deletions(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 126d7c2..d583b66 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -18,31 +18,24 @@ for i in "$@"; do case $i in --dbname=*) DB_NAME="${i#*=}" - shift ;; --dbuser=*) DB_USER="${i#*=}" - shift ;; --dbpass=*) DB_PASS="${i#*=}" - shift ;; --dbhost=*) DB_HOST="${i#*=}" - shift ;; --version=*) WP_VERSION="${i#*=}" - shift ;; --no-db) SKIP_DB="true" - shift ;; --tmpdir=*) TMPDIR="${i#*=}" - shift ;; *) # unknown option From 8213d0b8a34ae5b7099e2b42b45d52433da9e426 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 11:00:44 -0700 Subject: [PATCH 084/144] remove unused usage function --- bin/helpers.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 331ccfb..b345dd0 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -242,9 +242,3 @@ cleanup() { rm -f "$WP_VERSION_JSON" fi } - -# Display usage information -usage() { - echo "Usage:" - echo "$0 [--dbname=wordpress_test] [--dbuser=root] [--dbpass=''] [--dbhost=127.0.0.1] [--wpversion=latest] [--no-db]" -} From aeb1688ae1c6797ba1f58d2affd3e5bdefebca66 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 11:00:52 -0700 Subject: [PATCH 085/144] remove all shifts --- bin/helpers.sh | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index b345dd0..1ccff6a 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -19,11 +19,9 @@ download_wp() { case $i in --version=*) WP_VERSION="${i#*=}" - shift ;; --tmpdir=*) TMPDIR="${i#*=}" - shift ;; *) # unknown option @@ -57,27 +55,21 @@ setup_wp() { case $i in --dbname=*) DB_NAME="${i#*=}" - shift ;; --dbuser=*) DB_USER="${i#*=}" - shift ;; --dbpass=*) DB_PASS="${i#*=}" - shift ;; --dbhost=*) DB_HOST="${i#*=}" - shift ;; --version=*) WP_VERSION="${i#*=}" - shift ;; --tmpdir=*) TMPDIR="${i#*=}" - shift ;; *) # unknown option @@ -100,7 +92,6 @@ setup_wp_nightly() { case $i in --wpdir=*) WP_DIR="${i#*=}" - shift ;; *) # unknown option @@ -124,11 +115,9 @@ get_wp_version_num() { case $i in --version=*) WP_VERSION="${i#*=}" - shift ;; --tmpdir=*) TMPDIR="${i#*=}" - shift ;; *) # unknown option From 93b3ce88ab0c16eb320b3914b5df89994eb3c5d4 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 11:02:20 -0700 Subject: [PATCH 086/144] remove moar shifts --- bin/install-local-tests.sh | 7 ------- 1 file changed, 7 deletions(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index 2e0e6a1..e9e465e 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -18,31 +18,24 @@ for i in "$@"; do case $i in --dbname=*) DB_NAME="${i#*=}" - shift ;; --dbuser=*) DB_USER="${i#*=}" - shift ;; --dbpass=*) DB_PASS="${i#*=}" - shift ;; --dbhost=*) DB_HOST="${i#*=}" - shift ;; --version=*) WP_VERSION="${i#*=}" - shift ;; --no-db) SKIP_DB="true" - shift ;; --tmpdir=*) TMPDIR="${i#*=}" - shift ;; *) # unknown option From 96b637a67d87532f4ff2eefbbd44c95dee50671c Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 11:44:27 -0700 Subject: [PATCH 087/144] debug the actual command --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e7fcfcc..8a41ea4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,6 +43,7 @@ jobs: mkdir -p ${{ github.workspace }}/local_tests bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir=${{ github.workspace }}/local_tests echo "Testing nightly install..." + set -x bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --version=nightly --no-db --tmpdir=${{ github.workspace }}/local_tests - name: Run PHPUnit Test Install run: bash ${{ github.workspace }}/test_proj/bin/phpunit-test.sh --tmpdir=${{ github.workspace }}/local_tests From 92b776e34c2481f9a56c4fa66865e4838db7aa38 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 11:48:28 -0700 Subject: [PATCH 088/144] replace --no-db with --skip-db --- .github/workflows/test.yml | 3 +-- bin/install-local-tests.sh | 6 +++--- bin/install-wp-tests.sh | 4 ++-- bin/phpunit-test.sh | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8a41ea4..d7d95eb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,8 +43,7 @@ jobs: mkdir -p ${{ github.workspace }}/local_tests bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir=${{ github.workspace }}/local_tests echo "Testing nightly install..." - set -x - bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --version=nightly --no-db --tmpdir=${{ github.workspace }}/local_tests + bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --version=nightly --skip-db=true --tmpdir=${{ github.workspace }}/local_tests - name: Run PHPUnit Test Install run: bash ${{ github.workspace }}/test_proj/bin/phpunit-test.sh --tmpdir=${{ github.workspace }}/local_tests diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index e9e465e..c32a388 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -31,7 +31,7 @@ for i in "$@"; do --version=*) WP_VERSION="${i#*=}" ;; - --no-db) + --skip-db=*) SKIP_DB="true" ;; --tmpdir=*) @@ -39,7 +39,7 @@ for i in "$@"; do ;; *) # unknown option - echo "Unknown option: $i. Usage: ./bin/install-local-tests.sh --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --version=latest --tmpdir=/tmp --no-db" + echo "Unknown option: $i. Usage: ./bin/install-local-tests.sh --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --version=latest --tmpdir=/tmp --skip-db=true" exit 1 ;; esac @@ -52,7 +52,7 @@ echo "Using WordPress version: ${WP_VERSION}" if [ -z "$SKIP_DB" ]; then bash "$(dirname "$0")/install-wp-tests.sh" --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" else - bash "$(dirname "$0")/install-wp-tests.sh" bash "$(dirname "$0")/install-wp-tests.sh" --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" --no-db + bash "$(dirname "$0")/install-wp-tests.sh" bash "$(dirname "$0")/install-wp-tests.sh" --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" --skip-db=true fi # Run PHPUnit diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index d583b66..592d247 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -31,7 +31,7 @@ for i in "$@"; do --version=*) WP_VERSION="${i#*=}" ;; - --no-db) + --skip-db=*) SKIP_DB="true" ;; --tmpdir=*) @@ -39,7 +39,7 @@ for i in "$@"; do ;; *) # unknown option - echo "Unknown option: $i. Usage: ./bin/install-wp-tests.sh --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --version=latest --tmpdir=/tmp --no-db" + echo "Unknown option: $i. Usage: ./bin/install-wp-tests.sh --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --version=latest --tmpdir=/tmp --skip-db=true" exit 1 ;; esac diff --git a/bin/phpunit-test.sh b/bin/phpunit-test.sh index bedd2f9..6769aa0 100755 --- a/bin/phpunit-test.sh +++ b/bin/phpunit-test.sh @@ -14,7 +14,7 @@ echo '------------------------------------------' echo "๐Ÿƒโ€โ™‚๏ธ [Run 1]: Running PHPUnit on Single Site" composer phpunit --ansi -bash "${DIRNAME}/install-wp-tests.sh" --dbpass=root --no-db +bash "${DIRNAME}/install-wp-tests.sh" --dbpass=root --skip-db=true echo '------------------------------------------' echo "๐Ÿƒโ€โ™‚๏ธ [Run 2]: Running PHPUnit on Multisite" WP_MULTISITE=1 composer phpunit --ansi @@ -23,7 +23,7 @@ echo "๐Ÿงน Removing files before testing nightly WP..." cleanup echo "๐Ÿค” Installing WP Unit tests with WP nightly version..." -bash "${DIRNAME}/install-wp-tests.sh" --dbpass=root --version=nightly --no-db +bash "${DIRNAME}/install-wp-tests.sh" --dbpass=root --version=nightly --skip-db=true setup_wp_nightly From 21abb07390137f66246a932b6f3d17f1201d832a Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 11:49:03 -0700 Subject: [PATCH 089/144] add right param to composer includes --- src/Plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin.php b/src/Plugin.php index 2bb8116..582422c 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -81,7 +81,7 @@ public function copyBinDirectory() \"scripts\": { \"phpunit\": \"phpunit --do-not-cache-result\", \"test\": \"@phpunit\", - \"test:install\": \"bin/install-local-tests.sh --no-db\", + \"test:install\": \"bin/install-local-tests.sh --skip-db=true\", \"test:install:withdb\": \"bin/install-local-tests.sh\" }"; From c6f45fd0c4fb0f387f67ff9d632fee7b161a777b Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 11:53:50 -0700 Subject: [PATCH 090/144] echo the passed args for debugging --- bin/install-wp-tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 592d247..e040ea7 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -39,6 +39,7 @@ for i in "$@"; do ;; *) # unknown option + echo "Passed args: $@" echo "Unknown option: $i. Usage: ./bin/install-wp-tests.sh --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --version=latest --tmpdir=/tmp --skip-db=true" exit 1 ;; From c8d954007edcae2151cfda46ca0c4f8c2df7d107 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 11:57:45 -0700 Subject: [PATCH 091/144] move the passed args debugging line higher so we can see it for both runs --- bin/install-wp-tests.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index e040ea7..d15b5f5 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -13,6 +13,8 @@ DB_HOST="127.0.0.1" WP_VERSION=${WP_VERSION:-latest} SKIP_DB="" +echo "Passed args: $@" + # Parse command-line arguments for i in "$@"; do case $i in @@ -39,7 +41,6 @@ for i in "$@"; do ;; *) # unknown option - echo "Passed args: $@" echo "Unknown option: $i. Usage: ./bin/install-wp-tests.sh --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --version=latest --tmpdir=/tmp --skip-db=true" exit 1 ;; From 6a326d03049a047da2423bd14123802b3a92dea4 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 12:40:39 -0700 Subject: [PATCH 092/144] move local tests to a script --- .github/workflows/bin/run-local-tests.sh | 8 ++++++++ .github/workflows/test.yml | 9 +++------ 2 files changed, 11 insertions(+), 6 deletions(-) create mode 100755 .github/workflows/bin/run-local-tests.sh diff --git a/.github/workflows/bin/run-local-tests.sh b/.github/workflows/bin/run-local-tests.sh new file mode 100755 index 0000000..080bb8b --- /dev/null +++ b/.github/workflows/bin/run-local-tests.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +echo "Testing latest install..." +mkdir -p "$GITHUB_WORKSPACE"/local_tests +bash "$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir="$GITHUB_WORKSPACE"/local_tests + +echo "Testing nightly install..." +bash "$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh --version=nightly --skip-db=true --tmpdir="$GITHUB_WORKSPACE"/local_tests \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d7d95eb..9284562 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,12 +38,9 @@ jobs: sudo mv wp-cli.phar /usr/local/bin/wp - name: Run local install shell: bash - run: | - echo "Testing latest install..." - mkdir -p ${{ github.workspace }}/local_tests - bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir=${{ github.workspace }}/local_tests - echo "Testing nightly install..." - bash ${{ github.workspace }}/test_proj/bin/install-local-tests.sh --version=nightly --skip-db=true --tmpdir=${{ github.workspace }}/local_tests + env: + GITHUB_WORKSPACE: ${{ github.workspace }} + run: bash ${{ github.workspace }}/.github/workflows/bin/run-local-tests.sh - name: Run PHPUnit Test Install run: bash ${{ github.workspace }}/test_proj/bin/phpunit-test.sh --tmpdir=${{ github.workspace }}/local_tests From 0ddf5b4002ccbb84eb4d9d078af54b8bcf2ff8ab Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 12:42:16 -0700 Subject: [PATCH 093/144] remove the bash --- .github/workflows/bin/run-local-tests.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bin/run-local-tests.sh b/.github/workflows/bin/run-local-tests.sh index 080bb8b..410f47a 100755 --- a/.github/workflows/bin/run-local-tests.sh +++ b/.github/workflows/bin/run-local-tests.sh @@ -1,8 +1,10 @@ #!/bin/bash +set -ex + echo "Testing latest install..." mkdir -p "$GITHUB_WORKSPACE"/local_tests -bash "$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir="$GITHUB_WORKSPACE"/local_tests +"$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir="$GITHUB_WORKSPACE"/local_tests echo "Testing nightly install..." -bash "$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh --version=nightly --skip-db=true --tmpdir="$GITHUB_WORKSPACE"/local_tests \ No newline at end of file +"$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh --version=nightly --skip-db=true --tmpdir="$GITHUB_WORKSPACE"/local_tests \ No newline at end of file From 30fcdfd9679cb86e08ee1c9b35850dc455244b4a Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 12:43:16 -0700 Subject: [PATCH 094/144] run chmod in the script --- .github/workflows/bin/run-local-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bin/run-local-tests.sh b/.github/workflows/bin/run-local-tests.sh index 410f47a..f164f37 100755 --- a/.github/workflows/bin/run-local-tests.sh +++ b/.github/workflows/bin/run-local-tests.sh @@ -1,7 +1,7 @@ #!/bin/bash set -ex - +chmod +x "$GITHUB_WORKSPACE"/bin/*.sh echo "Testing latest install..." mkdir -p "$GITHUB_WORKSPACE"/local_tests "$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir="$GITHUB_WORKSPACE"/local_tests From d019a3e6dcc1d2b3cd53d5e0019aadd6fa3aff5c Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 12:44:19 -0700 Subject: [PATCH 095/144] add permissions --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9284562..c9771da 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,6 +3,9 @@ on: [pull_request] jobs: test: runs-on: ubuntu-latest + permissions: + contents: write + actions: write services: mariadb: image: mariadb:10.6 From 0be1cbc90fbaf9e0c26946316532f6143b7b0cd0 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 12:48:34 -0700 Subject: [PATCH 096/144] bail if the script doesn't exist --- .github/workflows/bin/run-local-tests.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/bin/run-local-tests.sh b/.github/workflows/bin/run-local-tests.sh index f164f37..79d848f 100755 --- a/.github/workflows/bin/run-local-tests.sh +++ b/.github/workflows/bin/run-local-tests.sh @@ -4,6 +4,15 @@ set -ex chmod +x "$GITHUB_WORKSPACE"/bin/*.sh echo "Testing latest install..." mkdir -p "$GITHUB_WORKSPACE"/local_tests + +if [ -f "$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh ]; then + echo "install-local-tests.sh exists, proceeding" +else + echo "install-local-tests.sh does not exist" + ls -la "$GITHUB_WORKSPACE" + exit 1 +fi + "$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir="$GITHUB_WORKSPACE"/local_tests echo "Testing nightly install..." From 2846a4007cbf94d074f5a21bc5b9fd622191485d Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 12:50:31 -0700 Subject: [PATCH 097/144] change the shebang in all the things --- .github/workflows/bin/run-local-tests.sh | 2 +- bin/helpers.sh | 2 +- bin/install-local-tests.sh | 2 +- bin/phpunit-test.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/bin/run-local-tests.sh b/.github/workflows/bin/run-local-tests.sh index 79d848f..a3974c0 100755 --- a/.github/workflows/bin/run-local-tests.sh +++ b/.github/workflows/bin/run-local-tests.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -ex chmod +x "$GITHUB_WORKSPACE"/bin/*.sh diff --git a/bin/helpers.sh b/bin/helpers.sh index 1ccff6a..db3435c 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash download() { if which curl &> /dev/null; then diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index c32a388..7868ba6 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e # shellcheck disable=SC1091 diff --git a/bin/phpunit-test.sh b/bin/phpunit-test.sh index 6769aa0..8bccd11 100755 --- a/bin/phpunit-test.sh +++ b/bin/phpunit-test.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e From 494a35822e1ad41a93e94c1bae19c5a06c11455b Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 12:52:55 -0700 Subject: [PATCH 098/144] handle line ending conversions appropriately --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfdb8b7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.sh text eol=lf From f32a01c32beaa072a6770bfba4bc0754d21de5e7 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 12:56:47 -0700 Subject: [PATCH 099/144] ls the bin folder after the chmod and chmod the right thing --- .github/workflows/bin/run-local-tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bin/run-local-tests.sh b/.github/workflows/bin/run-local-tests.sh index a3974c0..db9e458 100755 --- a/.github/workflows/bin/run-local-tests.sh +++ b/.github/workflows/bin/run-local-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -ex -chmod +x "$GITHUB_WORKSPACE"/bin/*.sh +chmod +x "$GITHUB_WORKSPACE"/test_proj/bin/*.sh echo "Testing latest install..." mkdir -p "$GITHUB_WORKSPACE"/local_tests @@ -9,9 +9,9 @@ if [ -f "$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh ]; then echo "install-local-tests.sh exists, proceeding" else echo "install-local-tests.sh does not exist" - ls -la "$GITHUB_WORKSPACE" exit 1 fi +ls -la "$GITHUB_WORKSPACE"/test_proj/bin "$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir="$GITHUB_WORKSPACE"/local_tests From f3030557aa9d83c783ab65bb21d5c5b346e9dfbb Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 12:58:25 -0700 Subject: [PATCH 100/144] don't bash the script --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c9771da..8cbdb14 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,7 +43,7 @@ jobs: shell: bash env: GITHUB_WORKSPACE: ${{ github.workspace }} - run: bash ${{ github.workspace }}/.github/workflows/bin/run-local-tests.sh + run: ${{ github.workspace }}/.github/workflows/bin/run-local-tests.sh - name: Run PHPUnit Test Install run: bash ${{ github.workspace }}/test_proj/bin/phpunit-test.sh --tmpdir=${{ github.workspace }}/local_tests From 0f1571f102238764d0e82b5ec48521912dc477c4 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 13:04:24 -0700 Subject: [PATCH 101/144] ignore problemmatic things --- bin/install-wp-tests.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index d15b5f5..8112e2b 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -17,6 +17,18 @@ echo "Passed args: $@" # Parse command-line arguments for i in "$@"; do + # Skip 'bash' argument + if [[ $i == "bash" ]]; then + echo "Ignoring 'bash' argument" + continue + fi + + # Skip the script path argument + if [[ $i == "*install-wp-tests.sh" ]]; then + echo "Ignoring script path argument" + continue + fi + case $i in --dbname=*) DB_NAME="${i#*=}" From d786485157abbf4316439c94a469a1a84473ce12 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 13:07:48 -0700 Subject: [PATCH 102/144] remove quotes --- bin/install-wp-tests.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 8112e2b..3590c80 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -13,6 +13,7 @@ DB_HOST="127.0.0.1" WP_VERSION=${WP_VERSION:-latest} SKIP_DB="" +# shellcheck disable=SC2145 echo "Passed args: $@" # Parse command-line arguments @@ -24,7 +25,7 @@ for i in "$@"; do fi # Skip the script path argument - if [[ $i == "*install-wp-tests.sh" ]]; then + if [[ $i == *install-wp-tests.sh ]]; then echo "Ignoring script path argument" continue fi From ed229e00184a0ed08084cf1ee57c2d5082d0aeca Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 13:09:25 -0700 Subject: [PATCH 103/144] force the wp download --- bin/helpers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index db3435c..685beaa 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -38,7 +38,7 @@ download_wp() { fi echo "Downloading WordPress version: ${WP_VERSION} to ${TMPDIR}/wordpress" - wp core download --version="$WP_VERSION" --path="${TMPDIR}/wordpress" + wp core download --version="$WP_VERSION" --path="${TMPDIR}/wordpress" --force } setup_wp() { From 11cafcb404580bc94036716709b49ce3c3dcfedc Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 13:11:21 -0700 Subject: [PATCH 104/144] don't create the wp-config if it exists --- bin/helpers.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 685beaa..3e50551 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -79,9 +79,13 @@ setup_wp() { esac done - download http://api.wordpress.org/core/version-check/1.7/ "$TMPDIR"/wp-latest.json - echo "Creating wp-config.php" - wp config create --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" --dbprefix="wptests_" --path="${TMPDIR}/wordpress" + download http://api.wordpress.org/core/version-check/1.7/ "$TMPDIR"/wp-latest.json + + if [ ! -f "$TMPDIR/wordpress/wp-config.php" ]; then + echo "Creating wp-config.php" + wp config create --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" --dbprefix="wptests_" --path="${TMPDIR}/wordpress" + fi + wp core install --url=localhost --title=Test --admin_user=admin --admin_password=password --admin_email=test@dev.null --path="${TMPDIR}/wordpress" } From 1c22889cdf09580fbac37d51d8488d81f222af66 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 13:14:40 -0700 Subject: [PATCH 105/144] remove debug code and cleanup when the test is done --- .github/workflows/bin/run-local-tests.sh | 10 +++++++--- bin/install-local-tests.sh | 1 - 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/bin/run-local-tests.sh b/.github/workflows/bin/run-local-tests.sh index db9e458..ef20aa3 100755 --- a/.github/workflows/bin/run-local-tests.sh +++ b/.github/workflows/bin/run-local-tests.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash -set -ex +set -e + +source "$GITHUB_WORKSPACE"/bin/helpers.sh + chmod +x "$GITHUB_WORKSPACE"/test_proj/bin/*.sh echo "Testing latest install..." mkdir -p "$GITHUB_WORKSPACE"/local_tests @@ -11,9 +14,10 @@ else echo "install-local-tests.sh does not exist" exit 1 fi -ls -la "$GITHUB_WORKSPACE"/test_proj/bin "$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir="$GITHUB_WORKSPACE"/local_tests echo "Testing nightly install..." -"$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh --version=nightly --skip-db=true --tmpdir="$GITHUB_WORKSPACE"/local_tests \ No newline at end of file +"$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh --version=nightly --skip-db=true --tmpdir="$GITHUB_WORKSPACE"/local_tests + +cleanup \ No newline at end of file diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index 7868ba6..9dfcb8a 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -56,6 +56,5 @@ else fi # Run PHPUnit -pwd echo "Running PHPUnit" composer phpunit From 99d5bc01d934a4293663e761c444c7a5cf173f69 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 13:15:23 -0700 Subject: [PATCH 106/144] move setup stuff to the top --- .github/workflows/test.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8cbdb14..f394ac5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,6 +11,18 @@ jobs: image: mariadb:10.6 steps: - uses: actions/checkout@v4 + - name: Start MySQL + run: | + sudo systemctl start mysql + # Validate that MySQL is running + sudo systemctl status mysql + # Connect to MySQL to test auth. + mysql -e "SELECT 1" -uroot -proot + - name: Install WP-CLI + run: | + curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar + chmod +x wp-cli.phar + sudo mv wp-cli.phar /usr/local/bin/wp - name: Setup barebones project run: | mkdir test_proj && cd test_proj @@ -27,18 +39,6 @@ jobs: 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) echo "โœ… All bin files found" - - name: Start MySQL - run: | - sudo systemctl start mysql - # Validate that MySQL is running - sudo systemctl status mysql - # Connect to MySQL to test auth. - mysql -e "SELECT 1" -uroot -proot - - name: Install WP-CLI - run: | - curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar - chmod +x wp-cli.phar - sudo mv wp-cli.phar /usr/local/bin/wp - name: Run local install shell: bash env: From 5f57ae928f60e7f833f79cb93e83f8d8a87d01e4 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 13:18:19 -0700 Subject: [PATCH 107/144] cleanup on the right thing --- .github/workflows/bin/run-local-tests.sh | 2 +- bin/helpers.sh | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/bin/run-local-tests.sh b/.github/workflows/bin/run-local-tests.sh index ef20aa3..95d7fc8 100755 --- a/.github/workflows/bin/run-local-tests.sh +++ b/.github/workflows/bin/run-local-tests.sh @@ -20,4 +20,4 @@ fi echo "Testing nightly install..." "$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh --version=nightly --skip-db=true --tmpdir="$GITHUB_WORKSPACE"/local_tests -cleanup \ No newline at end of file +cleanup "$GITHUB_WORKSPACE/local_tests" \ No newline at end of file diff --git a/bin/helpers.sh b/bin/helpers.sh index 3e50551..41f325a 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -221,9 +221,10 @@ install_db() { } cleanup() { - WPDIR=${1:-"/tmp/wordpress"} - WP_TESTS_DIR=${2:-"/tmp/wordpress-tests-lib"} - WP_VERSION_JSON=${3:-"/tmp/wp-latest.json"} + TMPDIR=${1:-"/tmp"} + WPDIR=${2:-"$TMPDIR/wordpress"} + WP_TESTS_DIR=${3:-"$TMPDIR/wordpress-tests-lib"} + WP_VERSION_JSON=${4:-"$TMPDIR/wp-latest.json"} wp db reset --yes --path="$WPDIR" rm -rf "$WPDIR" From ec89ba1bc7b1ce92c022dd2512db3196db1b090f Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 13:22:16 -0700 Subject: [PATCH 108/144] add db values as env variables to reset the db --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f394ac5..47b1ab1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,6 +43,10 @@ jobs: shell: bash env: GITHUB_WORKSPACE: ${{ github.workspace }} + DB_NAME: wordpress_test + DB_USER: root + DB_PASS: root + DB_HOST: 127.0.0.1 run: ${{ github.workspace }}/.github/workflows/bin/run-local-tests.sh - name: Run PHPUnit Test Install run: bash ${{ github.workspace }}/test_proj/bin/phpunit-test.sh --tmpdir=${{ github.workspace }}/local_tests From d122ed10dba3201dc8aeba5100a3dc01422dfd75 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 13:22:23 -0700 Subject: [PATCH 109/144] drop the database --- .github/workflows/bin/run-local-tests.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bin/run-local-tests.sh b/.github/workflows/bin/run-local-tests.sh index 95d7fc8..05cd634 100755 --- a/.github/workflows/bin/run-local-tests.sh +++ b/.github/workflows/bin/run-local-tests.sh @@ -15,9 +15,12 @@ else exit 1 fi -"$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh --dbpass=root --tmpdir="$GITHUB_WORKSPACE"/local_tests +"$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh --dbpass="$DB_PASS" --tmpdir="$GITHUB_WORKSPACE"/local_tests echo "Testing nightly install..." "$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh --version=nightly --skip-db=true --tmpdir="$GITHUB_WORKSPACE"/local_tests -cleanup "$GITHUB_WORKSPACE/local_tests" \ No newline at end of file +cleanup "$GITHUB_WORKSPACE/local_tests" +mysql -u"$DB_USER" -p"$DB_PASS" -h"$DB_HOST" -e "DROP DATABASE IF EXISTS \`$DB_NAME\`;" + +echo "Done! โœ…" \ No newline at end of file From c419d4a8fbf4cbd0e43f32afb0af8148ab93414b Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 13:23:55 -0700 Subject: [PATCH 110/144] remove debug code --- bin/install-wp-tests.sh | 2 +- bin/phpunit-test.sh | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 3590c80..50f905b 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -e # shellcheck disable=SC1091 source "$(dirname "$0")/helpers.sh" diff --git a/bin/phpunit-test.sh b/bin/phpunit-test.sh index 8bccd11..4fdc7c7 100755 --- a/bin/phpunit-test.sh +++ b/bin/phpunit-test.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash - set -e # shellcheck disable=SC1091 From 1f9f6b2499b725d6b0d12ffd05263c9353d7876d Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 13:26:04 -0700 Subject: [PATCH 111/144] move test file validation to a script --- .github/workflows/bin/validate-bin-files.sh | 11 +++++++++++ .github/workflows/test.yml | 11 +++-------- 2 files changed, 14 insertions(+), 8 deletions(-) create mode 100755 .github/workflows/bin/validate-bin-files.sh diff --git a/.github/workflows/bin/validate-bin-files.sh b/.github/workflows/bin/validate-bin-files.sh new file mode 100755 index 0000000..25395dc --- /dev/null +++ b/.github/workflows/bin/validate-bin-files.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -e + +cd "$TEST_PROJECT_DIRECTORY" +test -d bin || (echo "โŒ bin directory not found" >&2 && exit 1) +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) +echo "โœ… All bin files found" \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 47b1ab1..89f8321 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,14 +31,9 @@ jobs: composer config allow-plugins.pantheon-systems/wpunit-helpers true composer require --dev pantheon-systems/wpunit-helpers:dev-${{ github.head_ref }} - name: Validate that bin files were copied - run: | - cd ${{ github.workspace }}/test_proj - test -d bin || (echo "โŒ bin directory not found" >&2 && exit 1) - 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) - echo "โœ… All bin files found" + env: + TEST_PROJECT_DIR: ${{ github.workspace }}/test_proj + run: ${{ github.workspace }}/.github/workflows/bin/validate-bin-files.sh - name: Run local install shell: bash env: From 2a5bf86db2467a0c7e43f95ea328d380a357961e Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 13:33:22 -0700 Subject: [PATCH 112/144] add comments to helpers --- bin/helpers.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/helpers.sh b/bin/helpers.sh index 41f325a..3184f93 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash +# Arbitrary download function that uses wget or curl depending on what's available. download() { if which curl &> /dev/null; then curl -s "$1" > "$2"; @@ -11,6 +12,7 @@ download() { fi } +# Download WordPress with wp-cli. Always forces the download of files to overwrite existing ones. download_wp() { TMPDIR="/tmp" WP_VERSION="latest" @@ -41,6 +43,7 @@ download_wp() { wp core download --version="$WP_VERSION" --path="${TMPDIR}/wordpress" --force } +# Sets up WordPress using wp config create (if a wp-config file doesn't already exist) and wp core install. Expects that WordPress is already downloaded. setup_wp() { # Initialize variables with default values TMPDIR="/tmp" @@ -89,6 +92,7 @@ setup_wp() { wp core install --url=localhost --title=Test --admin_user=admin --admin_password=password --admin_email=test@dev.null --path="${TMPDIR}/wordpress" } +# Sets up WordPress nightly version. Uses setup_wp to get WordPress, then installs Gutenberg on the recently installed WordPress site. setup_wp_nightly() { WP_DIR="/tmp/wordpress" @@ -111,6 +115,7 @@ setup_wp_nightly() { wp plugin install gutenberg --activate --path="$WP_DIR" } +# Gets the WordPress version number from the JSON file. If the version is "latest", it will get the latest version from the JSON file. If the version is "nightly", it will return "trunk". get_wp_version_num() { WP_VERSION="latest" TMPDIR="/tmp/wp-latest.json" @@ -144,6 +149,7 @@ get_wp_version_num() { echo "$WP_VERSION" } +# Installs the WordPress test suite over svn. Uses get_wp_version_num to get a version based on what's passed that the svn repository will recognize. install_test_suite() { WP_VERSION=${1:-"latest"} TMPDIR=${2:-"/tmp"} @@ -188,6 +194,7 @@ install_test_suite() { fi } +# Installs the WordPress database. Uses the passed arguments to create a database. install_db() { DB_NAME=${1:-"wordpress_test"} DB_USER=${2:-"root"} @@ -220,6 +227,7 @@ install_db() { mysqladmin create "$DB_NAME" --user="$DB_USER" $EXTRA } +# Deletes all the WordPress files so we can make another pass with a different version. Resets the database to an empty db (but does not drop it). cleanup() { TMPDIR=${1:-"/tmp"} WPDIR=${2:-"$TMPDIR/wordpress"} From aabd8f67d6acf3433d06ef2aeaf8ce4d7a5357a4 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 14:40:20 -0700 Subject: [PATCH 113/144] [major] Update readme --- README.md | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4a46ecf..2458173 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,28 @@ # WPUnit Helpers -[![Lint](https://github.com/pantheon-systems/wpunit-helpers/actions/workflows/lint.yml/badge.svg)](https://github.com/pantheon-systems/wpunit-helpers/actions/workflows/lint.yml) ![GitHub](https://img.shields.io/github/license/pantheon-systems/wpunit-helpers) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/pantheon-systems/wpunit-helpers) [![Unofficial Support](https://img.shields.io/badge/Pantheon-Unofficial%20Support-yellow?logo=pantheon&color=FFDC28)](https://docs.pantheon.io/oss-support-levels#unofficial-support) +[![Lint](https://github.com/pantheon-systems/wpunit-helpers/actions/workflows/lint.yml/badge.svg)](https://github.com/pantheon-systems/wpunit-helpers/actions/workflows/lint.yml) [![Test](https://github.com/pantheon-systems/wpunit-helpers/actions/workflows/test.yml/badge.svg)](https://github.com/pantheon-systems/wpunit-helpers/actions/workflows/test.yml) ![GitHub](https://img.shields.io/github/license/pantheon-systems/wpunit-helpers) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/pantheon-systems/wpunit-helpers) [![Unofficial Support](https://img.shields.io/badge/Pantheon-Unofficial%20Support-yellow?logo=pantheon&color=FFDC28)](https://docs.pantheon.io/oss-support-levels#unofficial-support) -Unified scripts for installing and running automated WP Unit Tests. +Composer plugin providing unified scripts for installing and running automated WP Unit Tests. ## What is this? This is a set of scripts that can be used in a WordPress plugin or theme repository to run automated tests using the WP Unit Test Framework built on top of PHPUnit. The Composer plugin will install these scripts into the dependent project's `bin` directory, allowing you to add helper scripts to your `composer.json`. +This package fundamentally differs from the traditional `install-wp-tests.sh` script that's existed in the WordPress community for many years by removing some of the idiosyncracies of that workflow and replacing them with a WP-CLI-based approach. + +## Requirements +Before using these scripts, you must have the following installed: + +* [Composer](https://getcomposer.org/) +* [WP-CLI](https://wp-cli.org/) + +Additionally, if you intend to run the tests in a CI environment, you will need to have some modern MySQL-compatible database server available (MariaDB, MySQL, etc). + ## What's included? -* `install-wp-tests.sh` - The _de facto_ standard script for installing the WP Unit Test Framework. +* `install-wp-tests.sh` - A standardized script for installing the WP Unit Test Framework. * `install-local-tests.sh` - A helper script for installing WP Unit Tests locally. See [Local Testing](#local-testing) for more information. * `phpunit-test.sh` - A helper script for running WP Unit Tests that is intended for use in CI. +* `helpers.sh` - A collection of helper functions used by the other scripts. ## Installation @@ -28,7 +39,7 @@ On installation, the Composer plugin will copy the scripts into the `bin` direct "scripts": { "phpunit": "phpunit --do-not-cache-result", "test": "@phpunit", - "test:install": "bin/install-local-tests.sh --no-db", + "test:install": "bin/install-local-tests.sh --skip-db=true", "test:install:withdb": "bin/install-local-tests.sh" } } @@ -39,8 +50,8 @@ The `install-local-tests.sh` script is highly configurable to allow for a variet ### Flags -#### `--no-db` -This flag will skip the database creation step. This is useful if you are using a local database that is already set up. +#### `--skip-db` +If set and `true`, this flag will skip the database creation step. This is useful if you are using a local database that is already set up. This replaces the (now deprecated `--no-db` flag). #### `--dbname` This flag will set the name of the database to be created. The default value is `wordpress_test`. @@ -56,3 +67,6 @@ This flag will set the host of the database to be created. The default value is #### `--wpversion` This flag will set the version of WordPress to be installed. The default value is `latest`. Using `nightly` here will use the latest nightly build of WordPress. + +#### `--tmpdir` +This flag will set the temporary directory to be used for the WordPress installation. The default value is `/tmp`. From aa87381b13127ccdeb3346db2430115767b7321b Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 14:42:48 -0700 Subject: [PATCH 114/144] shellcheck the test scripts, too --- .github/workflows/bin/run-local-tests.sh | 1 + composer.json | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/bin/run-local-tests.sh b/.github/workflows/bin/run-local-tests.sh index 05cd634..bbf0be4 100755 --- a/.github/workflows/bin/run-local-tests.sh +++ b/.github/workflows/bin/run-local-tests.sh @@ -2,6 +2,7 @@ set -e +# shellcheck disable=SC1091 source "$GITHUB_WORKSPACE"/bin/helpers.sh chmod +x "$GITHUB_WORKSPACE"/test_proj/bin/*.sh diff --git a/composer.json b/composer.json index e6baa2f..5fef278 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,10 @@ "class": "Pantheon\\WPUnitHelpers\\Plugin" }, "scripts": { - "shellcheck": "shellcheck bin/*", + "shellcheck": [ + "shellcheck bin/*", + "shellcheck .github/workflows/bin/*" + ], "phpcs": "phpcs --standard=PSR2 src/", "phplint": "find src/ -name '*.php' -exec php -l {} \\;", "lint": [ From 87a116b49d19c205c806a7556f3ec258fa09a898 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 15:01:21 -0700 Subject: [PATCH 115/144] fix nightly setup needs to mirror setup_wp because we pass the same parameters along --- bin/helpers.sh | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 3184f93..dcc2236 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -94,22 +94,43 @@ setup_wp() { # Sets up WordPress nightly version. Uses setup_wp to get WordPress, then installs Gutenberg on the recently installed WordPress site. setup_wp_nightly() { - WP_DIR="/tmp/wordpress" + # Initialize variables with default values + TMPDIR="/tmp" + DB_NAME="wordpress_test" + DB_USER="root" + DB_PASS="" + DB_HOST="127.0.0.1" + # Parse command-line arguments for i in "$@"; do case $i in - --wpdir=*) - WP_DIR="${i#*=}" + --dbname=*) + DB_NAME="${i#*=}" + ;; + --dbuser=*) + DB_USER="${i#*=}" + ;; + --dbpass=*) + DB_PASS="${i#*=}" + ;; + --dbhost=*) + DB_HOST="${i#*=}" + ;; + --tmpdir=*) + TMPDIR="${i#*=}" ;; *) # unknown option - echo "Unknown option: $i. Usage: setup_wp_nightly --wpdir=/tmp/wordpress" + echo "Unknown option: $i. Usage: setup_wp --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --version=latest --tmpdir=/tmp" exit 1 ;; esac done - setup_wp --version="nightly" + WP_DIR="$TMPDIR/wordpress" + + setup_wp --version="nightly" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" + # If nightly version of WP is installed, install latest Gutenberg plugin and activate it. echo "Installing Gutenberg plugin" wp plugin install gutenberg --activate --path="$WP_DIR" From f0736fe8358e0cbf3a698c0c53fb50f1df11969e Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 15:01:35 -0700 Subject: [PATCH 116/144] run the nightly install if that's what was requested --- bin/install-wp-tests.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 50f905b..727dabd 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -69,5 +69,11 @@ if [ -z "$SKIP_DB" ]; then fi download_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" -setup_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" + +if [ "$WP_VERSION" == "nightly" ]; then + setup_wp_nightly --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" +else + setup_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" +fi + install_test_suite "$WP_VERSION" "$TMPDIR" "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" From bdfd96eb04cad8e5b34461ad92a42aa67fbc1c30 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 15:44:38 -0700 Subject: [PATCH 117/144] remove passed args debug code --- bin/install-wp-tests.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 727dabd..cce6858 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -13,9 +13,6 @@ DB_HOST="127.0.0.1" WP_VERSION=${WP_VERSION:-latest} SKIP_DB="" -# shellcheck disable=SC2145 -echo "Passed args: $@" - # Parse command-line arguments for i in "$@"; do # Skip 'bash' argument From e036b756b5483fa35556c51dcf0739116b5815b8 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 15:46:00 -0700 Subject: [PATCH 118/144] remove setup_wp_nightly in phpunit-test.sh it's run in install-wp-tests.sh --- bin/phpunit-test.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/bin/phpunit-test.sh b/bin/phpunit-test.sh index 4fdc7c7..01046e0 100755 --- a/bin/phpunit-test.sh +++ b/bin/phpunit-test.sh @@ -24,8 +24,6 @@ cleanup echo "๐Ÿค” Installing WP Unit tests with WP nightly version..." bash "${DIRNAME}/install-wp-tests.sh" --dbpass=root --version=nightly --skip-db=true -setup_wp_nightly - echo '------------------------------------------' echo "๐Ÿƒโ€โ™‚๏ธ [Run 3]: Running PHPUnit on Single Site (Nightly WordPress)" composer phpunit --ansi From c120b211d1e36698b5275e595f138972e9757b06 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 9 Feb 2024 15:47:53 -0700 Subject: [PATCH 119/144] remove gitattributes we probably don't need it --- .gitattributes | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index dfdb8b7..0000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -*.sh text eol=lf From 6e37732446c6913502b0b6d353a7791600b0e4ac Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 12 Feb 2024 15:27:50 -0700 Subject: [PATCH 120/144] remove debug Co-authored-by: Phil Tyler --- .github/workflows/bin/run-local-tests.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/bin/run-local-tests.sh b/.github/workflows/bin/run-local-tests.sh index bbf0be4..5febbd8 100755 --- a/.github/workflows/bin/run-local-tests.sh +++ b/.github/workflows/bin/run-local-tests.sh @@ -9,9 +9,7 @@ chmod +x "$GITHUB_WORKSPACE"/test_proj/bin/*.sh echo "Testing latest install..." mkdir -p "$GITHUB_WORKSPACE"/local_tests -if [ -f "$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh ]; then - echo "install-local-tests.sh exists, proceeding" -else +if [ ! -f "$GITHUB_WORKSPACE"/test_proj/bin/install-local-tests.sh ]; then echo "install-local-tests.sh does not exist" exit 1 fi From 9f6bb3ffb7e8f60cd5dcf7931efa01d4508bb844 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 12 Feb 2024 15:30:06 -0700 Subject: [PATCH 121/144] fix dumb comment thing Co-authored-by: Phil Tyler --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2458173..38a6910 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ The `install-local-tests.sh` script is highly configurable to allow for a variet ### Flags #### `--skip-db` -If set and `true`, this flag will skip the database creation step. This is useful if you are using a local database that is already set up. This replaces the (now deprecated `--no-db` flag). +If set and `true`, this flag will skip the database creation step. This is useful if you are using a local database that is already set up. This replaces the (now deprecated) `--no-db` flag. #### `--dbname` This flag will set the name of the database to be created. The default value is `wordpress_test`. From 45b6d75817b6e7895ff9b4dad0bace9537b5f1d4 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 12 Feb 2024 15:33:55 -0700 Subject: [PATCH 122/144] add missing : Co-authored-by: Phil Tyler --- bin/install-wp-tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index cce6858..cb57dc0 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -57,8 +57,8 @@ for i in "$@"; do esac done -WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} -WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} +WP_TESTS_DIR=${WP_TESTS_DIR:-$TMPDIR/wordpress-tests-lib} +WP_CORE_DIR=${WP_CORE_DIR:-$TMPDIR/wordpress/} # Maybe install the database. if [ -z "$SKIP_DB" ]; then From 32c4371757f46f295aea63504413a5e295adb1b4 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 08:34:09 -0700 Subject: [PATCH 123/144] loop over the files to check --- .github/workflows/bin/validate-bin-files.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/bin/validate-bin-files.sh b/.github/workflows/bin/validate-bin-files.sh index 25395dc..6f14f61 100755 --- a/.github/workflows/bin/validate-bin-files.sh +++ b/.github/workflows/bin/validate-bin-files.sh @@ -2,10 +2,20 @@ set -e +files=( + "bin/install-wp-tests.sh" + "bin/install-local-tests.sh" + "bin/phpunit-test.sh" + "bin/helpers.sh" +) + cd "$TEST_PROJECT_DIRECTORY" test -d bin || (echo "โŒ bin directory not found" >&2 && exit 1) -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) + +for file in "$(files[@])"; do + if ! test -f "$file"; then + echo "โŒ $file not found" >&2 + exit 1 + fi + echo "โœ… All bin files found" \ No newline at end of file From bc4bd7e37d7f8219a8f63efffb41b70c115345cf Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 08:44:38 -0700 Subject: [PATCH 124/144] set variables to local so we don't run into global clashes --- bin/helpers.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index dcc2236..150adde 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -172,14 +172,14 @@ get_wp_version_num() { # Installs the WordPress test suite over svn. Uses get_wp_version_num to get a version based on what's passed that the svn repository will recognize. install_test_suite() { - WP_VERSION=${1:-"latest"} - TMPDIR=${2:-"/tmp"} - DB_NAME=${3:-"wordpress_test"} - DB_USER=${4:-"root"} - DB_PASS=${5:-""} - DB_HOST=${6:-"127.0.0.1"} + local WP_VERSION=${1:-"latest"} + local TMPDIR=${2:-"/tmp"} + local DB_NAME=${3:-"wordpress_test"} + local DB_USER=${4:-"root"} + local DB_PASS=${5:-""} + local DB_HOST=${6:-"127.0.0.1"} + local WP_TESTS_DIR=${WP_TESTS_DIR-"$TMPDIR/wordpress-tests-lib"} WP_VERSION=$(get_wp_version_num --version="$WP_VERSION" --tmpdir="$TMPDIR") - WP_TESTS_DIR=${WP_TESTS_DIR-"$TMPDIR/wordpress-tests-lib"} # If we're using trunk, there is no tests tag. if [ "$WP_VERSION" == "trunk" ]; then @@ -217,10 +217,10 @@ install_test_suite() { # Installs the WordPress database. Uses the passed arguments to create a database. install_db() { - DB_NAME=${1:-"wordpress_test"} - DB_USER=${2:-"root"} - DB_PASS=${3:-""} - DB_HOST=${4:-"127.0.0.1"} + local DB_NAME=${1:-"wordpress_test"} + local DB_USER=${2:-"root"} + local DB_PASS=${3:-""} + local DB_HOST=${4:-"127.0.0.1"} echo "Creating database: $1 on $4..." From 2922922a0f6cba5237edeb1f660c6af1ce061567 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 08:45:06 -0700 Subject: [PATCH 125/144] make the file check test a loop --- .github/workflows/bin/validate-bin-files.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/bin/validate-bin-files.sh b/.github/workflows/bin/validate-bin-files.sh index 6f14f61..408adac 100755 --- a/.github/workflows/bin/validate-bin-files.sh +++ b/.github/workflows/bin/validate-bin-files.sh @@ -12,10 +12,10 @@ files=( cd "$TEST_PROJECT_DIRECTORY" test -d bin || (echo "โŒ bin directory not found" >&2 && exit 1) -for file in "$(files[@])"; do +for file in "${files[@]}"; do if ! test -f "$file"; then - echo "โŒ $file not found" >&2 - exit 1 + echo "โŒ $file not found" >&2 + exit 1 fi - -echo "โœ… All bin files found" \ No newline at end of file +done +echo "โœ… All bin files found" From ae54b816a376fd7fa151513f630c46ea755b6325 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 08:49:36 -0700 Subject: [PATCH 126/144] use string manipulation instead of parsing the string parts before/after the colon --- bin/helpers.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 150adde..2b35be0 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -225,9 +225,9 @@ install_db() { echo "Creating database: $1 on $4..." # 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]}; + local DB_HOSTNAME="${DB_HOST%%:*}" + local DB_SOCK_OR_PORT="${DB_HOST#*:}" + local EXTRA="" if [ -n "$DB_HOSTNAME" ] ; then From ac256c44939d13a34bf1a8e958d7e79ee3517dd9 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 08:53:38 -0700 Subject: [PATCH 127/144] better handling of EXTRA using an array --- bin/helpers.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 2b35be0..7b8cb02 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -228,24 +228,23 @@ install_db() { local DB_HOSTNAME="${DB_HOST%%:*}" local DB_SOCK_OR_PORT="${DB_HOST#*:}" - local EXTRA="" + local EXTRA=(--user="$DB_USER") 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" + EXTRA=(--host="$DB_HOSTNAME" --port="$DB_SOCK_OR_PORT" --protocol=tcp) elif [ -n "$DB_SOCK_OR_PORT" ] ; then - EXTRA=" --socket=$DB_SOCK_OR_PORT" + EXTRA=(--socket="$DB_SOCK_OR_PORT") elif [ -n "$DB_HOSTNAME" ] ; then - EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" + EXTRA=(--host="$DB_HOSTNAME" --protocol=tcp) fi fi if [ -n "$DB_PASS" ] ; then - EXTRA="$EXTRA --password=$DB_PASS" + EXTRA=(--password="$DB_PASS") fi - # shellcheck disable=SC2086 - mysqladmin create "$DB_NAME" --user="$DB_USER" $EXTRA + mysqladmin create "$DB_NAME" "${EXTRA[@]}" } # Deletes all the WordPress files so we can make another pass with a different version. Resets the database to an empty db (but does not drop it). From ef33b523f311b2b6279266906aa84ea75b9f2922 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 08:57:09 -0700 Subject: [PATCH 128/144] add to the EXTRA array rather than overwriting it --- bin/helpers.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 7b8cb02..7fb36c6 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -232,16 +232,16 @@ install_db() { 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) + EXTRA=("${EXTRA[@]}" --host="$DB_HOSTNAME" --port="$DB_SOCK_OR_PORT" --protocol=tcp) elif [ -n "$DB_SOCK_OR_PORT" ] ; then - EXTRA=(--socket="$DB_SOCK_OR_PORT") + EXTRA=("${EXTRA[@]}" --socket="$DB_SOCK_OR_PORT") elif [ -n "$DB_HOSTNAME" ] ; then - EXTRA=(--host="$DB_HOSTNAME" --protocol=tcp) + EXTRA=("${EXTRA[@]}" --host="$DB_HOSTNAME" --protocol=tcp) fi fi if [ -n "$DB_PASS" ] ; then - EXTRA=(--password="$DB_PASS") + EXTRA=("${EXTRA[@]}" --password="$DB_PASS") fi mysqladmin create "$DB_NAME" "${EXTRA[@]}" From 9488b342109ed76bb24089b1216bd919310093ca Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 08:57:31 -0700 Subject: [PATCH 129/144] apply the same logic to bash wp install args --- bin/install-local-tests.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index 9dfcb8a..f7b845c 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -49,12 +49,14 @@ done echo "Installing local tests into ${TMPDIR}" echo "Using WordPress version: ${WP_VERSION}" -if [ -z "$SKIP_DB" ]; then - bash "$(dirname "$0")/install-wp-tests.sh" --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" -else - bash "$(dirname "$0")/install-wp-tests.sh" bash "$(dirname "$0")/install-wp-tests.sh" --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" --skip-db=true +local ARGS=(--version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST") + +if [ -n "$SKIP_DB" ]; then + ARGS=("${ARGS[@]}" --skip-db=true) fi +bash "$(dirname "$0")/install-wp-tests.sh" "${ARGS[@]}" + # Run PHPUnit echo "Running PHPUnit" composer phpunit From fbebdda5c4e14077b1d9bc7d653659f271385d53 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 09:00:24 -0700 Subject: [PATCH 130/144] allow variables to be overridden with env variables --- bin/install-local-tests.sh | 12 ++++++------ bin/install-wp-tests.sh | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index f7b845c..ac1e785 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -5,13 +5,13 @@ set -e source "$(dirname "$0")/helpers.sh" # Initialize variables with default values -TMPDIR="/tmp" -DB_NAME="wordpress_test" -DB_USER="root" -DB_PASS="" -DB_HOST="127.0.0.1" +TMPDIR="${TMPDIR}:-/tmp" +DB_NAME="${DB_NAME}:-wordpress_test" +DB_USER="${DB_USER}:-root" +DB_PASS="${DB_PASS}:-" +DB_HOST="${DB_HOST}:-127.0.0.1" WP_VERSION=${WP_VERSION:-latest} -SKIP_DB="" +SKIP_DB="${SKIP_DB:-}" # Parse command-line arguments for i in "$@"; do diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index cb57dc0..20b1272 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -5,13 +5,13 @@ set -e source "$(dirname "$0")/helpers.sh" # Initialize variables with default values -TMPDIR="/tmp" -DB_NAME="wordpress_test" -DB_USER="root" -DB_PASS="" -DB_HOST="127.0.0.1" +TMPDIR="${TMPDIR}:-/tmp" +DB_NAME="${DB_NAME}:-wordpress_test" +DB_USER="${DB_USER}:-root" +DB_PASS="${DB_PASS}:-" +DB_HOST="${DB_HOST}:-127.0.0.1" WP_VERSION=${WP_VERSION:-latest} -SKIP_DB="" +SKIP_DB="${SKIP_DB}:-" # Parse command-line arguments for i in "$@"; do From bdb2251c02f6e7869b76ae192f8b676576665a56 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 09:02:41 -0700 Subject: [PATCH 131/144] remove local --- bin/install-local-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index ac1e785..4a6c55f 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -49,7 +49,7 @@ done echo "Installing local tests into ${TMPDIR}" echo "Using WordPress version: ${WP_VERSION}" -local ARGS=(--version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST") +ARGS=(--version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST") if [ -n "$SKIP_DB" ]; then ARGS=("${ARGS[@]}" --skip-db=true) From 961b48116d2d71567a8d48ae4f8524df9a66a844 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 09:09:11 -0700 Subject: [PATCH 132/144] add some logging not sure where things are failing exactly --- bin/install-local-tests.sh | 3 ++- bin/install-wp-tests.sh | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index 4a6c55f..477e476 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -11,7 +11,7 @@ DB_USER="${DB_USER}:-root" DB_PASS="${DB_PASS}:-" DB_HOST="${DB_HOST}:-127.0.0.1" WP_VERSION=${WP_VERSION:-latest} -SKIP_DB="${SKIP_DB:-}" +SKIP_DB="" # Parse command-line arguments for i in "$@"; do @@ -52,6 +52,7 @@ echo "Using WordPress version: ${WP_VERSION}" ARGS=(--version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST") if [ -n "$SKIP_DB" ]; then + echo "Skipping database creation" ARGS=("${ARGS[@]}" --skip-db=true) fi diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 20b1272..c1ecf82 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -62,15 +62,21 @@ WP_CORE_DIR=${WP_CORE_DIR:-$TMPDIR/wordpress/} # Maybe install the database. if [ -z "$SKIP_DB" ]; then + echo "Installing database" install_db "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" fi download_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" +SETUP_ARGS=(--version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST") + if [ "$WP_VERSION" == "nightly" ]; then - setup_wp_nightly --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" + echo "Setting up WP nightly" + setup_wp_nightly "${SETUP_ARGS[@]}" else - setup_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" + echo "Setting up WP $WP_VERSION" + setup_wp "${SETUP_ARGS[@]}" fi +echo "Installing WordPress test suite" install_test_suite "$WP_VERSION" "$TMPDIR" "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" From 6687e1ba6b01611c22cfad21f471dc6f2f3c1528 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 09:14:06 -0700 Subject: [PATCH 133/144] turn on debugging so we can see what values were passed in --- bin/install-wp-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index c1ecf82..af4fdc2 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -e +set -ex # shellcheck disable=SC1091 source "$(dirname "$0")/helpers.sh" From b06ab34f68e25e9b8a99ef852d4821db7704e767 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 09:18:06 -0700 Subject: [PATCH 134/144] remove defaults --- bin/install-local-tests.sh | 10 +++++----- bin/install-wp-tests.sh | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index 477e476..40be197 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -5,11 +5,11 @@ set -e source "$(dirname "$0")/helpers.sh" # Initialize variables with default values -TMPDIR="${TMPDIR}:-/tmp" -DB_NAME="${DB_NAME}:-wordpress_test" -DB_USER="${DB_USER}:-root" -DB_PASS="${DB_PASS}:-" -DB_HOST="${DB_HOST}:-127.0.0.1" +TMPDIR="/tmp" +DB_NAME="wordpress_test" +DB_USER="root" +DB_PASS="" +DB_HOST="127.0.0.1" WP_VERSION=${WP_VERSION:-latest} SKIP_DB="" diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index af4fdc2..68495fe 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -5,13 +5,13 @@ set -ex source "$(dirname "$0")/helpers.sh" # Initialize variables with default values -TMPDIR="${TMPDIR}:-/tmp" -DB_NAME="${DB_NAME}:-wordpress_test" -DB_USER="${DB_USER}:-root" -DB_PASS="${DB_PASS}:-" -DB_HOST="${DB_HOST}:-127.0.0.1" +TMPDIR="/tmp" +DB_NAME="wordpress_test" +DB_USER="root" +DB_PASS="" +DB_HOST="127.0.0.1" WP_VERSION=${WP_VERSION:-latest} -SKIP_DB="${SKIP_DB}:-" +SKIP_DB="" # Parse command-line arguments for i in "$@"; do From a6ad13b4631f2d99664b6fe1067519dedb1248b3 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 09:20:57 -0700 Subject: [PATCH 135/144] move debugging to install_db step --- bin/helpers.sh | 1 + bin/install-wp-tests.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 7fb36c6..5fe55da 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -217,6 +217,7 @@ install_test_suite() { # Installs the WordPress database. Uses the passed arguments to create a database. install_db() { + set -x local DB_NAME=${1:-"wordpress_test"} local DB_USER=${2:-"root"} local DB_PASS=${3:-""} diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 68495fe..69d5407 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -e # shellcheck disable=SC1091 source "$(dirname "$0")/helpers.sh" From 6da408fb3df70fc78bb9254a0a733a550039168e Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 09:30:08 -0700 Subject: [PATCH 136/144] revert string manipulation --- bin/helpers.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 5fe55da..d4c8e0b 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -226,9 +226,9 @@ install_db() { echo "Creating database: $1 on $4..." # parse DB_HOST for port or socket references - local DB_HOSTNAME="${DB_HOST%%:*}" - local DB_SOCK_OR_PORT="${DB_HOST#*:}" - + IFS=':' read -ra PARTS <<< "${DB_HOST}" + local DB_HOSTNAME=${PARTS[0]}; + local DB_SOCK_OR_PORT=${PARTS[1]}; local EXTRA=(--user="$DB_USER") if [ -n "$DB_HOSTNAME" ] ; then From aa84ed9f8282846b46ffb8a0f957e71d53a22ac0 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 09:33:42 -0700 Subject: [PATCH 137/144] move the debugging --- bin/helpers.sh | 1 - bin/install-local-tests.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index d4c8e0b..5f77214 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -217,7 +217,6 @@ install_test_suite() { # Installs the WordPress database. Uses the passed arguments to create a database. install_db() { - set -x local DB_NAME=${1:-"wordpress_test"} local DB_USER=${2:-"root"} local DB_PASS=${3:-""} diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index 40be197..76dab33 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -e +set -ex # shellcheck disable=SC1091 source "$(dirname "$0")/helpers.sh" From 59f8bf2e3916df1f6774d6e90cb51c2196107e0a Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 09:38:00 -0700 Subject: [PATCH 138/144] remove debugging --- bin/install-local-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index 76dab33..40be197 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -e # shellcheck disable=SC1091 source "$(dirname "$0")/helpers.sh" From ffc8079076dc59dd04d92ab2f8894c1e0df07ef0 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 09:38:21 -0700 Subject: [PATCH 139/144] remove --version from SETUP_ARGS it's only needed for non-nightly runs --- bin/install-wp-tests.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 69d5407..e71f5e3 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -68,12 +68,13 @@ fi download_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" -SETUP_ARGS=(--version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST") +SETUP_ARGS=(--tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST") if [ "$WP_VERSION" == "nightly" ]; then echo "Setting up WP nightly" setup_wp_nightly "${SETUP_ARGS[@]}" else + SETUP_ARGS=("${SETUP_ARGS[@]}" --version="$WP_VERSION") echo "Setting up WP $WP_VERSION" setup_wp "${SETUP_ARGS[@]}" fi From c8c99d759f96079d2be53b97a5a7baff0f92be1b Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 13:40:38 -0700 Subject: [PATCH 140/144] remove test in loop Co-authored-by: Phil Tyler --- .github/workflows/bin/validate-bin-files.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bin/validate-bin-files.sh b/.github/workflows/bin/validate-bin-files.sh index 408adac..76934dd 100755 --- a/.github/workflows/bin/validate-bin-files.sh +++ b/.github/workflows/bin/validate-bin-files.sh @@ -13,7 +13,7 @@ cd "$TEST_PROJECT_DIRECTORY" test -d bin || (echo "โŒ bin directory not found" >&2 && exit 1) for file in "${files[@]}"; do - if ! test -f "$file"; then + if [[ ! -f "$file" ]]; then echo "โŒ $file not found" >&2 exit 1 fi From 8ed9ff3b220626d5fc0d6ade0075c0ae817c8b6f Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 13:58:29 -0700 Subject: [PATCH 141/144] wrap install-local-tests and install-wp-tests in a function --- bin/install-local-tests.sh | 118 ++++++++++++++++--------------- bin/install-wp-tests.sh | 140 +++++++++++++++++++------------------ 2 files changed, 133 insertions(+), 125 deletions(-) diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh index 40be197..c99cda8 100755 --- a/bin/install-local-tests.sh +++ b/bin/install-local-tests.sh @@ -4,60 +4,64 @@ set -e # shellcheck disable=SC1091 source "$(dirname "$0")/helpers.sh" -# Initialize variables with default values -TMPDIR="/tmp" -DB_NAME="wordpress_test" -DB_USER="root" -DB_PASS="" -DB_HOST="127.0.0.1" -WP_VERSION=${WP_VERSION:-latest} -SKIP_DB="" - -# Parse command-line arguments -for i in "$@"; do - case $i in - --dbname=*) - DB_NAME="${i#*=}" - ;; - --dbuser=*) - DB_USER="${i#*=}" - ;; - --dbpass=*) - DB_PASS="${i#*=}" - ;; - --dbhost=*) - DB_HOST="${i#*=}" - ;; - --version=*) - WP_VERSION="${i#*=}" - ;; - --skip-db=*) - SKIP_DB="true" - ;; - --tmpdir=*) - TMPDIR="${i#*=}" - ;; - *) - # unknown option - echo "Unknown option: $i. Usage: ./bin/install-local-tests.sh --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --version=latest --tmpdir=/tmp --skip-db=true" - exit 1 - ;; - esac -done - -# Run install-wp-tests.sh -echo "Installing local tests into ${TMPDIR}" -echo "Using WordPress version: ${WP_VERSION}" - -ARGS=(--version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST") - -if [ -n "$SKIP_DB" ]; then - echo "Skipping database creation" - ARGS=("${ARGS[@]}" --skip-db=true) -fi - -bash "$(dirname "$0")/install-wp-tests.sh" "${ARGS[@]}" - -# Run PHPUnit -echo "Running PHPUnit" -composer phpunit +main() { + # Initialize variables with default values + local TMPDIR="/tmp" + local DB_NAME="wordpress_test" + local DB_USER="root" + local DB_PASS="" + local DB_HOST="127.0.0.1" + local WP_VERSION=${WP_VERSION:-latest} + local SKIP_DB="" + + # Parse command-line arguments + for i in "$@"; do + case $i in + --dbname=*) + DB_NAME="${i#*=}" + ;; + --dbuser=*) + DB_USER="${i#*=}" + ;; + --dbpass=*) + DB_PASS="${i#*=}" + ;; + --dbhost=*) + DB_HOST="${i#*=}" + ;; + --version=*) + WP_VERSION="${i#*=}" + ;; + --skip-db=*) + SKIP_DB="true" + ;; + --tmpdir=*) + TMPDIR="${i#*=}" + ;; + *) + # unknown option + echo "Unknown option: $i. Usage: ./bin/install-local-tests.sh --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --version=latest --tmpdir=/tmp --skip-db=true" + exit 1 + ;; + esac + done + + # Run install-wp-tests.sh + echo "Installing local tests into ${TMPDIR}" + echo "Using WordPress version: ${WP_VERSION}" + + ARGS=(--version="$WP_VERSION" --tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST") + + if [ -n "$SKIP_DB" ]; then + echo "Skipping database creation" + ARGS=("${ARGS[@]}" --skip-db=true) + fi + + bash "$(dirname "$0")/install-wp-tests.sh" "${ARGS[@]}" + + # Run PHPUnit + echo "Running PHPUnit" + composer phpunit +} + +main "$@" \ No newline at end of file diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index e71f5e3..6a32c5d 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -4,80 +4,84 @@ set -e # shellcheck disable=SC1091 source "$(dirname "$0")/helpers.sh" -# Initialize variables with default values -TMPDIR="/tmp" -DB_NAME="wordpress_test" -DB_USER="root" -DB_PASS="" -DB_HOST="127.0.0.1" -WP_VERSION=${WP_VERSION:-latest} -SKIP_DB="" +main() { + # Initialize variables with default values + local TMPDIR="/tmp" + local DB_NAME="wordpress_test" + local DB_USER="root" + local DB_PASS="" + local DB_HOST="127.0.0.1" + local WP_VERSION=${WP_VERSION:-latest} + local SKIP_DB="" -# Parse command-line arguments -for i in "$@"; do - # Skip 'bash' argument - if [[ $i == "bash" ]]; then - echo "Ignoring 'bash' argument" - continue - fi + # Parse command-line arguments + for i in "$@"; do + # Skip 'bash' argument + if [[ $i == "bash" ]]; then + echo "Ignoring 'bash' argument" + continue + fi - # Skip the script path argument - if [[ $i == *install-wp-tests.sh ]]; then - echo "Ignoring script path argument" - continue - fi + # Skip the script path argument + if [[ $i == *install-wp-tests.sh ]]; then + echo "Ignoring script path argument" + continue + fi - case $i in - --dbname=*) - DB_NAME="${i#*=}" - ;; - --dbuser=*) - DB_USER="${i#*=}" - ;; - --dbpass=*) - DB_PASS="${i#*=}" - ;; - --dbhost=*) - DB_HOST="${i#*=}" - ;; - --version=*) - WP_VERSION="${i#*=}" - ;; - --skip-db=*) - SKIP_DB="true" - ;; - --tmpdir=*) - TMPDIR="${i#*=}" - ;; - *) - # unknown option - echo "Unknown option: $i. Usage: ./bin/install-wp-tests.sh --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --version=latest --tmpdir=/tmp --skip-db=true" - exit 1 - ;; - esac -done + case $i in + --dbname=*) + DB_NAME="${i#*=}" + ;; + --dbuser=*) + DB_USER="${i#*=}" + ;; + --dbpass=*) + DB_PASS="${i#*=}" + ;; + --dbhost=*) + DB_HOST="${i#*=}" + ;; + --version=*) + WP_VERSION="${i#*=}" + ;; + --skip-db=*) + SKIP_DB="true" + ;; + --tmpdir=*) + TMPDIR="${i#*=}" + ;; + *) + # unknown option + echo "Unknown option: $i. Usage: ./bin/install-wp-tests.sh --dbname=wordpress_test --dbuser=root --dbpass=root --dbhost=localhost --version=latest --tmpdir=/tmp --skip-db=true" + exit 1 + ;; + esac + done -WP_TESTS_DIR=${WP_TESTS_DIR:-$TMPDIR/wordpress-tests-lib} -WP_CORE_DIR=${WP_CORE_DIR:-$TMPDIR/wordpress/} + WP_TESTS_DIR=${WP_TESTS_DIR:-$TMPDIR/wordpress-tests-lib} + WP_CORE_DIR=${WP_CORE_DIR:-$TMPDIR/wordpress/} -# Maybe install the database. -if [ -z "$SKIP_DB" ]; then - echo "Installing database" - install_db "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" -fi + # Maybe install the database. + if [ -z "$SKIP_DB" ]; then + echo "Installing database" + install_db "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" + fi -download_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" + download_wp --version="$WP_VERSION" --tmpdir="$TMPDIR" -SETUP_ARGS=(--tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST") + SETUP_ARGS=(--tmpdir="$TMPDIR" --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST") + + if [ "$WP_VERSION" == "nightly" ]; then + echo "Setting up WP nightly" + setup_wp_nightly "${SETUP_ARGS[@]}" + else + SETUP_ARGS=("${SETUP_ARGS[@]}" --version="$WP_VERSION") + echo "Setting up WP $WP_VERSION" + setup_wp "${SETUP_ARGS[@]}" + fi -if [ "$WP_VERSION" == "nightly" ]; then - echo "Setting up WP nightly" - setup_wp_nightly "${SETUP_ARGS[@]}" -else - SETUP_ARGS=("${SETUP_ARGS[@]}" --version="$WP_VERSION") - echo "Setting up WP $WP_VERSION" - setup_wp "${SETUP_ARGS[@]}" -fi + echo "Installing WordPress test suite" + install_test_suite "$WP_VERSION" "$TMPDIR" "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" +} -echo "Installing WordPress test suite" -install_test_suite "$WP_VERSION" "$TMPDIR" "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" +main "$@" From f0f1f3c2ccfedb8747501604228b7c802ba47c96 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 14:05:14 -0700 Subject: [PATCH 142/144] use local variables in all helper functions --- bin/helpers.sh | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/bin/helpers.sh b/bin/helpers.sh index 5f77214..8064c98 100755 --- a/bin/helpers.sh +++ b/bin/helpers.sh @@ -14,8 +14,8 @@ download() { # Download WordPress with wp-cli. Always forces the download of files to overwrite existing ones. download_wp() { - TMPDIR="/tmp" - WP_VERSION="latest" + local TMPDIR="/tmp" + local WP_VERSION="latest" for i in "$@"; do case $i in @@ -46,12 +46,12 @@ download_wp() { # Sets up WordPress using wp config create (if a wp-config file doesn't already exist) and wp core install. Expects that WordPress is already downloaded. setup_wp() { # Initialize variables with default values - TMPDIR="/tmp" - DB_NAME="wordpress_test" - DB_USER="root" - DB_PASS="" - DB_HOST="127.0.0.1" - WP_VERSION=${WP_VERSION:-latest} + local TMPDIR="/tmp" + local DB_NAME="wordpress_test" + local DB_USER="root" + local DB_PASS="" + local DB_HOST="127.0.0.1" + local WP_VERSION=${WP_VERSION:-latest} # Parse command-line arguments for i in "$@"; do @@ -95,11 +95,11 @@ setup_wp() { # Sets up WordPress nightly version. Uses setup_wp to get WordPress, then installs Gutenberg on the recently installed WordPress site. setup_wp_nightly() { # Initialize variables with default values - TMPDIR="/tmp" - DB_NAME="wordpress_test" - DB_USER="root" - DB_PASS="" - DB_HOST="127.0.0.1" + local TMPDIR="/tmp" + local DB_NAME="wordpress_test" + local DB_USER="root" + local DB_PASS="" + local DB_HOST="127.0.0.1" # Parse command-line arguments for i in "$@"; do @@ -138,8 +138,8 @@ setup_wp_nightly() { # Gets the WordPress version number from the JSON file. If the version is "latest", it will get the latest version from the JSON file. If the version is "nightly", it will return "trunk". get_wp_version_num() { - WP_VERSION="latest" - TMPDIR="/tmp/wp-latest.json" + local WP_VERSION="latest" + local TMPDIR="/tmp/wp-latest.json" for i in "$@"; do case $i in @@ -249,10 +249,10 @@ install_db() { # Deletes all the WordPress files so we can make another pass with a different version. Resets the database to an empty db (but does not drop it). cleanup() { - TMPDIR=${1:-"/tmp"} - WPDIR=${2:-"$TMPDIR/wordpress"} - WP_TESTS_DIR=${3:-"$TMPDIR/wordpress-tests-lib"} - WP_VERSION_JSON=${4:-"$TMPDIR/wp-latest.json"} + local TMPDIR=${1:-"/tmp"} + local WPDIR=${2:-"$TMPDIR/wordpress"} + local WP_TESTS_DIR=${3:-"$TMPDIR/wordpress-tests-lib"} + local WP_VERSION_JSON=${4:-"$TMPDIR/wp-latest.json"} wp db reset --yes --path="$WPDIR" rm -rf "$WPDIR" From 1df496ad7e1e48e565d2133c01daad9cce20329e Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 14:10:16 -0700 Subject: [PATCH 143/144] let's put the phpunit-test script in a function, too we don't need to pass args into it because we don't pass args into the script --- bin/phpunit-test.sh | 46 ++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/bin/phpunit-test.sh b/bin/phpunit-test.sh index 01046e0..fd5a6f0 100755 --- a/bin/phpunit-test.sh +++ b/bin/phpunit-test.sh @@ -4,32 +4,36 @@ set -e # shellcheck disable=SC1091 source "$(dirname "$0")/helpers.sh" -DIRNAME=$(dirname "$0") +main() { + local DIRNAME=$(dirname "$0") -echo "๐Ÿค” Installing WP Unit tests..." -bash "${DIRNAME}/install-wp-tests.sh" --dbpass=root + echo "๐Ÿค” Installing WP Unit tests..." + bash "${DIRNAME}/install-wp-tests.sh" --dbpass=root -echo '------------------------------------------' -echo "๐Ÿƒโ€โ™‚๏ธ [Run 1]: Running PHPUnit on Single Site" -composer phpunit --ansi + echo '------------------------------------------' + echo "๐Ÿƒโ€โ™‚๏ธ [Run 1]: Running PHPUnit on Single Site" + composer phpunit --ansi -bash "${DIRNAME}/install-wp-tests.sh" --dbpass=root --skip-db=true -echo '------------------------------------------' -echo "๐Ÿƒโ€โ™‚๏ธ [Run 2]: Running PHPUnit on Multisite" -WP_MULTISITE=1 composer phpunit --ansi + bash "${DIRNAME}/install-wp-tests.sh" --dbpass=root --skip-db=true + echo '------------------------------------------' + echo "๐Ÿƒโ€โ™‚๏ธ [Run 2]: Running PHPUnit on Multisite" + WP_MULTISITE=1 composer phpunit --ansi -echo "๐Ÿงน Removing files before testing nightly WP..." -cleanup + echo "๐Ÿงน Removing files before testing nightly WP..." + cleanup -echo "๐Ÿค” Installing WP Unit tests with WP nightly version..." -bash "${DIRNAME}/install-wp-tests.sh" --dbpass=root --version=nightly --skip-db=true + echo "๐Ÿค” Installing WP Unit tests with WP nightly version..." + bash "${DIRNAME}/install-wp-tests.sh" --dbpass=root --version=nightly --skip-db=true -echo '------------------------------------------' -echo "๐Ÿƒโ€โ™‚๏ธ [Run 3]: Running PHPUnit on Single Site (Nightly WordPress)" -composer phpunit --ansi + echo '------------------------------------------' + echo "๐Ÿƒโ€โ™‚๏ธ [Run 3]: Running PHPUnit on Single Site (Nightly WordPress)" + composer phpunit --ansi -echo '------------------------------------------' -echo "๐Ÿƒโ€โ™‚๏ธ [Run 4]: Running PHPUnit on Multisite (Nightly WordPress)" -WP_MULTISITE=1 composer phpunit --ansi + echo '------------------------------------------' + echo "๐Ÿƒโ€โ™‚๏ธ [Run 4]: Running PHPUnit on Multisite (Nightly WordPress)" + WP_MULTISITE=1 composer phpunit --ansi + + echo "Done! โœ…" +} -echo "Done! โœ…" +main \ No newline at end of file From 3c8fa1a42b964dfb070eb4044ecc2d1ec3c1f0bb Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 13 Feb 2024 14:11:29 -0700 Subject: [PATCH 144/144] fix local DIRNAME for shellcheck --- bin/phpunit-test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/phpunit-test.sh b/bin/phpunit-test.sh index fd5a6f0..0fae608 100755 --- a/bin/phpunit-test.sh +++ b/bin/phpunit-test.sh @@ -5,7 +5,8 @@ set -e source "$(dirname "$0")/helpers.sh" main() { - local DIRNAME=$(dirname "$0") + local DIRNAME + DIRNAME=$(dirname "$0") echo "๐Ÿค” Installing WP Unit tests..." bash "${DIRNAME}/install-wp-tests.sh" --dbpass=root