Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Feature/#275 generate schema artifact #278

Merged
merged 7 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env → .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ TESTS_ENVS=tests/_envs
#WPGRAPHQL_VERSION=v1.3.3
SKIP_TESTS_CLEANUP=1
SUITES=wpunit

WORDPRESS_DB_HOST=${DB_HOST}
WORDPRESS_DB_USER=${DB_USER}
WORDPRESS_DB_PASSWORD=${DB_PASSWORD}
WORDPRESS_DB_NAME=${DB_NAME}
WORDPRESS_TABLE_PREFIX=${WP_TABLE_PREFIX}
2 changes: 1 addition & 1 deletion .github/workflows/upload-schema-artifact.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Schema Linter
name: Schema Artifact

on:
workflow_dispatch:
Expand Down
18 changes: 14 additions & 4 deletions bin/install-test-env.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#!/usr/bin/env bash

source .env
if [[ ! -f ".env" ]]; then
echo "No .env file was detected. .env.dist has been copied to .env"
echo "Open the .env file and enter values to match your local environment"
cp .env.dist .env
fi

source .env.dist

env | sort

print_usage_instruction() {
echo "Ensure that .env file exist in project root directory exists."
echo "And run the following 'composer install-wp-tests' in the project root directory"
echo "And run the following 'composer build-test' in the project root directory"
exit 1
}

Expand All @@ -29,7 +37,7 @@ TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
WP_CORE_DIR=${TEST_WP_ROOT_FOLDER-$TMPDIR/wordpress/}
PLUGIN_DIR=$(pwd)
DB_SERVE_NAME=${DB_SERVE_NAME-wpgatsby_serve}
DB_SERVE_NAME=${DB_SERVE_NAME-wpgraphql_acf_serve}
SKIP_DB_CREATE=${SKIP_DB_CREATE-false}

download() {
Expand Down Expand Up @@ -132,6 +140,8 @@ install_db() {
fi
fi

env | sort

# create database
RESULT=`mysql -u $DB_USER --password="$DB_PASS" --skip-column-names -e "SHOW DATABASES LIKE '$DB_NAME'"$EXTRA`
if [ "$RESULT" != $DB_NAME ]; then
Expand All @@ -142,7 +152,7 @@ install_db() {
configure_wordpress() {
cd $WP_CORE_DIR
wp config create --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" --skip-check --force=true
wp core install --url=wp.test --title="WPGraphQL ACF Tests" --admin_user=admin --admin_password=password --admin_email=admin@wp.test
wp core install --url=wp.test --title="WPGraphQL for ACF Tests" --admin_user=admin --admin_password=password --admin_email=admin@wp.test
wp rewrite structure '/%year%/%monthnum%/%postname%/'
}

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ services:
local:

app_db:
image: mysql:5.7
image: mariadb:10.2
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: wordpress
Expand Down
22 changes: 14 additions & 8 deletions docker/app.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
###############################################################################
# Pre-configured WordPress Installation w/ WPGraphQL, WPGraphQL for ACF, ACF Pro #
# Pre-configured WordPress Installation w/ WPGraphQL, WPGatsby #
# For testing only, use in production not recommended. #
###############################################################################

# Use build args to get the right wordpress + php image
ARG WP_VERSION
ARG PHP_VERSION

FROM wordpress:${WP_VERSION}-php${PHP_VERSION}-apache

# Needed to specify the build args again after the FROM command.
ARG WP_VERSION
ARG PHP_VERSION

# Save the build args for use by the runtime environment
ENV WP_VERSION=${WP_VERSION}
ENV PHP_VERSION=${PHP_VERSION}

Expand Down Expand Up @@ -39,13 +46,9 @@ RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli

# Set project environmental variables
ENV WP_ROOT_FOLDER="/var/www/html"
ENV WORDPRESS_DB_HOST=${DB_HOST}
ENV WORDPRESS_DB_USER=${DB_USER}
ENV WORDPRESS_DB_PASSWORD=${DB_PASSWORD}
ENV WORDPRESS_DB_NAME=${DB_NAME}
ENV PLUGINS_DIR="${WP_ROOT_FOLDER}/wp-content/plugins"
ENV PROJECT_DIR="${PLUGINS_DIR}/wp-graphql-acf"
ENV WPGRAPHQL_VERSION="${WPGRAPHQL_VERSION}"
ENV PROJECT_DIR="${PLUGINS_DIR}/wp-graphql"
ENV DATA_DUMP_DIR="${PROJECT_DIR}/tests/_data"

# Remove exec statement from base entrypoint script.
RUN sed -i '$d' /usr/local/bin/docker-entrypoint.sh
Expand All @@ -66,13 +69,16 @@ RUN echo "Installing XDebug 3 (in disabled state)" \
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
&& echo "xdebug.max_nesting_level=512" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
;

# Set xdebug configuration off by default. See the entrypoint.sh.
ENV USING_XDEBUG=${USING_XDEBUG}
ENV USING_XDEBUG=0

# Set up entrypoint
WORKDIR /var/www/html
COPY docker/app.setup.sh /usr/local/bin/app-setup.sh
COPY docker/app.post-setup.sh /usr/local/bin/app-post-setup.sh
COPY docker/app.entrypoint.sh /usr/local/bin/app-entrypoint.sh
RUN chmod 755 /usr/local/bin/app-entrypoint.sh
ENTRYPOINT ["app-entrypoint.sh"]
Expand Down
85 changes: 3 additions & 82 deletions docker/app.entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,86 +1,7 @@
#!/bin/bash

if [ "$USING_XDEBUG" == "1" ]; then
echo "Enabling XDebug 3"
mv /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/
fi

# Run WordPress docker entrypoint.
. docker-entrypoint.sh 'apache2'

set +u

# Ensure mysql is loaded
dockerize -wait tcp://${DB_HOST}:${DB_HOST_PORT:-3306} -timeout 1m

# Config WordPress
if [ ! -f "${WP_ROOT_FOLDER}/wp-config.php" ]; then
wp config create \
--path="${WP_ROOT_FOLDER}" \
--dbname="${DB_NAME}" \
--dbuser="${DB_USER}" \
--dbpass="${DB_PASSWORD}" \
--dbhost="${DB_HOST}" \
--dbprefix="${WP_TABLE_PREFIX}" \
--skip-check \
--quiet \
--allow-root
fi

# Install WP if not yet installed
if ! $( wp core is-installed --allow-root ); then
wp core install \
--path="${WP_ROOT_FOLDER}" \
--url="${WP_URL}" \
--title='Test' \
--admin_user="${ADMIN_USERNAME}" \
--admin_password="${ADMIN_PASSWORD}" \
--admin_email="${ADMIN_EMAIL}" \
--allow-root
fi

# Install and activate WPGraphQL

echo "wpgraphql version... ${WPGRAPHQL_VERSION}"
echo "${PLUGINS_DIR}"

if [ ! -f "${PLUGINS_DIR}/wp-graphql/wp-graphql.php" ]; then
# WPGRAPHQL_VERSION in format like v1.2.3
echo ${WPGRAPHQL_VERSION}
if [[ -z ${WPGRAPHQL_VERSION} ]]; then
echo "installing latest WPGraphQL from WordPress.org"
wp plugin install wp-graphql --activate --allow-root
else
echo "Installing WPGraphQL from Github"
git clone https://github.com/wp-graphql/wp-graphql.git "${PLUGINS_DIR}/wp-graphql"
cd "${PLUGINS_DIR}/wp-graphql"
echo "checking out WPGraphQL tag/${WPGRAPHQL_VERSION}"
git checkout tags/${WPGRAPHQL_VERSION} -b master
composer install --no-dev
cd ${WP_ROOT_FOLDER}
echo "activating WPGraphQL"
wp plugin activate wp-graphql --allow-root
wp plugin list --allow-root
fi
else
wp plugin activate wp-graphql --allow-root
fi

# Install and activate ACF Pro
if [ ! -f "${PLUGINS_DIR}/advanced-custom-fields-pro/acf.php" ]; then
wp plugin install \
https://github.com/wp-premium/advanced-custom-fields-pro/archive/master.zip \
--activate --allow-root
else
wp plugin activate advanced-custom-fields-pro --allow-root
fi

# Install and activate WPGatsby
wp plugin activate wp-graphql-acf --allow-root

# Set pretty permalinks.
wp rewrite structure '/%year%/%monthnum%/%postname%/' --allow-root

wp db export "${PROJECT_DIR}/tests/_data/dump.sql" --allow-root
# Run app setup script.
. app-setup.sh
. app-post-setup.sh

exec "$@"
15 changes: 15 additions & 0 deletions docker/app.post-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Activate wp-graphql
wp plugin activate wp-graphql --allow-root

# Set pretty permalinks.
wp rewrite structure '/%year%/%monthnum%/%postname%/' --allow-root

wp db export "${DATA_DUMP_DIR}/dump.sql" --allow-root

# If maintenance mode is active, de-activate it
if $( wp maintenance-mode is-active --allow-root ); then
echo "Deactivating maintenance mode"
wp maintenance-mode deactivate --allow-root
fi
42 changes: 42 additions & 0 deletions docker/app.setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

if [ "$USING_XDEBUG" == "1" ]; then
echo "Enabling XDebug 3"
mv /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/
fi

# Run WordPress docker entrypoint.
. docker-entrypoint.sh 'apache2'

set +u

# Ensure mysql is loaded
dockerize -wait tcp://${DB_HOST}:${DB_HOST_PORT:-3306} -timeout 1m

# Config WordPress
if [ ! -f "${WP_ROOT_FOLDER}/wp-config.php" ]; then
wp config create \
--path="${WP_ROOT_FOLDER}" \
--dbname="${DB_NAME}" \
--dbuser="${DB_USER}" \
--dbpass="${DB_PASSWORD}" \
--dbhost="${DB_HOST}" \
--dbprefix="${WP_TABLE_PREFIX}" \
--skip-check \
--quiet \
--allow-root
fi

# Install WP if not yet installed
if ! $( wp core is-installed --allow-root ); then
wp core install \
--path="${WP_ROOT_FOLDER}" \
--url="${WP_URL}" \
--title='Test' \
--admin_user="${ADMIN_USERNAME}" \
--admin_password="${ADMIN_PASSWORD}" \
--admin_email="${ADMIN_EMAIL}" \
--allow-root
fi

echo "Running WordPress version: $(wp core version --allow-root) at $(wp option get home --allow-root)"
15 changes: 7 additions & 8 deletions docker/testing.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# Container for running Codeception tests on a WPGraphQL Docker instance. #
############################################################################

# Using the 'DESIRED_' prefix to avoid confusion with environment variables of the same name.
FROM wpgraphql-acf-app:latest
ARG WP_VERSION
ARG PHP_VERSION

FROM wp-graphql:latest-wp${WP_VERSION}-php${PHP_VERSION}

LABEL author=jasonbahl
LABEL author_uri=https://github.com/jasonbahl
Expand All @@ -18,8 +20,8 @@ RUN docker-php-ext-install pdo_mysql
RUN apt-get install zip unzip -y \
&& pecl install pcov

ENV COVERAGE=0
ENV SUITES=${SUITES:-zz}
ENV COVERAGE=
ENV SUITES=${SUITES:-}

# Install composer
ENV COMPOSER_ALLOW_SUPERUSER=1
Expand All @@ -34,11 +36,8 @@ ENV PATH "$PATH:~/.composer/vendor/bin"
# Configure php
RUN echo "date.timezone = UTC" >> /usr/local/etc/php/php.ini

# Remove exec statement from base entrypoint script.
RUN sed -i '$d' /usr/local/bin/app-entrypoint.sh

# Set up entrypoint
WORKDIR /var/www/html/wp-content/plugins/wp-graphql-acf
WORKDIR /var/www/html
COPY docker/testing.entrypoint.sh /usr/local/bin/testing-entrypoint.sh
RUN chmod 755 /usr/local/bin/testing-entrypoint.sh
ENTRYPOINT ["testing-entrypoint.sh"]
38 changes: 27 additions & 11 deletions docker/testing.entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

echo "WordPress: ${WP_VERSION} PHP: ${PHP_VERSION}"

# Processes parameters and runs Codeception.
run_tests() {
if [[ -n "$COVERAGE" ]]; then
Expand All @@ -15,10 +17,16 @@ run_tests() {
exit 1
fi

for suite in $suites ; do
echo "Running Test Suite $suite"
vendor/bin/codecept run -c codeception.dist.yml ${suite} ${coverage:-} ${debug:-} --no-exit
done
# If maintenance mode is active, de-activate it
if $( wp maintenance-mode is-active --allow-root ); then
echo "Deactivating maintenance mode"
wp maintenance-mode deactivate --allow-root
fi


# Suites is the comma separated list of suites/tests to run.
echo "Running Test Suite $suites"
vendor/bin/codecept run -c codeception.dist.yml "${suites}" ${coverage:-} ${debug:-} --no-exit
}

# Exits with a status of 0 (true) if provided version number is higher than proceeding numbers.
Expand All @@ -40,17 +48,25 @@ RewriteRule . /index.php [L]

# Move to WordPress root folder
workdir="$PWD"
echo "Moving to WordPress root directory."
echo "Moving to WordPress root directory ${WP_ROOT_FOLDER}."
cd ${WP_ROOT_FOLDER}

# Run app entrypoint script.
. app-entrypoint.sh
# Because we are starting apache independetly of the docker image,
# we set WORDPRESS environment variables so apache see them and used in the wp-config.php
echo "export WORDPRESS_DB_HOST=${WORDPRESS_DB_HOST}" >> /etc/apache2/envvars
echo "export WORDPRESS_DB_USER=${WORDPRESS_DB_USER}" >> /etc/apache2/envvars
echo "export WORDPRESS_DB_PASSWORD=${WORDPRESS_DB_PASSWORD}" >> /etc/apache2/envvars
echo "export WORDPRESS_DB_NAME=${WORDPRESS_DB_NAME}" >> /etc/apache2/envvars

# Run app setup scripts.
. app-setup.sh
. app-post-setup.sh

write_htaccess

# Return to PWD.
echo "Moving back to project working directory."
cd ${workdir}
echo "Moving back to project working directory ${PROJECT_DIR}"
cd ${PROJECT_DIR}

# Ensure Apache is running
service apache2 start
Expand Down Expand Up @@ -78,8 +94,8 @@ if version_gt $PHP_VERSION 7.0 && [[ -n "$COVERAGE" ]] && [[ -z "$USING_XDEBUG"
echo "Using pcov/clobber for codecoverage"
docker-php-ext-enable pcov
echo "pcov.enabled=1" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini
echo "pcov.directory = /var/www/html/wp-content/plugins/wp-graphql" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini
COMPOSER_MEMORY_LIMIT=-1 composer require --dev pcov/clobber
echo "pcov.directory = ${PROJECT_DIR}" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini
COMPOSER_MEMORY_LIMIT=-1 composer require pcov/clobber --dev
vendor/bin/pcov clobber
elif [[ -n "$COVERAGE" ]] && [[ -n "$USING_XDEBUG" ]]; then
echo "Using XDebug for codecoverage"
Expand Down