Skip to content

Commit 3f4d9b0

Browse files
authored
Merge pull request #344 from wpengine/feat-wpgraphql-logging-skeleton-plugin
chore: WPGraphQL Logging Plugin POC
2 parents fb2331a + a17b273 commit 3f4d9b0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+16575
-7
lines changed

.github/scripts/get_plugin_slug.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ UNIQUE_PLUGINS=($(printf '%s\n' "${PLUGINS[@]}" | sort -u))
3232
# Find the first plugin that actually exists
3333
PLUGIN_SLUG=""
3434
for plugin in "${UNIQUE_PLUGINS[@]}"; do
35-
if [ -d "plugins/$plugin" ]; then
35+
if [ -d "plugins/$plugin" ] || [[ " ${CHANGED_FILES[@]} " =~ "plugins/$plugin/" ]]; then
3636
PLUGIN_SLUG="$plugin"
37-
echo "Found existing plugin directory: $PLUGIN_SLUG"
37+
echo "Found plugin in changes or directory: $PLUGIN_SLUG"
3838
break
3939
fi
4040
done
@@ -45,3 +45,6 @@ if [ -z "$PLUGIN_SLUG" ]; then
4545
fi
4646

4747
echo "slug=$PLUGIN_SLUG" >> "$GITHUB_OUTPUT"
48+
49+
echo "Changed files: $CHANGED_FILES"
50+
echo "Detected plugin(s): ${UNIQUE_PLUGINS[*]}"

.github/workflows/code-quality.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
outputs:
2525
plugins: ${{ steps.detect.outputs.plugins }}
2626
has-plugins: ${{ steps.detect.outputs.has-plugins }}
27+
php-version: ${{ steps.detect-php-version.outputs.php-version }}
2728
steps:
2829
- name: Checkout
2930
uses: actions/checkout@v4
@@ -34,11 +35,13 @@ jobs:
3435
if [ "${{ github.event_name }}" = "push" ]; then
3536
bash .github/scripts/get_plugin_slug.sh main
3637
else
37-
bash .github/scripts/get_plugin_slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}
38+
bash .github/scripts/get_plugin_slug.sh \
39+
${{ github.event.pull_request.base.sha }} \
40+
${{ github.event.pull_request.head.sha }}
3841
fi
3942
4043
- name: Detect changed plugins with quality config
41-
id: detect
44+
id: detect-plugin-slug
4245
run: |
4346
if [ -z "${{ steps.plugin.outputs.slug }}" ]; then
4447
echo "No plugin slug detected"
@@ -58,6 +61,23 @@ jobs:
5861
echo "has-plugins=false" >> $GITHUB_OUTPUT
5962
echo "ℹ️ No phpcs.xml found for plugin: $PLUGIN, skipping quality checks"
6063
fi
64+
- name: Detect PHP version from composer.json
65+
id: detect-php-version
66+
run: |
67+
PLUGIN="${{ steps.plugin.outputs.slug }}"
68+
PHP_VERSION="7.4"
69+
if [ -f "plugins/$PLUGIN/composer.json" ]; then
70+
DETECTED_VERSION=$(jq -r '.require["php"] // empty' plugins/$PLUGIN/composer.json | grep -oE '[0-9]+\.[0-9]+' | head -1)
71+
if [ -n "$DETECTED_VERSION" ]; then
72+
PHP_VERSION="$DETECTED_VERSION"
73+
echo "Detected PHP version $PHP_VERSION from composer.json"
74+
else
75+
echo "No PHP version found in composer.json, using default $PHP_VERSION"
76+
fi
77+
else
78+
echo "No composer.json found, using default PHP version $PHP_VERSION"
79+
fi
80+
echo "php-version=$PHP_VERSION" >> $GITHUB_OUTPUT
6181
quality-checks:
6282
needs: detect-plugins
6383
if: needs.detect-plugins.outputs.has-plugins == 'true'
@@ -75,3 +95,5 @@ jobs:
7595
uses: ./.github/actions/code-quality
7696
with:
7797
working-directory: plugins/${{ matrix.plugin }}
98+
php-version: ${{ needs.detect-plugins.outputs.php-version }}
99+
composer-options: '--no-progress --no-suggest'

.github/workflows/codeception.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ jobs:
4141
if [ "${{ github.event_name }}" = "push" ]; then
4242
bash .github/scripts/get_plugin_slug.sh main
4343
else
44-
bash .github/scripts/get_plugin_slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}
44+
bash .github/scripts/get_plugin_slug.sh \
45+
${{ github.event.pull_request.base.sha }} \
46+
${{ github.event.pull_request.head.sha }}
4547
fi
4648
4749
- name: Detect changed plugins with quality config

.github/workflows/e2e-test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ jobs:
4343
if [ "${{ github.event_name }}" = "push" ]; then
4444
bash .github/scripts/get_plugin_slug.sh main
4545
else
46-
bash .github/scripts/get_plugin_slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}
46+
bash .github/scripts/get_plugin_slug.sh \
47+
${{ github.event.pull_request.base.sha }} \
48+
${{ github.event.pull_request.head.sha }}
4749
fi
4850
4951
- name: Detect changed plugin with E2E config

.github/workflows/plugin-artifact-for-pr.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ jobs:
2020
- name: Get changed plugin directory
2121
id: plugin
2222
run: |
23-
bash .github/scripts/get_plugin_slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}
23+
bash .github/scripts/get_plugin_slug.sh \
24+
${{ github.event.pull_request.base.sha }} \
25+
${{ github.event.pull_request.head.sha }}
2426
2527
- name: Create plugin artifact
2628
uses: ./.github/actions/create-plugin-artifact
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/.devcontainer
2+
/.git
3+
/.github
4+
/.idea
5+
/.log
6+
/.vscode
7+
/.wordpress-org
8+
/bin
9+
/docker
10+
/docker-output
11+
/docs
12+
/img
13+
/phpstan
14+
/plugin-build
15+
/tests
16+
17+
.coveralls.yml
18+
.distignore
19+
.dockerignore
20+
.DS_Store
21+
.env
22+
.env.dist
23+
.gitattributes
24+
.gitignore
25+
.phpcs.xml
26+
.phpcs.xml.dist
27+
.travis.yml
28+
CHANGELOG.md
29+
codeception.dist.yml
30+
codeception.yml
31+
composer.json
32+
composer.lock
33+
docker-compose.yml
34+
phpstan.neon.dist
35+
README.md
36+
schema.graphql
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
PLUGIN_SLUG=wpgraphql-logging
2+
3+
# Configure these to match your existing testing environment or the one you want to create with Docker.
4+
## Usually, these values should match the ones in the `wp-config.php` file.
5+
## If using Local by Flywheel, you can `open AdminerEvo` and find the values in the URL: `http://localhost:{DB_PORT}/?username={DB_USER}&db={DB_NAME}`
6+
## NOTE: Codeception may modify or the database during testing. If you want to preserve your local data, create a new database and use that for the `DB_NAME`.
7+
DB_NAME=wordpress
8+
DB_HOST=mysql
9+
DB_USER=root
10+
DB_PASSWORD=password
11+
DB_PORT=3306
12+
13+
# The local path to the WordPress root directory, the one containing the wp-load.php file.
14+
## This can be a relative path from the directory that contains the codeception.yml file, or an absolute path.
15+
## If you are using Local by Flywheel, you can find the path in the Local by Flywheel app under the site's settings.
16+
WORDPRESS_ROOT_DIR="/var/www/html"
17+
18+
# This table prefix used by the WordPress site, and in Acceptance tests.
19+
WORDPRESS_TABLE_PREFIX=wp_
20+
21+
# The URL and domain of the WordPress site, and in Acceptance tests.
22+
## If the port is in use, you can change it to a different port.
23+
WORDPRESS_URL=http://localhost
24+
WORDPRESS_DOMAIN=localhost
25+
WORDPRESS_ADMIN_PATH=/wp-admin
26+
27+
# The username and password of the administrator user of the WordPress site, and in Acceptance tests.
28+
WORDPRESS_ADMIN_USER=admin
29+
WORDPRESS_ADMIN_PASSWORD=password
30+
WORDPRESS_ADMIN_EMAIL=[email protected]
31+
32+
# Tests will require a MySQL database to run.
33+
# Do not use a database that contains important data!
34+
WORDPRESS_DB_HOST=${DB_HOST}
35+
WORDPRESS_DB_USER=${DB_USER}
36+
WORDPRESS_DB_PASSWORD=${DB_PASSWORD}
37+
WORDPRESS_DB_NAME=${DB_NAME}
38+
WORDPRESS_DB_PORT=${DB_PORT}
39+
40+
# WPUnit tests will use these variables instead.
41+
# By default this is the same as WordPress
42+
TEST_DB_HOST=${WORDPRESS_DB_HOST}
43+
TEST_DB_USER=${WORDPRESS_DB_USER}
44+
TEST_DB_PASSWORD=${WORDPRESS_DB_PASSWORD}
45+
TEST_DB_NAME=${WORDPRESS_DB_NAME}
46+
TEST_DB_PORT=${WORDPRESS_DB_PORT}
47+
# The Integration suite will use this table prefix for the WordPress tables.
48+
TEST_TABLE_PREFIX=test_
49+
50+
# The DSN used by Acceptance tests.
51+
TEST_DB_DSN="mysql:host=${TEST_DB_HOST};port=${TEST_DB_PORT};dbname=${TEST_DB_NAME}"
52+
53+
# The following variables are used to determine test behavior.
54+
55+
# Include 3rd party plugins (e.g. WooCommerce) in the tests.
56+
# Skips recreating the database before running the tests.
57+
SKIP_DB_CREATE=false
58+
# Skips configuring the WordPress installation
59+
SKIP_WP_SETUP=false
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
###############################################################################
2+
# Pre-configured WordPress Installation w/ WPGraphQL Logging Plugin
3+
# For testing only, use in production not recommended. #
4+
###############################################################################
5+
6+
# Use build args to get the right wordpress + php image
7+
ARG WP_VERSION
8+
ARG PHP_VERSION
9+
10+
FROM wordpress:${WP_VERSION:-6.8}-php${PHP_VERSION:-8.2}
11+
12+
# Needed to specify the build args again after the FROM command.
13+
ARG WP_VERSION
14+
ARG PHP_VERSION
15+
16+
# Save the build args for use by the runtime environment
17+
ENV WP_VERSION=${WP_VERSION}
18+
ENV PHP_VERSION=${PHP_VERSION}
19+
20+
SHELL [ "/bin/bash", "-c" ]
21+
22+
# Install required packages
23+
RUN apt-get update && \
24+
apt-get -y install \
25+
git \
26+
ssh \
27+
tar \
28+
gzip \
29+
mariadb-client \
30+
net-tools
31+
32+
# Needed for Codeception WPDB test integration.
33+
RUN docker-php-ext-install pdo pdo_mysql
34+
35+
# Install XDebug 3
36+
RUN if [[ $PHP_VERSION == 7* ]]; then pecl install xdebug-3.1.5; else pecl install xdebug; fi \
37+
&& mkdir -p /usr/local/etc/php/conf.d/disabled \
38+
&& echo "zend_extension=xdebug" > /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
39+
&& echo "xdebug.mode=develop,debug,coverage" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
40+
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
41+
&& echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
42+
&& echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
43+
&& echo "xdebug.max_nesting_level=512" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
44+
;
45+
46+
# Set xdebug configuration off by default. Set USING_XDEBUG=1 in the runtime environment to enable it.
47+
ENV USING_XDEBUG=0
48+
49+
# Install PCOV
50+
# This is needed for Codeception / PHPUnit to track code coverage
51+
RUN apt-get install zip unzip -y \
52+
&& pecl install pcov
53+
54+
# Install Dockerize
55+
ENV DOCKERIZE_VERSION=v0.7.0
56+
RUN curl -L -O https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
57+
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
58+
&& rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
59+
60+
# Install composer
61+
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
62+
RUN chmod +x /usr/local/bin/composer
63+
64+
# Install WP-CLI
65+
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
66+
&& chmod +x wp-cli.phar \
67+
&& mv wp-cli.phar /usr/local/bin/wp
68+
69+
# Install nvm, Node.js, and npm
70+
ENV NVM_DIR=/usr/local/nvm
71+
ENV NODE_VERSION=20
72+
73+
RUN mkdir -p $NVM_DIR
74+
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash \
75+
&& . $NVM_DIR/nvm.sh \
76+
&& nvm install $NODE_VERSION \
77+
&& nvm use $NODE_VERSION \
78+
&& nvm alias default $NODE_VERSION \
79+
&& npm install -g npm
80+
81+
# Setup the container for testing
82+
COPY init-docker.sh /usr/local/bin/
83+
RUN chmod +x /usr/local/bin/init-docker.sh
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
# Exit if any command fails.
4+
set -e
5+
6+
# Wait for the database
7+
dockerize -wait tcp://"${WORDPRESS_DB_HOST}":3306 -timeout 1m
8+
9+
# Get the current user
10+
11+
cd "$WORDPRESS_ROOT_DIR/wp-content/plugins/$PLUGIN_SLUG"
12+
13+
# Load NVM
14+
source $NVM_DIR/nvm.sh
15+
nvm use $NODE_VERSION
16+
17+
# Setup the test environment
18+
chmod +x ./bin/install-test-env.sh
19+
20+
bash -c "./bin/install-test-env.sh"
21+
22+
echo "Setting permissions"
23+
chmod -R 777 "$WORDPRESS_ROOT_DIR/wp-content/plugins/$PLUGIN_SLUG"
24+
25+
# Go back to the root directory
26+
cd "$WORDPRESS_ROOT_DIR"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
# WordPress Coding Standards
5+
# https://make.wordpress.org/core/handbook/coding-standards/
6+
7+
root = true
8+
9+
[*]
10+
charset = utf-8
11+
end_of_line = lf
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
indent_style = tab
15+
16+
17+
[*.md]
18+
trim_trailing_whitespace = false

0 commit comments

Comments
 (0)