Skip to content

Commit

Permalink
Merge pull request #249 from myrotvorets/refactor-ci
Browse files Browse the repository at this point in the history
Add PHPUnit and WP PHPUnit dependencies; refactor CI workflow
  • Loading branch information
myrotvorets-team authored Feb 3, 2024
2 parents cfa791c + e6d56b2 commit f987701
Show file tree
Hide file tree
Showing 6 changed files with 600 additions and 302 deletions.
31 changes: 13 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ jobs:
fail-fast: false
matrix:
config:
- { wp: latest, ms: 'no', php: '8.1', phpunit: 9, coverage: 'yes' }
- { wp: nightly, ms: 'no', php: '8.1', phpunit: 9, coverage: 'yes' }
- { wp: latest, ms: 'yes', php: '8.1', phpunit: 9, coverage: 'yes' }
- { wp: nightly, ms: 'yes', php: '8.1', phpunit: 9, coverage: 'yes' }
- { wp: latest, ms: 'no', php: '8.2', phpunit: 9 }
- { wp: nightly, ms: 'no', php: '8.2', phpunit: 9 }
- { wp: latest, ms: 'yes', php: '8.2', phpunit: 9 }
- { wp: nightly, ms: 'yes', php: '8.2', phpunit: 9 }
- { wp: latest, ms: 'no', php: '8.3', phpunit: 9 }
- { wp: nightly, ms: 'no', php: '8.3', phpunit: 9 }
- { wp: latest, ms: 'yes', php: '8.3', phpunit: 9 }
- { wp: nightly, ms: 'yes', php: '8.3', phpunit: 9 }
- { wp: latest, ms: 'no', php: '8.1', coverage: 'yes' }
- { wp: nightly, ms: 'no', php: '8.1', coverage: 'yes' }
- { wp: latest, ms: 'yes', php: '8.1', coverage: 'yes' }
- { wp: nightly, ms: 'yes', php: '8.1', coverage: 'yes' }
- { wp: latest, ms: 'no', php: '8.2' }
- { wp: nightly, ms: 'no', php: '8.2' }
- { wp: latest, ms: 'yes', php: '8.2' }
- { wp: nightly, ms: 'yes', php: '8.2' }
- { wp: latest, ms: 'no', php: '8.3' }
- { wp: nightly, ms: 'no', php: '8.3' }
- { wp: latest, ms: 'yes', php: '8.3' }
- { wp: nightly, ms: 'yes', php: '8.3' }
services:
mysql:
image: mariadb:latest@sha256:a9385bb457ebf4600da632cc331f11a5328c582bfb492aa76517282bcae1dcc9
Expand Down Expand Up @@ -66,11 +66,6 @@ jobs:
env:
fail-fast: 'true'

- name: Install PHPUnit
run: |
wget -q -O /usr/local/bin/phpunit "https://phar.phpunit.de/phpunit-${{ matrix.config.phpunit }}.phar"
chmod +x /usr/local/bin/phpunit
- name: Install dependencies
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # tag=2.2.0

Expand All @@ -96,7 +91,7 @@ jobs:
if [ "${{ steps.coverage.outputs.coverage }}" != 'none' ]; then
OPTIONS="$OPTIONS --coverage-clover=clover.xml"
fi
phpunit --order-by=random ${OPTIONS}
vendor/bin/phpunit --order-by=random ${OPTIONS}
- name: Upload coverage report
uses: codecov/codecov-action@e0b68c6749509c5f83f984dd99a76a1c1a231044 # v4.0.1
Expand Down
153 changes: 103 additions & 50 deletions bin/test
Original file line number Diff line number Diff line change
@@ -1,76 +1,129 @@
#!/bin/sh

set -x

ARGS=""
while [ $# -gt 0 ]; do
case "$1" in
--wp)
shift
WORDPRESS_VERSION="$1"
;;

--multisite)
shift
WP_MULTISITE="$1"
;;

*)
ARGS="${ARGS} $1"
;;
esac

shift
case "$1" in
--wp)
shift
WP_VERSION="$1"
;;

--multisite)
shift
WP_MULTISITE="$1"
;;

--php)
shift
PHP_VERSION="$1"
;;

--php-options)
shift
PHP_OPTIONS="$1"
;;

--phpunit)
shift
PHPUNIT_VERSION="$1"
;;

--network)
shift
NETWORK_NAME_OVERRIDE="$1"
;;

--dbhost)
shift
MYSQL_HOST_OVERRIDE="$1"
;;

--docker-options)
shift
DOCKER_OPTIONS="$1"
;;

*)
ARGS="${ARGS} $1"
;;
esac

shift
done

: "${WORDPRESS_VERSION:=latest}"
: "${WP_VERSION:=latest}"
: "${WP_MULTISITE:=0}"
: "${PHP_VERSION:=""}"
: "${PHP_OPTIONS:=""}"
: "${PHPUNIT_VERSION:=""}"
: "${DOCKER_OPTIONS:=""}"

export WORDPRESS_VERSION
export WP_VERSION
export WP_MULTISITE

if [ $# -ge 2 ]; then
shift 2
elif [ $# -ge 1 ]; then
shift 1
fi
export PHP_VERSION
export PHP_OPTIONS
export PHPUNIT_VERSION

echo "--------------"
echo "Will test with WORDPRESS_VERSION=${WORDPRESS_VERSION} and WP_MULTISITE=${WP_MULTISITE}"
echo "Will test with WP_VERSION=${WP_VERSION} and WP_MULTISITE=${WP_MULTISITE}"
echo "--------------"
echo

MARIADB_VERSION="10.3"
UUID=$(date +%s000)
NETWORK_NAME="tests-${UUID}"

docker network create "${NETWORK_NAME}"
if [ -z "${NETWORK_NAME_OVERRIDE}" ]; then
NETWORK_NAME="tests-${UUID}"
docker network create "${NETWORK_NAME}"
else
NETWORK_NAME="${NETWORK_NAME_OVERRIDE}"
fi

export MYSQL_HOST="db-${UUID}"
export MYSQL_USER=wordpress
export MYSQL_PASSWORD=wordpress
export MYSQL_DATABASE=wordpress_test
export MYSQL_ROOT_PASSWORD=wordpress
export MYSQL_INITDB_SKIP_TZINFO=1

db=$(docker run --rm --network "${NETWORK_NAME}" --name "${MYSQL_HOST}" -e MYSQL_ROOT_PASSWORD -e MARIADB_INITDB_SKIP_TZINFO -e MYSQL_USER -e MYSQL_PASSWORD -e MYSQL_DATABASE -d "mariadb:${MARIADB_VERSION}")
db=""
if [ -z "${MYSQL_HOST_OVERRIDE}" ]; then
MYSQL_HOST="db-${UUID}"
db=$(docker run --rm --network "${NETWORK_NAME}" --name "${MYSQL_HOST}" -e MYSQL_ROOT_PASSWORD="wordpress" -e MYSQL_INITDB_SKIP_TZINFO=1 -e MYSQL_USER -e MYSQL_PASSWORD -e MYSQL_DATABASE -d "mysql:8")
else
MYSQL_HOST="${MYSQL_HOST_OVERRIDE}"
fi

export MYSQL_HOST

cleanup() {
docker rm -f "${db}"
docker network rm "${NETWORK_NAME}"
if [ -n "${db}" ]; then
docker rm -f "${db}"
fi

if [ -z "${NETWORK_NAME_OVERRIDE}" ]; then
docker network rm "${NETWORK_NAME}"
fi
}

trap cleanup EXIT

# shellcheck disable=SC2086 # ARGS must not be quoted
if [ -z "${CI}" ]; then
interactive="-it"
else
interactive=""
fi

# shellcheck disable=SC2086,SC2248,SC2312 # ARGS and DOCKER_OPTIONS must not be quoted
docker run \
--rm \
--network "${NETWORK_NAME}" \
-e WORDPRESS_VERSION \
-e WP_MULTISITE \
-e MYSQL_USER \
-e MYSQL_PASSWORD \
-e MYSQL_DATABASE \
-e MYSQL_HOST \
-v "$(pwd):/app" \
wildwildangel/wp-test-runner "/usr/local/bin/runner" ${ARGS}
${interactive} \
--rm \
--network "${NETWORK_NAME}" \
-e WP_VERSION \
-e WP_MULTISITE \
-e PHP_VERSION \
-e PHP_OPTIONS \
-e PHPUNIT_VERSION \
-e MYSQL_USER \
-e MYSQL_PASSWORD \
-e MYSQL_DB="${MYSQL_DATABASE}" \
-e MYSQL_HOST \
-e DISABLE_XDEBUG=1 \
${DOCKER_OPTIONS} \
-v "$(pwd):/home/circleci/project" \
ghcr.io/automattic/vip-container-images/wp-test-runner:latest \
${ARGS}
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
"johnpbloch/wordpress-core": "^6.4.3",
"php-stubs/wordpress-stubs": "^6.4.1",
"phpcompatibility/phpcompatibility-wp": "^2.1.4",
"phpunit/phpunit": "^9.6.16",
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "^5.21.1",
"wp-phpunit/wp-phpunit": "^6.4",
"yoast/phpunit-polyfills": "^2.0"
},
"config": {
Expand Down
Loading

0 comments on commit f987701

Please sign in to comment.