From 3e077c7f229ebd5c2cb1d6904be9c1ddb397d58f Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Tue, 23 Mar 2021 23:53:42 +0530 Subject: [PATCH 01/74] Add lint workflow --- .github/workflows/lint.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..4dd081a9 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,17 @@ +name: Lint + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: '14' + - run: npm ci + - run: npm run lint \ No newline at end of file From 5fe33756b422ba79765713e27349aef1710bf120 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 00:05:12 +0530 Subject: [PATCH 02/74] Update workflow name --- .github/workflows/{lint.yml => main.yml} | 4 ++-- php/class-plugin.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) rename .github/workflows/{lint.yml => main.yml} (89%) diff --git a/.github/workflows/lint.yml b/.github/workflows/main.yml similarity index 89% rename from .github/workflows/lint.yml rename to .github/workflows/main.yml index 4dd081a9..407293ee 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/main.yml @@ -1,9 +1,9 @@ -name: Lint +name: Lint and Test on: [push] jobs: - build: + lint: runs-on: ubuntu-latest diff --git a/php/class-plugin.php b/php/class-plugin.php index 9d7d8714..076f9a2b 100644 --- a/php/class-plugin.php +++ b/php/class-plugin.php @@ -12,7 +12,8 @@ /** * Main plugin bootstrap file. */ -class Plugin extends Plugin_Base { +class Plugin extends Plugin_Base +{ /** * Sample class. From 0b2efe1393e22157e7fff690aa9cafa3a719819a Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 00:14:37 +0530 Subject: [PATCH 03/74] Add e2e test job --- .github/workflows/main.yml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 407293ee..ce6bbdda 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,9 +4,26 @@ on: [push] jobs: lint: + name: 'Lint' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: '14' + - run: npm ci + - run: npm run lint + test_e2e_latest_coverage: + name: 'E2E tests (PHP 7.4, WordPress latest, with code coverage)' runs-on: ubuntu-latest + env: + NODE_ENV: e2e + WP_VERSION: latest + steps: - uses: actions/checkout@v2 - name: Use Node.js @@ -14,4 +31,8 @@ jobs: with: node-version: '14' - run: npm ci - - run: npm run lint \ No newline at end of file + - run: npm run env:start + - run: npm run wp -- wp core install --title=WordPress --admin_user=admin --admin_password=password --admin_email=admin@example.com --skip-email --url=http://localhost:8088 --quiet + - run: npm run wp -- wp plugin activate foo-bar + - run: npm run build:js + - run: npm run test:e2e:coveralls From 8e9ad2e25dfc6ddf882ad182afe84e497803c67f Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 00:18:51 +0530 Subject: [PATCH 04/74] Add lint job as dep for test jobs --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ce6bbdda..02c862e1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,6 +17,7 @@ jobs: - run: npm run lint test_e2e_latest_coverage: + needs: [lint] name: 'E2E tests (PHP 7.4, WordPress latest, with code coverage)' runs-on: ubuntu-latest From c5a3bd0409eb17c92c485085d593fa23ff1e5025 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 00:21:02 +0530 Subject: [PATCH 05/74] Fix lint issue --- php/class-plugin.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/php/class-plugin.php b/php/class-plugin.php index 076f9a2b..9d7d8714 100644 --- a/php/class-plugin.php +++ b/php/class-plugin.php @@ -12,8 +12,7 @@ /** * Main plugin bootstrap file. */ -class Plugin extends Plugin_Base -{ +class Plugin extends Plugin_Base { /** * Sample class. From ce454aa219afc0c3932f5e65a155e2ac319f7ccf Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 00:39:21 +0530 Subject: [PATCH 06/74] Disable TTY allocation --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d0646927..05c97c18 100755 --- a/package.json +++ b/package.json @@ -139,7 +139,7 @@ "test:js:coverage-merge": "node tests/merge-coverage.js --reporter=lcov", "test:php": "composer test", "test:php:coverage": "composer test-coverage", - "wp": "docker-compose exec -u xfs cli", + "wp": "docker-compose exec -T -u xfs cli", "xdebug:status": "bin/xdebug.sh status", "xdebug:on": "bin/xdebug.sh on", "xdebug:off": "bin/xdebug.sh off" From 3d4edb1fa940b7c9c02ae9fa88f4e4f9f55c5045 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 00:51:11 +0530 Subject: [PATCH 07/74] Add PHP tets job --- .github/workflows/main.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 02c862e1..869d33db 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,6 +2,9 @@ name: Lint and Test on: [push] +env: + DEV_LIB_PATH: vendor/xwp/wp-dev-lib/scripts + jobs: lint: name: 'Lint' @@ -37,3 +40,18 @@ jobs: - run: npm run wp -- wp plugin activate foo-bar - run: npm run build:js - run: npm run test:e2e:coveralls + + test_php_latest_coverage: + needs: [lint] + name: 'PHP tests (PHP 7.4, WordPress latest, with code coverage)' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Setup PHP 7.4 + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: phpunit + - run: source "$DEV_LIB_PATH/travis.install.sh" + - run: source "$DEV_LIB_PATH/travis.script.sh" From 61f908aab28395de0bf8f676eb298c6ab2829cf4 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 01:03:16 +0530 Subject: [PATCH 08/74] Add compser install step --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 869d33db..c41db046 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -53,5 +53,6 @@ jobs: with: php-version: '7.4' tools: phpunit + - run: composer install - run: source "$DEV_LIB_PATH/travis.install.sh" - run: source "$DEV_LIB_PATH/travis.script.sh" From 3a6314a3c1c8a8e4fc4da50a108816522692ce13 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 01:52:30 +0530 Subject: [PATCH 09/74] Add env vars --- .github/workflows/main.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c41db046..1e0a5d69 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,6 +4,7 @@ on: [push] env: DEV_LIB_PATH: vendor/xwp/wp-dev-lib/scripts + DIFF_HEAD: HEAD jobs: lint: @@ -46,6 +47,10 @@ jobs: name: 'PHP tests (PHP 7.4, WordPress latest, with code coverage)' runs-on: ubuntu-latest + env: + WP_VERSION: latest + DEV_LIB_ONLY: phpunit,coverage + steps: - uses: actions/checkout@v2 - name: Setup PHP 7.4 From 4833fb5aba9437e11032189e82c5828b9847e818 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 01:58:32 +0530 Subject: [PATCH 10/74] Remove DIFF_HEAD and add env debug step --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1e0a5d69..8fdb61a2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,7 +4,6 @@ on: [push] env: DEV_LIB_PATH: vendor/xwp/wp-dev-lib/scripts - DIFF_HEAD: HEAD jobs: lint: @@ -31,6 +30,7 @@ jobs: steps: - uses: actions/checkout@v2 + - uses: hmarr/debug-action@v2 - name: Use Node.js uses: actions/setup-node@v1 with: From 4e7b4d860e66207a707052cefa0488ae8b84a213 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 13:44:18 +0530 Subject: [PATCH 11/74] Update js and e2e coveralls steps --- .github/workflows/main.yml | 61 ++++++++++++++++++++++++++++---------- package.json | 5 ++-- 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8fdb61a2..e380592c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,18 +19,19 @@ jobs: - run: npm ci - run: npm run lint - test_e2e_latest_coverage: + test-e2e-coverage: needs: [lint] name: 'E2E tests (PHP 7.4, WordPress latest, with code coverage)' runs-on: ubuntu-latest env: NODE_ENV: e2e - WP_VERSION: latest + WP_VERSION: 5.7 steps: - uses: actions/checkout@v2 - uses: hmarr/debug-action@v2 + - name: Use Node.js uses: actions/setup-node@v1 with: @@ -40,24 +41,52 @@ jobs: - run: npm run wp -- wp core install --title=WordPress --admin_user=admin --admin_password=password --admin_email=admin@example.com --skip-email --url=http://localhost:8088 --quiet - run: npm run wp -- wp plugin activate foo-bar - run: npm run build:js - - run: npm run test:e2e:coveralls + - run: npm run test:e2e:coverage + + - name: Coveralls + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: ./tests/coverage/e2e/lcov.info - test_php_latest_coverage: + test-js-coverage: needs: [lint] - name: 'PHP tests (PHP 7.4, WordPress latest, with code coverage)' + name: 'JS unit tests (with code coverage)' runs-on: ubuntu-latest - env: - WP_VERSION: latest - DEV_LIB_ONLY: phpunit,coverage - steps: - uses: actions/checkout@v2 - - name: Setup PHP 7.4 - uses: shivammathur/setup-php@v2 + - uses: hmarr/debug-action@v2 + + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: '14' + - run: npm ci + - run: npm run test:js:coverage + + - name: Coveralls + uses: coverallsapp/github-action@master with: - php-version: '7.4' - tools: phpunit - - run: composer install - - run: source "$DEV_LIB_PATH/travis.install.sh" - - run: source "$DEV_LIB_PATH/travis.script.sh" + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: ./tests/coverage/js/lcov.info + + # test_php_latest_coverage: + # needs: [lint] + # name: 'PHP tests (PHP 7.4, WordPress latest, with code coverage)' + # runs-on: ubuntu-latest + + # env: + # WP_VERSION: latest + # DEV_LIB_ONLY: phpunit,coverage + + # steps: + # - uses: actions/checkout@v2 + # - name: Setup PHP 7.4 + # uses: shivammathur/setup-php@v2 + # with: + # php-version: '7.4' + # tools: phpunit + # - run: composer install + # - run: source "$DEV_LIB_PATH/travis.install.sh" + # - run: source "$DEV_LIB_PATH/travis.script.sh" diff --git a/package.json b/package.json index 05c97c18..5db99716 100755 --- a/package.json +++ b/package.json @@ -128,13 +128,12 @@ "test:e2e:watch": "npm run test:e2e -- --watch", "test:e2e:interactive": "npm run test:e2e -- --puppeteer-interactive", "test:e2e:ci": "npm run test:e2e -- --runInBand", - "test:e2e:coverage": "npm run test:e2e -- --coverage --coverageDirectory=tests/coverage/e2e", - "test:e2e:coveralls": "npm run test:e2e:coverage -- --runInBand --coverageReporters=json && npm run test:js:coverage-merge -- --no-js --reporter=text-lcov | coveralls", + "test:e2e:coverage": "npm run test:e2e -- --coverage --coverageReporters=lcov --coverageDirectory=tests/coverage/e2e", + "test:e2e:coveralls": "npm run test:e2e:coverage -- --runInBand --coverageReporters=json && npm run test:js:coverage-merge -- --no-js --reporter=text-lcov", "test:js": "wp-scripts test-unit-js tests/js", "test:js:help": "wp-scripts test-unit-js --help", "test:js:watch": "npm run test:js -- --watch", "test:js:coverage": "wp-scripts test-unit-js --coverage --coverageDirectory=tests/coverage/js", - "test:js:coveralls": "npm run test:js:coverage && coveralls < tests/coverage/js/lcov.info", "test:js:coverage-all": "run-s \"test:js:coverage -- --coverageReporters=json {@}\" \"test:e2e:coverage -- --coverageReporters=json {@}\" test:js:coverage-merge --", "test:js:coverage-merge": "node tests/merge-coverage.js --reporter=lcov", "test:php": "composer test", From 1abd9f905bad0c652cf7ba9edf19f84215d6e971 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 14:15:55 +0530 Subject: [PATCH 12/74] Set coveralls to parallel --- .github/workflows/main.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e380592c..b734da1e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -48,6 +48,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} path-to-lcov: ./tests/coverage/e2e/lcov.info + parallel: true test-js-coverage: needs: [lint] @@ -70,6 +71,17 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} path-to-lcov: ./tests/coverage/js/lcov.info + parallel: true + + finish: + needs: [test-e2e-coverage, test-js-coverage] + runs-on: ubuntu-latest + steps: + - name: Coveralls Finished + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.github_token }} + parallel-finished: true # test_php_latest_coverage: # needs: [lint] From 82163aa580d5dad6dc52f9126ddb825d4563da93 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 16:56:54 +0530 Subject: [PATCH 13/74] Add PHP Unittest job --- .github/workflows/main.yml | 39 +++++----- bin/install-wp-tests.sh | 154 +++++++++++++++++++++++++++++++++++++ 2 files changed, 173 insertions(+), 20 deletions(-) create mode 100644 bin/install-wp-tests.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b734da1e..78f19d1e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -73,6 +73,25 @@ jobs: path-to-lcov: ./tests/coverage/js/lcov.info parallel: true + test-php-coverage: + needs: [lint] + name: 'PHP tests (PHP 7.4, WordPress latest, with code coverage)' + runs-on: ubuntu-latest + + env: + WP_VERSION: latest + + steps: + - uses: actions/checkout@v2 + - name: Setup PHP 7.4 + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: phpunit + - run: composer install + - run: source "bin/install-wp-tests.sh" + - run: composer test + finish: needs: [test-e2e-coverage, test-js-coverage] runs-on: ubuntu-latest @@ -82,23 +101,3 @@ jobs: with: github-token: ${{ secrets.github_token }} parallel-finished: true - - # test_php_latest_coverage: - # needs: [lint] - # name: 'PHP tests (PHP 7.4, WordPress latest, with code coverage)' - # runs-on: ubuntu-latest - - # env: - # WP_VERSION: latest - # DEV_LIB_ONLY: phpunit,coverage - - # steps: - # - uses: actions/checkout@v2 - # - name: Setup PHP 7.4 - # uses: shivammathur/setup-php@v2 - # with: - # php-version: '7.4' - # tools: phpunit - # - run: composer install - # - run: source "$DEV_LIB_PATH/travis.install.sh" - # - run: source "$DEV_LIB_PATH/travis.script.sh" diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh new file mode 100644 index 00000000..17c29ed2 --- /dev/null +++ b/bin/install-wp-tests.sh @@ -0,0 +1,154 @@ +#!/usr/bin/env bash + +if [ $# -lt 3 ]; then + echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" + 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} +TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") + +export WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} +export 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 + 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 '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json + 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 -x + +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 https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes + svn co --quiet 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" + elif ! [ -z $DB_SOCK_OR_PORT ] ; then + EXTRA=" --socket=$DB_SOCK_OR_PORT" + elif ! [ -z $DB_HOSTNAME ] ; then + EXTRA=" --host=$DB_HOSTNAME" + fi + fi + + # create database + mysqladmin -f drop $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA + mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA +} + +install_wp +install_test_suite +install_db From a01e1b505a9101ea66b8b3446406621d8012b1c4 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 17:04:01 +0530 Subject: [PATCH 14/74] Update phpunit test command --- .github/workflows/main.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 78f19d1e..ad756f7b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -81,6 +81,16 @@ jobs: env: WP_VERSION: latest + services: + mysql: + image: mysql:5.7 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: wordpress_test + ports: + - 3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + steps: - uses: actions/checkout@v2 - name: Setup PHP 7.4 @@ -89,7 +99,7 @@ jobs: php-version: '7.4' tools: phpunit - run: composer install - - run: source "bin/install-wp-tests.sh" + - run: source bin/install-wp-tests.sh wordpress_test root root localhost latest - run: composer test finish: From 34a642156bf26a02a45b3e535d72d2837323279e Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 17:15:47 +0530 Subject: [PATCH 15/74] Add debug/print statements --- bin/install-wp-tests.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 17c29ed2..45162c75 100644 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -18,6 +18,9 @@ TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") export WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} export WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} +echo "WP_TESTS_DIR is $WP_TESTS_DIR" +echo "WP_CORE_DIR is $WP_CORE_DIR" + download() { if [ `which curl` ]; then curl -s "$1" > "$2"; @@ -59,6 +62,8 @@ install_wp() { mkdir -p $WP_CORE_DIR + echo "Installing WP to $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 @@ -90,6 +95,8 @@ install_wp() { tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR fi + echo "WP installed to $WP_CORE_DIR" + download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php } @@ -101,6 +108,8 @@ install_test_suite() { local ioption='-i' fi + echo "Installing Tests to $WP_TESTS_DIR" + # set up testing suite if it doesn't yet exist if [ ! -d $WP_TESTS_DIR ]; then # set up testing suite @@ -119,7 +128,7 @@ 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 - + echo "Tests installed to $WP_TESTS_DIR" } install_db() { From 15448c31fdac7f080189a3f07389e66e4110679b Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 17:23:02 +0530 Subject: [PATCH 16/74] Add more print statements --- bin/install-wp-tests.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 45162c75..822c07fd 100644 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -x + if [ $# -lt 3 ]; then echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" exit 1 @@ -26,6 +28,9 @@ download() { curl -s "$1" > "$2"; elif [ `which wget` ]; then wget -nv -O "$2" "$1" + else + echo 'wget or curl not found' + return 1 fi } @@ -52,7 +57,7 @@ else WP_TESTS_TAG="tags/$LATEST_VERSION" fi -set -x +echo "WP_TESTS_TAG is $WP_TESTS_TAG" install_wp() { From 1854e26c42a503dbca84d5bc092e683ba6bfee6b Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 17:31:35 +0530 Subject: [PATCH 17/74] Add more print statements --- 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 822c07fd..ee561e8c 100644 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -24,6 +24,7 @@ echo "WP_TESTS_DIR is $WP_TESTS_DIR" echo "WP_CORE_DIR is $WP_CORE_DIR" download() { + echo "Download $1 to $2" if [ `which curl` ]; then curl -s "$1" > "$2"; elif [ `which wget` ]; then From 8e472095021d3aaba6e85b7124388025ecb542d5 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 17:37:02 +0530 Subject: [PATCH 18/74] Remove failing grep --- .github/workflows/main.yml | 1 + bin/install-wp-tests.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ad756f7b..ddcec9f1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -104,6 +104,7 @@ jobs: finish: needs: [test-e2e-coverage, test-js-coverage] + name: Finish runs-on: ubuntu-latest steps: - name: Coveralls Finished diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index ee561e8c..88336900 100644 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -49,7 +49,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 + 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 43a5a685042d8513d5db2ecfc2ad04d36c832fe3 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 17:50:42 +0530 Subject: [PATCH 19/74] Add mysql port --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ddcec9f1..69af9870 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -99,7 +99,7 @@ jobs: php-version: '7.4' tools: phpunit - run: composer install - - run: source bin/install-wp-tests.sh wordpress_test root root localhost latest + - run: source bin/install-wp-tests.sh wordpress_test root root localhost:${{ job.services.mysql.ports[3306] }} latest - run: composer test finish: From 35ecf9538cb3cbe43b64a2826e23ed71968318c4 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 17:51:36 +0530 Subject: [PATCH 20/74] Disable all jobs except phpunit --- .github/workflows/main.yml | 174 ++++++++++++++++++------------------- 1 file changed, 87 insertions(+), 87 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 69af9870..8be067cc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,72 +6,72 @@ env: DEV_LIB_PATH: vendor/xwp/wp-dev-lib/scripts jobs: - lint: - name: 'Lint' - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Use Node.js - uses: actions/setup-node@v1 - with: - node-version: '14' - - run: npm ci - - run: npm run lint - - test-e2e-coverage: - needs: [lint] - name: 'E2E tests (PHP 7.4, WordPress latest, with code coverage)' - runs-on: ubuntu-latest - - env: - NODE_ENV: e2e - WP_VERSION: 5.7 - - steps: - - uses: actions/checkout@v2 - - uses: hmarr/debug-action@v2 - - - name: Use Node.js - uses: actions/setup-node@v1 - with: - node-version: '14' - - run: npm ci - - run: npm run env:start - - run: npm run wp -- wp core install --title=WordPress --admin_user=admin --admin_password=password --admin_email=admin@example.com --skip-email --url=http://localhost:8088 --quiet - - run: npm run wp -- wp plugin activate foo-bar - - run: npm run build:js - - run: npm run test:e2e:coverage - - - name: Coveralls - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ./tests/coverage/e2e/lcov.info - parallel: true - - test-js-coverage: - needs: [lint] - name: 'JS unit tests (with code coverage)' - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - uses: hmarr/debug-action@v2 - - - name: Use Node.js - uses: actions/setup-node@v1 - with: - node-version: '14' - - run: npm ci - - run: npm run test:js:coverage - - - name: Coveralls - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ./tests/coverage/js/lcov.info - parallel: true + # lint: + # name: 'Lint' + # runs-on: ubuntu-latest + + # steps: + # - uses: actions/checkout@v2 + # - name: Use Node.js + # uses: actions/setup-node@v1 + # with: + # node-version: '14' + # - run: npm ci + # - run: npm run lint + + # test-e2e-coverage: + # needs: [lint] + # name: 'E2E tests (PHP 7.4, WordPress latest, with code coverage)' + # runs-on: ubuntu-latest + + # env: + # NODE_ENV: e2e + # WP_VERSION: 5.7 + + # steps: + # - uses: actions/checkout@v2 + # - uses: hmarr/debug-action@v2 + + # - name: Use Node.js + # uses: actions/setup-node@v1 + # with: + # node-version: '14' + # - run: npm ci + # - run: npm run env:start + # - run: npm run wp -- wp core install --title=WordPress --admin_user=admin --admin_password=password --admin_email=admin@example.com --skip-email --url=http://localhost:8088 --quiet + # - run: npm run wp -- wp plugin activate foo-bar + # - run: npm run build:js + # - run: npm run test:e2e:coverage + + # - name: Coveralls + # uses: coverallsapp/github-action@master + # with: + # github-token: ${{ secrets.GITHUB_TOKEN }} + # path-to-lcov: ./tests/coverage/e2e/lcov.info + # parallel: true + + # test-js-coverage: + # needs: [lint] + # name: 'JS unit tests (with code coverage)' + # runs-on: ubuntu-latest + + # steps: + # - uses: actions/checkout@v2 + # - uses: hmarr/debug-action@v2 + + # - name: Use Node.js + # uses: actions/setup-node@v1 + # with: + # node-version: '14' + # - run: npm ci + # - run: npm run test:js:coverage + + # - name: Coveralls + # uses: coverallsapp/github-action@master + # with: + # github-token: ${{ secrets.GITHUB_TOKEN }} + # path-to-lcov: ./tests/coverage/js/lcov.info + # parallel: true test-php-coverage: needs: [lint] @@ -91,24 +91,24 @@ jobs: - 3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - steps: - - uses: actions/checkout@v2 - - name: Setup PHP 7.4 - uses: shivammathur/setup-php@v2 - with: - php-version: '7.4' - tools: phpunit - - run: composer install - - run: source bin/install-wp-tests.sh wordpress_test root root localhost:${{ job.services.mysql.ports[3306] }} latest - - run: composer test - - finish: - needs: [test-e2e-coverage, test-js-coverage] - name: Finish - runs-on: ubuntu-latest - steps: - - name: Coveralls Finished - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.github_token }} - parallel-finished: true + # steps: + # - uses: actions/checkout@v2 + # - name: Setup PHP 7.4 + # uses: shivammathur/setup-php@v2 + # with: + # php-version: '7.4' + # tools: phpunit + # - run: composer install + # - run: source bin/install-wp-tests.sh wordpress_test root root localhost:${{ job.services.mysql.ports[3306] }} latest + # - run: composer test + + # finish: + # needs: [test-e2e-coverage, test-js-coverage] + # name: Finish + # runs-on: ubuntu-latest + # steps: + # - name: Coveralls Finished + # uses: coverallsapp/github-action@master + # with: + # github-token: ${{ secrets.github_token }} + # parallel-finished: true From 46692d4dbd13fc7db79829c8cb12268924b34427 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 17:52:37 +0530 Subject: [PATCH 21/74] Fix incorrect job steps --- .github/workflows/main.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8be067cc..ac480d90 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -91,16 +91,16 @@ jobs: - 3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - # steps: - # - uses: actions/checkout@v2 - # - name: Setup PHP 7.4 - # uses: shivammathur/setup-php@v2 - # with: - # php-version: '7.4' - # tools: phpunit - # - run: composer install - # - run: source bin/install-wp-tests.sh wordpress_test root root localhost:${{ job.services.mysql.ports[3306] }} latest - # - run: composer test + steps: + - uses: actions/checkout@v2 + - name: Setup PHP 7.4 + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: phpunit + - run: composer install + - run: source bin/install-wp-tests.sh wordpress_test root root localhost:${{ job.services.mysql.ports[3306] }} latest + - run: composer test # finish: # needs: [test-e2e-coverage, test-js-coverage] From dc3d12b16dec34a77b62783c3a389b092dbb25ee Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 17:53:14 +0530 Subject: [PATCH 22/74] Remove lint dep --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ac480d90..3dfdb517 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -74,7 +74,7 @@ jobs: # parallel: true test-php-coverage: - needs: [lint] + # needs: [lint] name: 'PHP tests (PHP 7.4, WordPress latest, with code coverage)' runs-on: ubuntu-latest From 1c7ec0c5bb5abfe039b09cf70d51e586298548cc Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 17:58:24 +0530 Subject: [PATCH 23/74] Use default mysql service in the ubuntu image --- .github/workflows/main.yml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3dfdb517..7a4d5340 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -81,15 +81,15 @@ jobs: env: WP_VERSION: latest - services: - mysql: - image: mysql:5.7 - env: - MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: wordpress_test - ports: - - 3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + # services: + # mysql: + # image: mysql:5 + # env: + # MYSQL_ROOT_PASSWORD: root + # MYSQL_DATABASE: wordpress_test + # ports: + # - 3306 + # options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 steps: - uses: actions/checkout@v2 @@ -98,6 +98,8 @@ jobs: with: php-version: '7.4' tools: phpunit + - run: sudo systemctl enable mysql.service + - run: sudo systemctl start mysql.service - run: composer install - run: source bin/install-wp-tests.sh wordpress_test root root localhost:${{ job.services.mysql.ports[3306] }} latest - run: composer test From f86cf1a4f16a5a4f5b9ccdeaa5f04c702cdb04f8 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 18:01:49 +0530 Subject: [PATCH 24/74] Update mysql port and remove DB drop command --- .github/workflows/main.yml | 2 +- bin/install-wp-tests.sh | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7a4d5340..4e9434fb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -101,7 +101,7 @@ jobs: - run: sudo systemctl enable mysql.service - run: sudo systemctl start mysql.service - run: composer install - - run: source bin/install-wp-tests.sh wordpress_test root root localhost:${{ job.services.mysql.ports[3306] }} latest + - run: source bin/install-wp-tests.sh wordpress_test root root localhost latest - run: composer test # finish: diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 88336900..7f59e18b 100644 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -160,8 +160,7 @@ install_db() { fi # create database - mysqladmin -f drop $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA - mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA + mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA || true } install_wp From a7b0177d974d740380ce3c7115f6d3e5a8aa741f Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 18:03:43 +0530 Subject: [PATCH 25/74] Print MySQL version --- 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 7f59e18b..8ee106a5 100644 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -138,6 +138,7 @@ install_test_suite() { } install_db() { + $(echo mysql -V) if [ ${SKIP_DB_CREATE} = "true" ]; then return 0 From 8c89a8d206b51123f21ddbab128a2dac6fd01ee1 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 18:07:08 +0530 Subject: [PATCH 26/74] Update tests dir --- tests/bootstrap.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d301b43c..eff868e5 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -17,6 +17,11 @@ $_tests_dir = '/tmp/wordpress-tests'; } +// Github Actions tests directory. +if ( ! is_dir( $_tests_dir . '/includes/' ) ) { + $_tests_dir = '/tmp/wordpress/tests/phpunit'; +} + // Composer tests directory. if ( ! is_dir( $_tests_dir . '/includes/' ) ) { $_tests_dir = $_plugin_root . '/vendor/xwp/wordpress-tests/phpunit'; From 99e4ccc383877f6a7032637494ec578575924661 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 18:15:12 +0530 Subject: [PATCH 27/74] Add phpunit bootstrap debug print statements --- tests/bootstrap.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index eff868e5..e9c94f2d 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -11,22 +11,22 @@ $_plugin_root = realpath( __DIR__ . '/..' ); $_tests_dir = getenv( 'WP_TESTS_DIR' ); - +print_r( $_tests_dir . "\n" ); // Travis CI & Vagrant SSH tests directory. if ( empty( $_tests_dir ) ) { $_tests_dir = '/tmp/wordpress-tests'; } - +print_r( $_tests_dir . "\n" ); // Github Actions tests directory. if ( ! is_dir( $_tests_dir . '/includes/' ) ) { $_tests_dir = '/tmp/wordpress/tests/phpunit'; } - +print_r( $_tests_dir . "\n" ); // Composer tests directory. if ( ! is_dir( $_tests_dir . '/includes/' ) ) { $_tests_dir = $_plugin_root . '/vendor/xwp/wordpress-tests/phpunit'; } - +print_r( $_tests_dir . "\n" ); if ( ! file_exists( $_tests_dir . '/includes/' ) ) { trigger_error( 'Unable to locate wordpress-tests', E_USER_ERROR ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error } From 3c04a2c32cc590948c6016cdf8f1c82286d32eba Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 18:19:32 +0530 Subject: [PATCH 28/74] Update default WP_TESTS_DIR path --- bin/install-wp-tests.sh | 2 +- tests/bootstrap.php | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 8ee106a5..f7485a27 100644 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -17,7 +17,7 @@ SKIP_DB_CREATE=${6-false} TMPDIR=${TMPDIR-/tmp} TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") -export WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} +export WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests} export WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} echo "WP_TESTS_DIR is $WP_TESTS_DIR" diff --git a/tests/bootstrap.php b/tests/bootstrap.php index e9c94f2d..49022a16 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -12,16 +12,11 @@ $_tests_dir = getenv( 'WP_TESTS_DIR' ); print_r( $_tests_dir . "\n" ); -// Travis CI & Vagrant SSH tests directory. +// Github Actions, Travis CI & Vagrant SSH tests directory. if ( empty( $_tests_dir ) ) { $_tests_dir = '/tmp/wordpress-tests'; } print_r( $_tests_dir . "\n" ); -// Github Actions tests directory. -if ( ! is_dir( $_tests_dir . '/includes/' ) ) { - $_tests_dir = '/tmp/wordpress/tests/phpunit'; -} -print_r( $_tests_dir . "\n" ); // Composer tests directory. if ( ! is_dir( $_tests_dir . '/includes/' ) ) { $_tests_dir = $_plugin_root . '/vendor/xwp/wordpress-tests/phpunit'; From 562330df518603d2784c90f0b9c2325563f28061 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 18:33:50 +0530 Subject: [PATCH 29/74] code refactor and cleanup --- bin/install-wp-tests.sh | 135 ++++++++++++++++++++++++++++------------ tests/bootstrap.php | 6 +- 2 files changed, 97 insertions(+), 44 deletions(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index f7485a27..bde256ac 100644 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -7,23 +7,65 @@ if [ $# -lt 3 ]; then 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} +function set_environment_variables { + 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} + TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") + + PROJECT_DIR=$( git rev-parse --show-toplevel ) + PROJECT_SLUG=${PROJECT_SLUG:-$( basename "$PROJECT_DIR" | sed 's/^wp-//' )} + + if [ -z "$PROJECT_TYPE" ]; then + if [ -e style.css ]; then + PROJECT_TYPE=theme + elif grep -isqE "^[ ]*\*[ ]*Plugin Name[ ]*:" "$PROJECT_DIR"/*.php; then + PROJECT_TYPE=plugin + elif [ $( find . -maxdepth 2 -name wp-config.php | wc -l | sed 's/ //g' ) -gt 0 ]; then + PROJECT_TYPE=site + else + PROJECT_TYPE=unknown + fi + fi -TMPDIR=${TMPDIR-/tmp} -TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") + export WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests} + export WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} -export WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests} -export WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} + echo "WP_TESTS_DIR is $WP_TESTS_DIR" + echo "WP_CORE_DIR is $WP_CORE_DIR" -echo "WP_TESTS_DIR is $WP_TESTS_DIR" -echo "WP_CORE_DIR is $WP_CORE_DIR" + 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 + + 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 + + echo "WP_TESTS_TAG is $WP_TESTS_TAG" +} -download() { +function download() { echo "Download $1 to $2" if [ `which curl` ]; then curl -s "$1" > "$2"; @@ -35,32 +77,7 @@ download() { 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 - 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 - - 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 - -echo "WP_TESTS_TAG is $WP_TESTS_TAG" - -install_wp() { +function install_wp() { if [ -d $WP_CORE_DIR ]; then return; @@ -106,7 +123,7 @@ install_wp() { download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php } -install_test_suite() { +function install_test_suite() { # portable in-place argument for both GNU sed and Mac OSX sed if [[ $(uname -s) == 'Darwin' ]]; then local ioption='-i .bak' @@ -137,7 +154,7 @@ install_test_suite() { echo "Tests installed to $WP_TESTS_DIR" } -install_db() { +function install_db() { $(echo mysql -V) if [ ${SKIP_DB_CREATE} = "true" ]; then @@ -164,6 +181,42 @@ install_db() { mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA || true } +function sync_project_dir() { + if [ "$PROJECT_TYPE" == plugin ]; then + INSTALL_PATH="$WP_CORE_DIR/wp-content/plugins/$PROJECT_SLUG" + + # Rsync the files into the right location + mkdir -p "$INSTALL_PATH" + rsync -a $(verbose_arg) --exclude .git/hooks --delete "$PROJECT_DIR/" "$INSTALL_PATH/" + cd "$INSTALL_PATH" + + echo "Location: $INSTALL_PATH" + elif [ "$PROJECT_TYPE" == theme ]; then + INSTALL_PATH="$WP_CORE_DIR/wp-content/themes/$PROJECT_SLUG" + + # Rsync the files into the right location + mkdir -p "$INSTALL_PATH" + rsync -a $(verbose_arg) --exclude .git/hooks --exclude node_modules --delete "$PROJECT_DIR/" "$INSTALL_PATH/" + cd "$INSTALL_PATH" + + # Clone the theme dependencies (i.e. plugins) into the plugins directory + if [ ! -z "$THEME_GIT_PLUGIN_DEPENDENCIES" ]; then + IFS=',' read -r -a dependencies <<< "$THEME_GIT_PLUGIN_DEPENDENCIES" + for dep in "${dependencies[@]}" + do + filename=$(basename "$dep") + git clone "$dep" "$WP_CORE_DIR/wp-content/plugins/${filename%.*}" + done + fi + + echo "Location: $INSTALL_PATH" + elif [ "$PROJECT_TYPE" == site ]; then + cd "$PROJECT_DIR" + fi +} + +set_environment_variables install_wp install_test_suite install_db +sync_project_dir diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 49022a16..fc2a6b5a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -11,17 +11,17 @@ $_plugin_root = realpath( __DIR__ . '/..' ); $_tests_dir = getenv( 'WP_TESTS_DIR' ); -print_r( $_tests_dir . "\n" ); + // Github Actions, Travis CI & Vagrant SSH tests directory. if ( empty( $_tests_dir ) ) { $_tests_dir = '/tmp/wordpress-tests'; } -print_r( $_tests_dir . "\n" ); + // Composer tests directory. if ( ! is_dir( $_tests_dir . '/includes/' ) ) { $_tests_dir = $_plugin_root . '/vendor/xwp/wordpress-tests/phpunit'; } -print_r( $_tests_dir . "\n" ); + if ( ! file_exists( $_tests_dir . '/includes/' ) ) { trigger_error( 'Unable to locate wordpress-tests', E_USER_ERROR ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error } From 19e7ffefe0e4de8df63b286b01fec17d22dfa290 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 18:41:18 +0530 Subject: [PATCH 30/74] Set vars at script level scope --- bin/install-wp-tests.sh | 99 ++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 51 deletions(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index bde256ac..ec739165 100644 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -7,63 +7,61 @@ if [ $# -lt 3 ]; then exit 1 fi -function set_environment_variables { - 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} - TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") - - PROJECT_DIR=$( git rev-parse --show-toplevel ) - PROJECT_SLUG=${PROJECT_SLUG:-$( basename "$PROJECT_DIR" | sed 's/^wp-//' )} - - if [ -z "$PROJECT_TYPE" ]; then - if [ -e style.css ]; then - PROJECT_TYPE=theme - elif grep -isqE "^[ ]*\*[ ]*Plugin Name[ ]*:" "$PROJECT_DIR"/*.php; then - PROJECT_TYPE=plugin - elif [ $( find . -maxdepth 2 -name wp-config.php | wc -l | sed 's/ //g' ) -gt 0 ]; then - PROJECT_TYPE=site - else - PROJECT_TYPE=unknown - 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} +TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") + +PROJECT_DIR=$( git rev-parse --show-toplevel ) +PROJECT_SLUG=${PROJECT_SLUG:-$( basename "$PROJECT_DIR" | sed 's/^wp-//' )} + +if [ -z "$PROJECT_TYPE" ]; then + if [ -e style.css ]; then + PROJECT_TYPE=theme + elif grep -isqE "^[ ]*\*[ ]*Plugin Name[ ]*:" "$PROJECT_DIR"/*.php; then + PROJECT_TYPE=plugin + elif [ $( find . -maxdepth 2 -name wp-config.php | wc -l | sed 's/ //g' ) -gt 0 ]; then + PROJECT_TYPE=site + else + PROJECT_TYPE=unknown fi +fi - export WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests} - export WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} +export WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests} +export WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} - echo "WP_TESTS_DIR is $WP_TESTS_DIR" - echo "WP_CORE_DIR is $WP_CORE_DIR" +echo "WP_TESTS_DIR is $WP_TESTS_DIR" +echo "WP_CORE_DIR is $WP_CORE_DIR" - 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" +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 - # 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 - - 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" + 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 + + 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 - echo "WP_TESTS_TAG is $WP_TESTS_TAG" -} +echo "WP_TESTS_TAG is $WP_TESTS_TAG" function download() { echo "Download $1 to $2" @@ -215,7 +213,6 @@ function sync_project_dir() { fi } -set_environment_variables install_wp install_test_suite install_db From b6edb9d5e917b7d508a1fc9d33857e1b2874e344 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 18:44:11 +0530 Subject: [PATCH 31/74] Move download function to top --- bin/install-wp-tests.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index ec739165..637005d7 100644 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -38,6 +38,18 @@ export WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} echo "WP_TESTS_DIR is $WP_TESTS_DIR" echo "WP_CORE_DIR is $WP_CORE_DIR" +download() { + echo "Download $1 to $2" + if [ `which curl` ]; then + curl -s "$1" > "$2"; + elif [ `which wget` ]; then + wget -nv -O "$2" "$1" + else + echo 'wget or curl not found' + return 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 @@ -63,19 +75,7 @@ fi echo "WP_TESTS_TAG is $WP_TESTS_TAG" -function download() { - echo "Download $1 to $2" - if [ `which curl` ]; then - curl -s "$1" > "$2"; - elif [ `which wget` ]; then - wget -nv -O "$2" "$1" - else - echo 'wget or curl not found' - return 1 - fi -} - -function install_wp() { +install_wp() { if [ -d $WP_CORE_DIR ]; then return; @@ -121,7 +121,7 @@ function install_wp() { download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php } -function install_test_suite() { +install_test_suite() { # portable in-place argument for both GNU sed and Mac OSX sed if [[ $(uname -s) == 'Darwin' ]]; then local ioption='-i .bak' @@ -152,7 +152,7 @@ function install_test_suite() { echo "Tests installed to $WP_TESTS_DIR" } -function install_db() { +install_db() { $(echo mysql -V) if [ ${SKIP_DB_CREATE} = "true" ]; then @@ -179,7 +179,7 @@ function install_db() { mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA || true } -function sync_project_dir() { +sync_project_dir() { if [ "$PROJECT_TYPE" == plugin ]; then INSTALL_PATH="$WP_CORE_DIR/wp-content/plugins/$PROJECT_SLUG" From 47aac991c9525e9d609e524b78951f743bb9000a Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 18:48:38 +0530 Subject: [PATCH 32/74] Run tests in the installed path --- .github/workflows/main.yml | 2 +- bin/install-wp-tests.sh | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4e9434fb..21e6036a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -102,7 +102,7 @@ jobs: - run: sudo systemctl start mysql.service - run: composer install - run: source bin/install-wp-tests.sh wordpress_test root root localhost latest - - run: composer test + - run: cd "$INSTALL_PATH" && composer test # finish: # needs: [test-e2e-coverage, test-js-coverage] diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 637005d7..c3b81604 100644 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -186,9 +186,9 @@ sync_project_dir() { # Rsync the files into the right location mkdir -p "$INSTALL_PATH" rsync -a $(verbose_arg) --exclude .git/hooks --delete "$PROJECT_DIR/" "$INSTALL_PATH/" - cd "$INSTALL_PATH" echo "Location: $INSTALL_PATH" + export INSTALL_PATH elif [ "$PROJECT_TYPE" == theme ]; then INSTALL_PATH="$WP_CORE_DIR/wp-content/themes/$PROJECT_SLUG" @@ -208,8 +208,10 @@ sync_project_dir() { fi echo "Location: $INSTALL_PATH" + export INSTALL_PATH elif [ "$PROJECT_TYPE" == site ]; then cd "$PROJECT_DIR" + export INSTALL_PATH=$PROJECT_DIR fi } From c598f5c46933e4a04bcc31ea32da7efa40288f2d Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 18:53:31 +0530 Subject: [PATCH 33/74] Set working directory --- .github/workflows/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 21e6036a..d9d381f5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -102,7 +102,9 @@ jobs: - run: sudo systemctl start mysql.service - run: composer install - run: source bin/install-wp-tests.sh wordpress_test root root localhost latest - - run: cd "$INSTALL_PATH" && composer test + - name: Run PHP Tests + working-directory: $INSTALL_PATH + run: composer test # finish: # needs: [test-e2e-coverage, test-js-coverage] From 5837bef41f38d044b54e561aa20cbc9f651e0334 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 18:59:43 +0530 Subject: [PATCH 34/74] Update env var --- .github/workflows/main.yml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d9d381f5..6a2ce46f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -98,12 +98,19 @@ jobs: with: php-version: '7.4' tools: phpunit - - run: sudo systemctl enable mysql.service - - run: sudo systemctl start mysql.service - - run: composer install - - run: source bin/install-wp-tests.sh wordpress_test root root localhost latest - - name: Run PHP Tests - working-directory: $INSTALL_PATH + + - name: Start MySQL + run: | + sudo systemctl enable mysql.service + sudo systemctl start mysql.service + + - name: Install and Setup tests + run: | + composer install + source bin/install-wp-tests.sh wordpress_test root root localhost latest + + - name: Run tests + working-directory: ${{env.INSTALL_PATH}} run: composer test # finish: From 996fdf7df72f254e6d719fa6a373ae3b5295ebb1 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 19:01:50 +0530 Subject: [PATCH 35/74] Add debug step --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6a2ce46f..522b6f09 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -108,7 +108,7 @@ jobs: run: | composer install source bin/install-wp-tests.sh wordpress_test root root localhost latest - + - uses: hmarr/debug-action@v2 - name: Run tests working-directory: ${{env.INSTALL_PATH}} run: composer test From 06a38fe73e9e1d51784864dd6636ba7a3f967ebe Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 19:13:14 +0530 Subject: [PATCH 36/74] Update script to run tests after install --- .github/workflows/main.yml | 6 +----- bin/install-wp-tests.sh | 5 +++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 522b6f09..590e88ab 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -104,14 +104,10 @@ jobs: sudo systemctl enable mysql.service sudo systemctl start mysql.service - - name: Install and Setup tests + - name: Install and Run tests run: | composer install source bin/install-wp-tests.sh wordpress_test root root localhost latest - - uses: hmarr/debug-action@v2 - - name: Run tests - working-directory: ${{env.INSTALL_PATH}} - run: composer test # finish: # needs: [test-e2e-coverage, test-js-coverage] diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index c3b81604..81520b4f 100644 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -187,8 +187,8 @@ sync_project_dir() { mkdir -p "$INSTALL_PATH" rsync -a $(verbose_arg) --exclude .git/hooks --delete "$PROJECT_DIR/" "$INSTALL_PATH/" + cd "$INSTALL_PATH" echo "Location: $INSTALL_PATH" - export INSTALL_PATH elif [ "$PROJECT_TYPE" == theme ]; then INSTALL_PATH="$WP_CORE_DIR/wp-content/themes/$PROJECT_SLUG" @@ -208,7 +208,6 @@ sync_project_dir() { fi echo "Location: $INSTALL_PATH" - export INSTALL_PATH elif [ "$PROJECT_TYPE" == site ]; then cd "$PROJECT_DIR" export INSTALL_PATH=$PROJECT_DIR @@ -219,3 +218,5 @@ install_wp install_test_suite install_db sync_project_dir + +composer test From 9419bb77f3e013deaee727e9e38965b1f850b56a Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 19:38:20 +0530 Subject: [PATCH 37/74] Cleanup script --- .github/workflows/main.yml | 14 +------------- bin/{install-wp-tests.sh => php-tests.sh} | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-) rename bin/{install-wp-tests.sh => php-tests.sh} (99%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 590e88ab..48f4d611 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,7 +30,6 @@ jobs: # steps: # - uses: actions/checkout@v2 - # - uses: hmarr/debug-action@v2 # - name: Use Node.js # uses: actions/setup-node@v1 @@ -57,7 +56,6 @@ jobs: # steps: # - uses: actions/checkout@v2 - # - uses: hmarr/debug-action@v2 # - name: Use Node.js # uses: actions/setup-node@v1 @@ -81,16 +79,6 @@ jobs: env: WP_VERSION: latest - # services: - # mysql: - # image: mysql:5 - # env: - # MYSQL_ROOT_PASSWORD: root - # MYSQL_DATABASE: wordpress_test - # ports: - # - 3306 - # options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - steps: - uses: actions/checkout@v2 - name: Setup PHP 7.4 @@ -107,7 +95,7 @@ jobs: - name: Install and Run tests run: | composer install - source bin/install-wp-tests.sh wordpress_test root root localhost latest + source bin/php-tests.sh wordpress_test root root localhost latest # finish: # needs: [test-e2e-coverage, test-js-coverage] diff --git a/bin/install-wp-tests.sh b/bin/php-tests.sh similarity index 99% rename from bin/install-wp-tests.sh rename to bin/php-tests.sh index 81520b4f..17931676 100644 --- a/bin/install-wp-tests.sh +++ b/bin/php-tests.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -x +set +x if [ $# -lt 3 ]; then echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" From 85f5546e332975a35e75169bac281d49855610de Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 19:41:32 +0530 Subject: [PATCH 38/74] Code refactor and cleanup --- bin/php-tests.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bin/php-tests.sh b/bin/php-tests.sh index 17931676..cbd70742 100644 --- a/bin/php-tests.sh +++ b/bin/php-tests.sh @@ -38,7 +38,7 @@ export WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} echo "WP_TESTS_DIR is $WP_TESTS_DIR" echo "WP_CORE_DIR is $WP_CORE_DIR" -download() { +function download() { echo "Download $1 to $2" if [ `which curl` ]; then curl -s "$1" > "$2"; @@ -50,6 +50,12 @@ download() { fi } +function verbose_arg { + if [ "$VERBOSE" == 1 ]; then + echo '-v' + 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 @@ -75,7 +81,7 @@ fi echo "WP_TESTS_TAG is $WP_TESTS_TAG" -install_wp() { +function install_wp() { if [ -d $WP_CORE_DIR ]; then return; @@ -121,7 +127,7 @@ install_wp() { download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php } -install_test_suite() { +function install_test_suite() { # portable in-place argument for both GNU sed and Mac OSX sed if [[ $(uname -s) == 'Darwin' ]]; then local ioption='-i .bak' @@ -152,7 +158,7 @@ install_test_suite() { echo "Tests installed to $WP_TESTS_DIR" } -install_db() { +function install_db() { $(echo mysql -V) if [ ${SKIP_DB_CREATE} = "true" ]; then @@ -179,7 +185,7 @@ install_db() { mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA || true } -sync_project_dir() { +function sync_project_dir() { if [ "$PROJECT_TYPE" == plugin ]; then INSTALL_PATH="$WP_CORE_DIR/wp-content/plugins/$PROJECT_SLUG" From 7446d7e5439ea3d592a009afa013e34773df1333 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 19:46:53 +0530 Subject: [PATCH 39/74] Add php coveralls --- .github/workflows/main.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 48f4d611..2b57ca16 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -97,6 +97,13 @@ jobs: composer install source bin/php-tests.sh wordpress_test root root localhost latest + - name: Upload coverage results to Coveralls + env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + composer global require php-coveralls/php-coveralls + php-coveralls --coverage_clover=build/logs/clover.xml -v + # finish: # needs: [test-e2e-coverage, test-js-coverage] # name: Finish From 457b7b6f5f7a3f8ccdab48959f3bcfc243010664 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 21:17:03 +0530 Subject: [PATCH 40/74] Add coveralls clover --- bin/php-tests.sh | 2 +- composer.json | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/php-tests.sh b/bin/php-tests.sh index cbd70742..0a0a45e6 100644 --- a/bin/php-tests.sh +++ b/bin/php-tests.sh @@ -225,4 +225,4 @@ install_test_suite install_db sync_project_dir -composer test +composer test-coverage-clover diff --git a/composer.json b/composer.json index 2db6a706..2a7360df 100644 --- a/composer.json +++ b/composer.json @@ -58,6 +58,9 @@ ], "test-coverage": [ "phpunit --coverage-html tests/coverage/phpunit" + ], + "test-coverage-clover": [ + "phpunit --coverage-clover tests/coverage/clover.xml" ] }, "extra": { From 215ea210a95e266882ee9512f1547be98c4233e1 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 21:17:20 +0530 Subject: [PATCH 41/74] Update clover path --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2b57ca16..ae02de9b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -102,7 +102,7 @@ jobs: COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | composer global require php-coveralls/php-coveralls - php-coveralls --coverage_clover=build/logs/clover.xml -v + php-coveralls --coverage_clover=tests/coverage/clover.xml -v # finish: # needs: [test-e2e-coverage, test-js-coverage] From 2274d05320d52aeec95b27ec0d4e5c401335f9b1 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 21:28:33 +0530 Subject: [PATCH 42/74] Update composer script to run coverage --- .github/workflows/main.yml | 8 +------- bin/php-tests.sh | 8 +++++++- composer.json | 5 +++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ae02de9b..b187714e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -78,6 +78,7 @@ jobs: env: WP_VERSION: latest + COVERALLS: true steps: - uses: actions/checkout@v2 @@ -97,13 +98,6 @@ jobs: composer install source bin/php-tests.sh wordpress_test root root localhost latest - - name: Upload coverage results to Coveralls - env: - COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - composer global require php-coveralls/php-coveralls - php-coveralls --coverage_clover=tests/coverage/clover.xml -v - # finish: # needs: [test-e2e-coverage, test-js-coverage] # name: Finish diff --git a/bin/php-tests.sh b/bin/php-tests.sh index 0a0a45e6..ff2de012 100644 --- a/bin/php-tests.sh +++ b/bin/php-tests.sh @@ -225,4 +225,10 @@ install_test_suite install_db sync_project_dir -composer test-coverage-clover +if [ "$COVERALLS" == true ]; then + echo "Running PHP unit tests with coverage" + composer test-coveralls +else + echo "Running PHP unit tests" + composer test +fi diff --git a/composer.json b/composer.json index 2a7360df..88dd08bf 100644 --- a/composer.json +++ b/composer.json @@ -59,8 +59,9 @@ "test-coverage": [ "phpunit --coverage-html tests/coverage/phpunit" ], - "test-coverage-clover": [ - "phpunit --coverage-clover tests/coverage/clover.xml" + "test-coveralls": [ + "composer test --coverage-clover tests/coverage/clover.xml", + "php-coveralls --coverage_clover=tests/coverage/clover.xml -v" ] }, "extra": { From a4c9e6403414ad398825eb2cd57ba8a1ccbe3fc0 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 21:32:44 +0530 Subject: [PATCH 43/74] Replace test command --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 88dd08bf..4da729f1 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,7 @@ "phpunit --coverage-html tests/coverage/phpunit" ], "test-coveralls": [ - "composer test --coverage-clover tests/coverage/clover.xml", + "phpunit --coverage-clover tests/coverage/clover.xml", "php-coveralls --coverage_clover=tests/coverage/clover.xml -v" ] }, From 170a36dd66f2256001af3b2dffa72db7299f8085 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 21:35:54 +0530 Subject: [PATCH 44/74] Remove .coveralls.yml file --- .coveralls.yml | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .coveralls.yml diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index 3b85ca4f..00000000 --- a/.coveralls.yml +++ /dev/null @@ -1,3 +0,0 @@ -service_name: travis-ci -coverage_clover: build/logs/clover.xml -json_path: build/logs/coveralls-upload.json From a2e385ba6d7c461a6aea2bdf6569a3cc61c64172 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 21:46:56 +0530 Subject: [PATCH 45/74] Add coveralls.yml with json_path --- .coveralls.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .coveralls.yml diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 00000000..7b4af8dc --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1,2 @@ +coverage_clover: tests/coverage/clover.xml +json_path: tests/coverage/coveralls-upload.json From afc356e2a38e7e582888427ac929b6f3ac9d5c62 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 21:50:24 +0530 Subject: [PATCH 46/74] Add COVERALLS_REPO_TOKEN --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b187714e..98aa3142 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -78,6 +78,7 @@ jobs: env: WP_VERSION: latest + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} COVERALLS: true steps: From 0efe1fb3912c4f622747fe6647d26d3fb5e018fa Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 22:24:55 +0530 Subject: [PATCH 47/74] Add PHP and WP version matrix --- .github/workflows/main.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 98aa3142..7f544ba0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -71,15 +71,25 @@ jobs: # path-to-lcov: ./tests/coverage/js/lcov.info # parallel: true - test-php-coverage: + test-php: # needs: [lint] - name: 'PHP tests (PHP 7.4, WordPress latest, with code coverage)' + name: 'PHP tests (PHP ${{ matrix.php_versions }}, WordPress ${{ matrix.wp_versions }})' runs-on: ubuntu-latest + strategy: + matrix: + php_versions: [7.4, 7.3, 7.2, 7.1, '7.0', 5.6.20] + wp_versions: ['latest', 'trunk', '5.0'] + exclude: + - php_versions: [7.3, 7.2, 7.1, '7.0', 5.6.20] + wp_versions: ['trunk', '5.0'] + include: + - php_versions: 5.6.20 + wp_versions: 5.0 env: WP_VERSION: latest COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} - COVERALLS: true + COVERALLS: ${{ matrix.php_versions == 7.4 && matrix.wp_versions == latest }} steps: - uses: actions/checkout@v2 From 68a18aa4299c8e98b2845e6f28f1044ae774a659 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 22:25:46 +0530 Subject: [PATCH 48/74] Fix syntax error --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7f544ba0..1ec3903a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -89,7 +89,7 @@ jobs: env: WP_VERSION: latest COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} - COVERALLS: ${{ matrix.php_versions == 7.4 && matrix.wp_versions == latest }} + COVERALLS: ${{ matrix.php_versions == 7.4 && matrix.wp_versions == 'latest' }} steps: - uses: actions/checkout@v2 From 7e53fa84427ac0a18fd78086f94b0c4ddc772e1e Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 22:29:50 +0530 Subject: [PATCH 49/74] Update matrix to use include --- .github/workflows/main.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1ec3903a..e6b6234d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -78,25 +78,24 @@ jobs: strategy: matrix: php_versions: [7.4, 7.3, 7.2, 7.1, '7.0', 5.6.20] - wp_versions: ['latest', 'trunk', '5.0'] - exclude: - - php_versions: [7.3, 7.2, 7.1, '7.0', 5.6.20] - wp_versions: ['trunk', '5.0'] + wp_versions: ['latest'] include: - php_versions: 5.6.20 wp_versions: 5.0 + - php_versions: 7.4 + wp_versions: 'trunk' env: - WP_VERSION: latest + WP_VERSION: ${{ matrix.wp_versions }} COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} COVERALLS: ${{ matrix.php_versions == 7.4 && matrix.wp_versions == 'latest' }} steps: - uses: actions/checkout@v2 - - name: Setup PHP 7.4 + - name: Setup PHP ${{ matrix.php_versions }} uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: ${{ matrix.php_versions }} tools: phpunit - name: Start MySQL From a1a9265189d92eb4ffdfb3681d822e5090baf4cf Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 22:38:19 +0530 Subject: [PATCH 50/74] Update WP version to '5.0' --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e6b6234d..92849512 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -80,10 +80,10 @@ jobs: php_versions: [7.4, 7.3, 7.2, 7.1, '7.0', 5.6.20] wp_versions: ['latest'] include: - - php_versions: 5.6.20 - wp_versions: 5.0 - php_versions: 7.4 wp_versions: 'trunk' + - php_versions: 5.6.20 + wp_versions: '5.0' env: WP_VERSION: ${{ matrix.wp_versions }} From 9427cffb0c824914e2b6a47532e901408e60cf03 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 22:47:42 +0530 Subject: [PATCH 51/74] Set PHPUnit version --- .github/workflows/main.yml | 3 ++- bin/php-tests.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 92849512..7a2b1cc8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -76,6 +76,7 @@ jobs: name: 'PHP tests (PHP ${{ matrix.php_versions }}, WordPress ${{ matrix.wp_versions }})' runs-on: ubuntu-latest strategy: + fail-fast: false matrix: php_versions: [7.4, 7.3, 7.2, 7.1, '7.0', 5.6.20] wp_versions: ['latest'] @@ -96,7 +97,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php_versions }} - tools: phpunit + tools: phpunit:${{ matrix.php_versions }} - name: Start MySQL run: | diff --git a/bin/php-tests.sh b/bin/php-tests.sh index ff2de012..a81991fb 100644 --- a/bin/php-tests.sh +++ b/bin/php-tests.sh @@ -39,7 +39,6 @@ echo "WP_TESTS_DIR is $WP_TESTS_DIR" echo "WP_CORE_DIR is $WP_CORE_DIR" function download() { - echo "Download $1 to $2" if [ `which curl` ]; then curl -s "$1" > "$2"; elif [ `which wget` ]; then @@ -183,6 +182,7 @@ function install_db() { # create database mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA || true + mysql --user="$DB_USER" --password="$DB_PASS" --execute="ALTER USER '$DB_USER'@'localhost' IDENTIFIED WITH mysql_native_password BY '$DB_PASS';"; } function sync_project_dir() { From 36ff513198acc9f56c285ec1b79050207993ad4b Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 22:57:25 +0530 Subject: [PATCH 52/74] Use PHPUnit 5 for older PHP versions --- .github/workflows/main.yml | 8 ++++++-- bin/php-tests.sh | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7a2b1cc8..2e97c82a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -97,7 +97,11 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php_versions }} - tools: phpunit:${{ matrix.php_versions }} + tools: phpunit + + - name: Setup PHPUnit 5 for PHP 5.6||7.0 + if: ${{ ['7.0', 5.6.20].contains(matrix.php_versions) }} + run: composer require phpunit/phpunit:5.7.27 - name: Start MySQL run: | @@ -107,7 +111,7 @@ jobs: - name: Install and Run tests run: | composer install - source bin/php-tests.sh wordpress_test root root localhost latest + source bin/php-tests.sh wordpress_test root root localhost # finish: # needs: [test-e2e-coverage, test-js-coverage] diff --git a/bin/php-tests.sh b/bin/php-tests.sh index a81991fb..83cc2929 100644 --- a/bin/php-tests.sh +++ b/bin/php-tests.sh @@ -3,7 +3,7 @@ set +x if [ $# -lt 3 ]; then - echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" + echo "usage: $0 [db-host] [skip-database-creation]" exit 1 fi @@ -11,9 +11,9 @@ DB_NAME=$1 DB_USER=$2 DB_PASS=$3 DB_HOST=${4-localhost} -WP_VERSION=${5-latest} -SKIP_DB_CREATE=${6-false} +SKIP_DB_CREATE=${5-false} +WP_VERSION=${WP_VERSION:-latest} TMPDIR=${TMPDIR-/tmp} TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") From 103a5cfa46d5321c8280af5a843ddc5cec4a5cd8 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 22:58:50 +0530 Subject: [PATCH 53/74] Update if condition --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2e97c82a..c6212d79 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -100,7 +100,7 @@ jobs: tools: phpunit - name: Setup PHPUnit 5 for PHP 5.6||7.0 - if: ${{ ['7.0', 5.6.20].contains(matrix.php_versions) }} + if: ${{ matrix.php_versions == '7.0' || matrix.php_versions == 5.6.20 }} run: composer require phpunit/phpunit:5.7.27 - name: Start MySQL From 85e140f416707bdd8b52be445978bf5dd0c900c4 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 22:59:40 +0530 Subject: [PATCH 54/74] Fix syntax error --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c6212d79..d2019d87 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -100,7 +100,7 @@ jobs: tools: phpunit - name: Setup PHPUnit 5 for PHP 5.6||7.0 - if: ${{ matrix.php_versions == '7.0' || matrix.php_versions == 5.6.20 }} + if: ${{ matrix.php_versions == '7.0' || matrix.php_versions == '5.6.20' }} run: composer require phpunit/phpunit:5.7.27 - name: Start MySQL From 5c4bca8de8679b552ab9fe8f699a454f958911a0 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 23:03:35 +0530 Subject: [PATCH 55/74] Force update deps --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d2019d87..8455b06e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -101,7 +101,7 @@ jobs: - name: Setup PHPUnit 5 for PHP 5.6||7.0 if: ${{ matrix.php_versions == '7.0' || matrix.php_versions == '5.6.20' }} - run: composer require phpunit/phpunit:5.7.27 + run: composer require phpunit/phpunit:5.7.27 --with-all-dependencies - name: Start MySQL run: | From 57fabc3d3f66c1f8d849b3c8463c0ecf247fe1a6 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 23:07:43 +0530 Subject: [PATCH 56/74] Remove phpcov for phpunit5 --- .github/workflows/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8455b06e..0939f727 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -101,7 +101,9 @@ jobs: - name: Setup PHPUnit 5 for PHP 5.6||7.0 if: ${{ matrix.php_versions == '7.0' || matrix.php_versions == '5.6.20' }} - run: composer require phpunit/phpunit:5.7.27 --with-all-dependencies + run: | + composer remove --dev phpunit/phpcov + composer require phpunit/phpunit:5.7.27 --with-all-dependencies - name: Start MySQL run: | From 356f9b74b9213cf68d4c1385dcccfbc137685dc9 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 23:15:16 +0530 Subject: [PATCH 57/74] Remove all composer packages to prevent PHP version issues --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0939f727..87fb6ebb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -102,7 +102,7 @@ jobs: - name: Setup PHPUnit 5 for PHP 5.6||7.0 if: ${{ matrix.php_versions == '7.0' || matrix.php_versions == '5.6.20' }} run: | - composer remove --dev phpunit/phpcov + composer remove --dev --quiet --no-scripts $(composer show) composer require phpunit/phpunit:5.7.27 --with-all-dependencies - name: Start MySQL From 1a0dc2195cc8817ceef954a843c2e9a5b05bc09a Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 23:18:20 +0530 Subject: [PATCH 58/74] Update composer install and remove sequence --- .github/workflows/main.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 87fb6ebb..97775705 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -99,21 +99,22 @@ jobs: php-version: ${{ matrix.php_versions }} tools: phpunit + - name: Start MySQL + run: | + sudo systemctl enable mysql.service + sudo systemctl start mysql.service + + - name: Install dependencies + run: composer install + - name: Setup PHPUnit 5 for PHP 5.6||7.0 if: ${{ matrix.php_versions == '7.0' || matrix.php_versions == '5.6.20' }} run: | composer remove --dev --quiet --no-scripts $(composer show) composer require phpunit/phpunit:5.7.27 --with-all-dependencies - - name: Start MySQL - run: | - sudo systemctl enable mysql.service - sudo systemctl start mysql.service - - name: Install and Run tests - run: | - composer install - source bin/php-tests.sh wordpress_test root root localhost + run: source bin/php-tests.sh wordpress_test root root localhost # finish: # needs: [test-e2e-coverage, test-js-coverage] From 26ee81c588eaf3341b874a2c73df340b3b8c173a Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 23:21:06 +0530 Subject: [PATCH 59/74] DOnt use scripts --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 97775705..dff68b5a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -105,7 +105,7 @@ jobs: sudo systemctl start mysql.service - name: Install dependencies - run: composer install + run: composer install --no-scripts - name: Setup PHPUnit 5 for PHP 5.6||7.0 if: ${{ matrix.php_versions == '7.0' || matrix.php_versions == '5.6.20' }} From 937b8f3f576563b05b0b4fe1a37982e38964b2a6 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 23:23:27 +0530 Subject: [PATCH 60/74] Use --no-scripts --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dff68b5a..6e2a262b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -105,13 +105,13 @@ jobs: sudo systemctl start mysql.service - name: Install dependencies - run: composer install --no-scripts + run: composer install - name: Setup PHPUnit 5 for PHP 5.6||7.0 if: ${{ matrix.php_versions == '7.0' || matrix.php_versions == '5.6.20' }} run: | composer remove --dev --quiet --no-scripts $(composer show) - composer require phpunit/phpunit:5.7.27 --with-all-dependencies + composer require phpunit/phpunit:5.7.27 --with-all-dependencies --no-scripts - name: Install and Run tests run: source bin/php-tests.sh wordpress_test root root localhost From ba014fd6a7e4e4ba6b7b9eaaae85d9cc9935c0f9 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 24 Mar 2021 23:40:02 +0530 Subject: [PATCH 61/74] Install phpunit directly for older PHP versions --- .github/workflows/main.yml | 8 +++++--- bin/php-tests.sh | 11 +++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6e2a262b..e777c463 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -107,13 +107,15 @@ jobs: - name: Install dependencies run: composer install - - name: Setup PHPUnit 5 for PHP 5.6||7.0 + - name: Install and Run tests if: ${{ matrix.php_versions == '7.0' || matrix.php_versions == '5.6.20' }} run: | - composer remove --dev --quiet --no-scripts $(composer show) - composer require phpunit/phpunit:5.7.27 --with-all-dependencies --no-scripts + wget -O bin/phpunit https://phar.phpunit.de/phpunit-5.phar + chmod +x bin/phpunit + source bin/php-tests.sh wordpress_test root root localhost false bin/phpunit - name: Install and Run tests + if: ${{ matrix.php_versions != '7.0' && matrix.php_versions != '5.6.20' }} run: source bin/php-tests.sh wordpress_test root root localhost # finish: diff --git a/bin/php-tests.sh b/bin/php-tests.sh index 83cc2929..f49aa1f3 100644 --- a/bin/php-tests.sh +++ b/bin/php-tests.sh @@ -3,7 +3,7 @@ set +x if [ $# -lt 3 ]; then - echo "usage: $0 [db-host] [skip-database-creation]" + echo "usage: $0 [db-host] [skip-database-creation] [phpunit]" exit 1 fi @@ -12,6 +12,7 @@ DB_USER=$2 DB_PASS=$3 DB_HOST=${4-localhost} SKIP_DB_CREATE=${5-false} +PHPUNIT_PATH=${6-false} WP_VERSION=${WP_VERSION:-latest} TMPDIR=${TMPDIR-/tmp} @@ -20,6 +21,7 @@ TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") PROJECT_DIR=$( git rev-parse --show-toplevel ) PROJECT_SLUG=${PROJECT_SLUG:-$( basename "$PROJECT_DIR" | sed 's/^wp-//' )} + if [ -z "$PROJECT_TYPE" ]; then if [ -e style.css ]; then PROJECT_TYPE=theme @@ -230,5 +232,10 @@ if [ "$COVERALLS" == true ]; then composer test-coveralls else echo "Running PHP unit tests" - composer test + if [ "$PHPUNIT_PATH" == false ]; then + composer test + else + echo "Using custom PHPUnit located at $PHPUNIT_PATH" + $PHPUNIT_PATH + fi fi From ba2388c780200f7a5d832e1459665b21d2266fc1 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Thu, 25 Mar 2021 00:07:51 +0530 Subject: [PATCH 62/74] MySQL use mysql_native_password authentication for back compat --- .github/workflows/main.yml | 2 ++ bin/php-tests.sh | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e777c463..94c9e754 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -101,6 +101,8 @@ jobs: - name: Start MySQL run: | + echo "[mysqld]" >> /etc/mysql/my.cnf + echo "default-authentication-plugin=mysql_native_password" >> /etc/mysql/my.cnf sudo systemctl enable mysql.service sudo systemctl start mysql.service diff --git a/bin/php-tests.sh b/bin/php-tests.sh index f49aa1f3..71e239e0 100644 --- a/bin/php-tests.sh +++ b/bin/php-tests.sh @@ -184,7 +184,6 @@ function install_db() { # create database mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA || true - mysql --user="$DB_USER" --password="$DB_PASS" --execute="ALTER USER '$DB_USER'@'localhost' IDENTIFIED WITH mysql_native_password BY '$DB_PASS';"; } function sync_project_dir() { From 489b4d8bb9a3935b4aef1add8b6bfdab9c51b1e3 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Thu, 25 Mar 2021 00:09:25 +0530 Subject: [PATCH 63/74] Run as sudo --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 94c9e754..381606be 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -101,8 +101,8 @@ jobs: - name: Start MySQL run: | - echo "[mysqld]" >> /etc/mysql/my.cnf - echo "default-authentication-plugin=mysql_native_password" >> /etc/mysql/my.cnf + sudo echo "[mysqld]" >> /etc/mysql/my.cnf + sudo echo "default-authentication-plugin=mysql_native_password" >> /etc/mysql/my.cnf sudo systemctl enable mysql.service sudo systemctl start mysql.service From f444c96a4207ebc13402711dc93e722a549425b2 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Thu, 25 Mar 2021 00:15:00 +0530 Subject: [PATCH 64/74] Update mysql conf file --- .github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 381606be..290465e4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -101,8 +101,7 @@ jobs: - name: Start MySQL run: | - sudo echo "[mysqld]" >> /etc/mysql/my.cnf - sudo echo "default-authentication-plugin=mysql_native_password" >> /etc/mysql/my.cnf + sudo echo "default-authentication-plugin=mysql_native_password" >> /etc/mysql/mysql.conf.d/mysqld.cnf sudo systemctl enable mysql.service sudo systemctl start mysql.service From f7aecfb54df735d7d60457baff701f4b18b3c89a Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Thu, 25 Mar 2021 00:19:54 +0530 Subject: [PATCH 65/74] Use ubuntu-18.04 for PHP7.0 and 5.6 --- .github/workflows/main.yml | 6 ++++-- bin/php-tests.sh | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 290465e4..a4cfc0cd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -74,17 +74,20 @@ jobs: test-php: # needs: [lint] name: 'PHP tests (PHP ${{ matrix.php_versions }}, WordPress ${{ matrix.wp_versions }})' - runs-on: ubuntu-latest + runs-on: ${{ matrix.os_versions }} strategy: fail-fast: false matrix: php_versions: [7.4, 7.3, 7.2, 7.1, '7.0', 5.6.20] wp_versions: ['latest'] + os_versions: ['ubuntu-latest'] include: - php_versions: 7.4 wp_versions: 'trunk' + os_versions: 'ubuntu-18.04' - php_versions: 5.6.20 wp_versions: '5.0' + os_versions: 'ubuntu-18.04' env: WP_VERSION: ${{ matrix.wp_versions }} @@ -101,7 +104,6 @@ jobs: - name: Start MySQL run: | - sudo echo "default-authentication-plugin=mysql_native_password" >> /etc/mysql/mysql.conf.d/mysqld.cnf sudo systemctl enable mysql.service sudo systemctl start mysql.service diff --git a/bin/php-tests.sh b/bin/php-tests.sh index 71e239e0..f49aa1f3 100644 --- a/bin/php-tests.sh +++ b/bin/php-tests.sh @@ -184,6 +184,7 @@ function install_db() { # create database mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA || true + mysql --user="$DB_USER" --password="$DB_PASS" --execute="ALTER USER '$DB_USER'@'localhost' IDENTIFIED WITH mysql_native_password BY '$DB_PASS';"; } function sync_project_dir() { From 65e169e89e063a8b273a83dadbe0c963438c0f55 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Thu, 25 Mar 2021 00:24:17 +0530 Subject: [PATCH 66/74] Update ubuntu version --- .github/workflows/main.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a4cfc0cd..e8420a0d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -78,13 +78,21 @@ jobs: strategy: fail-fast: false matrix: - php_versions: [7.4, 7.3, 7.2, 7.1, '7.0', 5.6.20] + php_versions: [7.4, 7.3, 7.2, 7.1] wp_versions: ['latest'] os_versions: ['ubuntu-latest'] include: - php_versions: 7.4 wp_versions: 'trunk' + + - php_versions: '7.0' + wp_versions: 'latest' os_versions: 'ubuntu-18.04' + + - php_versions: 5.6.20 + wp_versions: 'latest' + os_versions: 'ubuntu-18.04' + - php_versions: 5.6.20 wp_versions: '5.0' os_versions: 'ubuntu-18.04' From ffd2b2ad32b88a1f053d582185875deef930548c Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Thu, 25 Mar 2021 00:26:52 +0530 Subject: [PATCH 67/74] Update OS var --- .github/workflows/main.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e8420a0d..f501e59b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -74,28 +74,28 @@ jobs: test-php: # needs: [lint] name: 'PHP tests (PHP ${{ matrix.php_versions }}, WordPress ${{ matrix.wp_versions }})' - runs-on: ${{ matrix.os_versions }} + runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: php_versions: [7.4, 7.3, 7.2, 7.1] wp_versions: ['latest'] - os_versions: ['ubuntu-latest'] + os: [ubuntu-latest] include: - php_versions: 7.4 wp_versions: 'trunk' - php_versions: '7.0' wp_versions: 'latest' - os_versions: 'ubuntu-18.04' + os: ubuntu-18.04 # Use ubuntu-18.4 which has MySQL 5.7 for back-compat < PHP7.0 - php_versions: 5.6.20 wp_versions: 'latest' - os_versions: 'ubuntu-18.04' + os: ubuntu-18.04 - php_versions: 5.6.20 wp_versions: '5.0' - os_versions: 'ubuntu-18.04' + os: ubuntu-18.04 env: WP_VERSION: ${{ matrix.wp_versions }} From 17775d629af7a41292db424d390e59d3ba63f465 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Thu, 25 Mar 2021 00:28:19 +0530 Subject: [PATCH 68/74] Cleanup --- .github/workflows/main.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f501e59b..cad02eef 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -84,15 +84,12 @@ jobs: include: - php_versions: 7.4 wp_versions: 'trunk' - - php_versions: '7.0' wp_versions: 'latest' - os: ubuntu-18.04 # Use ubuntu-18.4 which has MySQL 5.7 for back-compat < PHP7.0 - + os: ubuntu-18.04 - php_versions: 5.6.20 wp_versions: 'latest' os: ubuntu-18.04 - - php_versions: 5.6.20 wp_versions: '5.0' os: ubuntu-18.04 From 43a092e7a8d935e15a8805ade647197b3e3e602d Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Thu, 25 Mar 2021 00:29:54 +0530 Subject: [PATCH 69/74] Add missing OS var --- .github/workflows/main.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cad02eef..f609e574 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -84,12 +84,16 @@ jobs: include: - php_versions: 7.4 wp_versions: 'trunk' + os: ubuntu-latest + - php_versions: '7.0' wp_versions: 'latest' - os: ubuntu-18.04 + os: ubuntu-18.04 # Use ubuntu-18.4 which has MySQL 5.7 for back-compat < PHP7.0 + - php_versions: 5.6.20 wp_versions: 'latest' os: ubuntu-18.04 + - php_versions: 5.6.20 wp_versions: '5.0' os: ubuntu-18.04 From ab337ee6dbed8486c8739b0f9b0d665a0629ca5d Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Thu, 25 Mar 2021 00:34:47 +0530 Subject: [PATCH 70/74] Enable JS and E2E test jobs --- .github/workflows/main.yml | 151 +++++++++++++++++++------------------ 1 file changed, 76 insertions(+), 75 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f609e574..7376ac9d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,73 +6,73 @@ env: DEV_LIB_PATH: vendor/xwp/wp-dev-lib/scripts jobs: - # lint: - # name: 'Lint' - # runs-on: ubuntu-latest - - # steps: - # - uses: actions/checkout@v2 - # - name: Use Node.js - # uses: actions/setup-node@v1 - # with: - # node-version: '14' - # - run: npm ci - # - run: npm run lint - - # test-e2e-coverage: - # needs: [lint] - # name: 'E2E tests (PHP 7.4, WordPress latest, with code coverage)' - # runs-on: ubuntu-latest - - # env: - # NODE_ENV: e2e - # WP_VERSION: 5.7 - - # steps: - # - uses: actions/checkout@v2 - - # - name: Use Node.js - # uses: actions/setup-node@v1 - # with: - # node-version: '14' - # - run: npm ci - # - run: npm run env:start - # - run: npm run wp -- wp core install --title=WordPress --admin_user=admin --admin_password=password --admin_email=admin@example.com --skip-email --url=http://localhost:8088 --quiet - # - run: npm run wp -- wp plugin activate foo-bar - # - run: npm run build:js - # - run: npm run test:e2e:coverage - - # - name: Coveralls - # uses: coverallsapp/github-action@master - # with: - # github-token: ${{ secrets.GITHUB_TOKEN }} - # path-to-lcov: ./tests/coverage/e2e/lcov.info - # parallel: true - - # test-js-coverage: - # needs: [lint] - # name: 'JS unit tests (with code coverage)' - # runs-on: ubuntu-latest - - # steps: - # - uses: actions/checkout@v2 - - # - name: Use Node.js - # uses: actions/setup-node@v1 - # with: - # node-version: '14' - # - run: npm ci - # - run: npm run test:js:coverage - - # - name: Coveralls - # uses: coverallsapp/github-action@master - # with: - # github-token: ${{ secrets.GITHUB_TOKEN }} - # path-to-lcov: ./tests/coverage/js/lcov.info - # parallel: true + lint: + name: 'Lint' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: '14' + - run: npm ci + - run: npm run lint + + test-e2e-coverage: + needs: [lint] + name: 'E2E tests (PHP 7.4, WordPress latest, with code coverage)' + runs-on: ubuntu-latest + + env: + NODE_ENV: e2e + WP_VERSION: 5.7 + + steps: + - uses: actions/checkout@v2 + + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: '14' + - run: npm ci + - run: npm run env:start + - run: npm run wp -- wp core install --title=WordPress --admin_user=admin --admin_password=password --admin_email=admin@example.com --skip-email --url=http://localhost:8088 --quiet + - run: npm run wp -- wp plugin activate foo-bar + - run: npm run build:js + - run: npm run test:e2e:coverage + + - name: Coveralls + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: ./tests/coverage/e2e/lcov.info + parallel: true + + test-js-coverage: + needs: [lint] + name: 'JS unit tests (with code coverage)' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: '14' + - run: npm ci + - run: npm run test:js:coverage + + - name: Coveralls + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: ./tests/coverage/js/lcov.info + parallel: true test-php: - # needs: [lint] + needs: [lint] name: 'PHP tests (PHP ${{ matrix.php_versions }}, WordPress ${{ matrix.wp_versions }})' runs-on: ${{ matrix.os }} strategy: @@ -101,6 +101,7 @@ jobs: env: WP_VERSION: ${{ matrix.wp_versions }} COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COVERALLS_PARALLEL: true COVERALLS: ${{ matrix.php_versions == 7.4 && matrix.wp_versions == 'latest' }} steps: @@ -130,13 +131,13 @@ jobs: if: ${{ matrix.php_versions != '7.0' && matrix.php_versions != '5.6.20' }} run: source bin/php-tests.sh wordpress_test root root localhost - # finish: - # needs: [test-e2e-coverage, test-js-coverage] - # name: Finish - # runs-on: ubuntu-latest - # steps: - # - name: Coveralls Finished - # uses: coverallsapp/github-action@master - # with: - # github-token: ${{ secrets.github_token }} - # parallel-finished: true + finish: + needs: [test-e2e-coverage, test-js-coverage, test-php] + name: Finish + runs-on: ubuntu-latest + steps: + - name: Coveralls Finished + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.github_token }} + parallel-finished: true From e9f2c58bf413ccb3caa41e95d2036dc9012564de Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Thu, 25 Mar 2021 00:37:12 +0530 Subject: [PATCH 71/74] Update print statement to include WP version --- bin/php-tests.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/php-tests.sh b/bin/php-tests.sh index f49aa1f3..db14c95b 100644 --- a/bin/php-tests.sh +++ b/bin/php-tests.sh @@ -90,10 +90,10 @@ function install_wp() { mkdir -p $WP_CORE_DIR - echo "Installing WP to $WP_CORE_DIR" - if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then mkdir -p $TMPDIR/wordpress-nightly + echo "Installing WP from https://wordpress.org/nightly-builds/wordpress-latest.zip to $WP_CORE_DIR" + 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 @@ -119,6 +119,8 @@ function install_wp() { else local ARCHIVE_NAME="wordpress-$WP_VERSION" fi + + echo "Installing WP from https://wordpress.org/${ARCHIVE_NAME}.tar.gz to $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 From b4bf2c603ea4bcbafea2f2979e68b30d4c5234e5 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Thu, 25 Mar 2021 00:53:26 +0530 Subject: [PATCH 72/74] Rename actions file and fix coveralls issue --- .github/workflows/{main.yml => lint-tests.yml} | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) rename .github/workflows/{main.yml => lint-tests.yml} (95%) diff --git a/.github/workflows/main.yml b/.github/workflows/lint-tests.yml similarity index 95% rename from .github/workflows/main.yml rename to .github/workflows/lint-tests.yml index 7376ac9d..8ac553f5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/lint-tests.yml @@ -1,6 +1,12 @@ -name: Lint and Test +name: Lint and Tests -on: [push] +on: + push: + branches: + - master + - develop + - feature/github-actions + pull_request: env: DEV_LIB_PATH: vendor/xwp/wp-dev-lib/scripts @@ -47,6 +53,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} path-to-lcov: ./tests/coverage/e2e/lcov.info + flag-name: 'E2E Tests' parallel: true test-js-coverage: @@ -69,6 +76,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} path-to-lcov: ./tests/coverage/js/lcov.info + flag-name: 'JS Unit Tests' parallel: true test-php: From 5a7cb833fc4974d0e700355250f78255c871cd2e Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Thu, 25 Mar 2021 01:02:39 +0530 Subject: [PATCH 73/74] Remove test branch from push branches list --- .github/workflows/lint-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/lint-tests.yml b/.github/workflows/lint-tests.yml index 8ac553f5..95c43266 100644 --- a/.github/workflows/lint-tests.yml +++ b/.github/workflows/lint-tests.yml @@ -5,7 +5,6 @@ on: branches: - master - develop - - feature/github-actions pull_request: env: From 94840705b87e6b2732e80c2bc29b3770920200f0 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Thu, 25 Mar 2021 22:49:49 +0530 Subject: [PATCH 74/74] Refactor and cleanup workflow yaml file --- .github/workflows/lint-tests.yml | 196 ++++++++++++++++--------------- 1 file changed, 104 insertions(+), 92 deletions(-) diff --git a/.github/workflows/lint-tests.yml b/.github/workflows/lint-tests.yml index 95c43266..4c3697e8 100644 --- a/.github/workflows/lint-tests.yml +++ b/.github/workflows/lint-tests.yml @@ -1,4 +1,4 @@ -name: Lint and Tests +name: Coding Standards and Tests on: push: @@ -7,26 +7,26 @@ on: - develop pull_request: -env: - DEV_LIB_PATH: vendor/xwp/wp-dev-lib/scripts - jobs: lint: - name: 'Lint' + name: "Coding Standards" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Use Node.js - uses: actions/setup-node@v1 - with: - node-version: '14' - - run: npm ci - - run: npm run lint - - test-e2e-coverage: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: "14" + + - name: Install dependencies + run: npm ci + + - name: Run coding standards check + run: npm run lint + + test-e2e: needs: [lint] - name: 'E2E tests (PHP 7.4, WordPress latest, with code coverage)' + name: "E2E tests (PHP 7.4, WordPress latest, with code coverage)" runs-on: ubuntu-latest env: @@ -34,75 +34,87 @@ jobs: WP_VERSION: 5.7 steps: - - uses: actions/checkout@v2 - - - name: Use Node.js - uses: actions/setup-node@v1 - with: - node-version: '14' - - run: npm ci - - run: npm run env:start - - run: npm run wp -- wp core install --title=WordPress --admin_user=admin --admin_password=password --admin_email=admin@example.com --skip-email --url=http://localhost:8088 --quiet - - run: npm run wp -- wp plugin activate foo-bar - - run: npm run build:js - - run: npm run test:e2e:coverage - - - name: Coveralls - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ./tests/coverage/e2e/lcov.info - flag-name: 'E2E Tests' - parallel: true - - test-js-coverage: + - uses: actions/checkout@v2 + - uses: hmarr/debug-action@v2 + - uses: actions/setup-node@v1 + with: + node-version: "14" + + - name: Install dependencies + run: npm ci + + - name: Build assets + run: npm run build:js + + - name: Start docker local env + run: npm run env:start + + - name: Install WordPress + run: | + npm run wp -- wp core install --title=WordPress --admin_user=admin --admin_password=password --admin_email=admin@example.com --skip-email --url=http://localhost:8088 --quiet + npm run wp -- wp plugin activate foo-bar + + - name: Run E2E tests with coverage + run: npm run test:e2e:coverage + + - name: Coveralls + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: ./tests/coverage/e2e/lcov.info + flag-name: "E2E Tests" + parallel: true + + test-js: needs: [lint] - name: 'JS unit tests (with code coverage)' + name: "JS unit tests (with code coverage)" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - - name: Use Node.js - uses: actions/setup-node@v1 - with: - node-version: '14' - - run: npm ci - - run: npm run test:js:coverage - - - name: Coveralls - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ./tests/coverage/js/lcov.info - flag-name: 'JS Unit Tests' - parallel: true + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: "14" + + - name: Install dependencies + run: npm ci + + - name: Run JS tests + run: npm run test:js:coverage + + - name: Coveralls + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: ./tests/coverage/js/lcov.info + flag-name: "JS Unit Tests" + parallel: true test-php: needs: [lint] - name: 'PHP tests (PHP ${{ matrix.php_versions }}, WordPress ${{ matrix.wp_versions }})' + name: "PHP tests (PHP ${{ matrix.php_versions }}, WordPress ${{ matrix.wp_versions }})" runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: php_versions: [7.4, 7.3, 7.2, 7.1] - wp_versions: ['latest'] + wp_versions: ["latest"] os: [ubuntu-latest] include: - php_versions: 7.4 - wp_versions: 'trunk' + wp_versions: "trunk" os: ubuntu-latest - - php_versions: '7.0' - wp_versions: 'latest' + - php_versions: "7.0" + wp_versions: "latest" os: ubuntu-18.04 # Use ubuntu-18.4 which has MySQL 5.7 for back-compat < PHP7.0 - php_versions: 5.6.20 - wp_versions: 'latest' + wp_versions: "latest" os: ubuntu-18.04 - php_versions: 5.6.20 - wp_versions: '5.0' + wp_versions: "5.0" os: ubuntu-18.04 env: @@ -112,39 +124,39 @@ jobs: COVERALLS: ${{ matrix.php_versions == 7.4 && matrix.wp_versions == 'latest' }} steps: - - uses: actions/checkout@v2 - - name: Setup PHP ${{ matrix.php_versions }} - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php_versions }} - tools: phpunit - - - name: Start MySQL - run: | - sudo systemctl enable mysql.service - sudo systemctl start mysql.service - - - name: Install dependencies - run: composer install - - - name: Install and Run tests - if: ${{ matrix.php_versions == '7.0' || matrix.php_versions == '5.6.20' }} - run: | - wget -O bin/phpunit https://phar.phpunit.de/phpunit-5.phar - chmod +x bin/phpunit - source bin/php-tests.sh wordpress_test root root localhost false bin/phpunit - - - name: Install and Run tests - if: ${{ matrix.php_versions != '7.0' && matrix.php_versions != '5.6.20' }} - run: source bin/php-tests.sh wordpress_test root root localhost + - uses: actions/checkout@v2 + - name: Setup PHP ${{ matrix.php_versions }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php_versions }} + tools: phpunit + + - name: Start MySQL + run: | + sudo systemctl enable mysql.service + sudo systemctl start mysql.service + + - name: Install dependencies + run: composer install + + - name: Install and Run tests + if: ${{ matrix.php_versions == '7.0' || matrix.php_versions == '5.6.20' }} + run: | + wget -O bin/phpunit https://phar.phpunit.de/phpunit-5.phar + chmod +x bin/phpunit + source bin/php-tests.sh wordpress_test root root localhost false bin/phpunit + + - name: Install and Run tests + if: ${{ matrix.php_versions != '7.0' && matrix.php_versions != '5.6.20' }} + run: source bin/php-tests.sh wordpress_test root root localhost finish: - needs: [test-e2e-coverage, test-js-coverage, test-php] + needs: [test-e2e, test-js, test-php] name: Finish runs-on: ubuntu-latest steps: - - name: Coveralls Finished - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.github_token }} - parallel-finished: true + - name: Coveralls Finished + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.github_token }} + parallel-finished: true