Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/loud-baboons-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wpengine/hwp-previews-wordpress-plugin": patch
---

chore: Updated action and filter docs.
43 changes: 43 additions & 0 deletions .github/scripts/get-plugin-slug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

set -e

BASE_SHA="$1"
HEAD_SHA="$2"

git fetch --prune --unshallow

# Get changed files in plugins subdirectories
CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" | grep '^plugins/[^/]\+/' || true)

if [ -z "$CHANGED_FILES" ]; then
echo "No plugin files changed"
exit 1
fi

# Extract plugin names from both old and new paths
PLUGINS=()
for file in $CHANGED_FILES; do
plugin=$(echo $file | cut -d/ -f2)
PLUGINS+=("$plugin")
done

# Get unique plugin names
UNIQUE_PLUGINS=($(printf '%s\n' "${PLUGINS[@]}" | sort -u))

# Find the first plugin that actually exists
PLUGIN_SLUG=""
for plugin in "${UNIQUE_PLUGINS[@]}"; do
if [ -d "plugins/$plugin" ]; then
PLUGIN_SLUG="$plugin"
echo "Found existing plugin directory: $PLUGIN_SLUG"
break
fi
done

if [ -z "$PLUGIN_SLUG" ]; then
echo "No valid plugin directory found"
exit 1
fi

echo "slug=$PLUGIN_SLUG" >> "$GITHUB_OUTPUT"
44 changes: 12 additions & 32 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,51 +28,31 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Get changed plugin directory
id: plugin
run: |
bash .github/scripts/get-plugin-slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}

- name: Detect changed plugins with quality config
id: detect
run: |
git fetch --prune --unshallow
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' || true)

if [ -z "$CHANGED_FILES" ]; then
echo "No plugin files changed"
if [ -z "${{ steps.plugin.outputs.slug }}" ]; then
echo "No plugin slug detected"
echo "plugins=[]" >> $GITHUB_OUTPUT
echo "has-plugins=false" >> $GITHUB_OUTPUT
exit 0
fi

# Extract unique plugin names and check for phpcs.xml
PLUGINS_WITH_CONFIG=()
CHECKED_PLUGINS=()

for file in $CHANGED_FILES; do
plugin=$(echo $file | cut -d/ -f2)

# Skip if we already checked this plugin
if [[ " ${CHECKED_PLUGINS[@]} " =~ " $plugin " ]]; then
continue
fi

CHECKED_PLUGINS+=("$plugin")

if [ -f "plugins/$plugin/phpcs.xml" ]; then
PLUGINS_WITH_CONFIG+=("$plugin")
echo "✅ Found phpcs.xml for plugin: $plugin"
else
echo "ℹ️ No phpcs.xml found for plugin: $plugin, skipping quality checks"
fi
done
PLUGIN="${{ steps.plugin.outputs.slug }}"

# Convert to JSON array
if [ ${#PLUGINS_WITH_CONFIG[@]} -gt 0 ]; then
PLUGINS_JSON=$(printf '%s\n' "${PLUGINS_WITH_CONFIG[@]}" | jq -R -s -c 'split("\n")[:-1]')
echo "plugins=${PLUGINS_JSON}" >> $GITHUB_OUTPUT
if [ -f "plugins/$PLUGIN/phpcs.xml" ]; then
echo "plugins=[\"$PLUGIN\"]" >> $GITHUB_OUTPUT
echo "has-plugins=true" >> $GITHUB_OUTPUT
echo "Found ${#PLUGINS_WITH_CONFIG[@]} plugin(s) with quality config: ${PLUGINS_WITH_CONFIG[*]}"
echo "Found phpcs.xml for plugin: $PLUGIN"
else
echo "plugins=[]" >> $GITHUB_OUTPUT
echo "has-plugins=false" >> $GITHUB_OUTPUT
echo "No plugins found with quality configuration"
echo "ℹ️ No phpcs.xml found for plugin: $PLUGIN, skipping quality checks"
fi
quality-checks:
needs: detect-plugins
Expand Down
59 changes: 13 additions & 46 deletions .github/workflows/codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,64 +35,31 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Detect changed plugins with test config
id: detect
- name: Get changed plugin directory
id: plugin
run: |
git fetch --prune --unshallow
bash .github/scripts/get-plugin-slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}

# Get changed files based on event type
if [ "${{ github.event_name }}" = "pull_request" ]; then
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' || true)
else
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD | grep '^plugins/' || true)
fi

if [ -z "$CHANGED_FILES" ]; then
echo "No plugin files changed"
- name: Detect changed plugins with quality config
id: detect
run: |
if [ -z "${{ steps.plugin.outputs.slug }}" ]; then
echo "No plugin slug detected"
echo "plugins=[]" >> $GITHUB_OUTPUT
echo "has-plugins=false" >> $GITHUB_OUTPUT
exit 0
fi

# Extract unique plugin names and check for test config
PLUGINS_WITH_CONFIG=()
CHECKED_PLUGINS=()

for file in $CHANGED_FILES; do
plugin=$(echo $file | cut -d/ -f2)

# Skip if we already checked this plugin
if [[ " ${CHECKED_PLUGINS[@]} " =~ " $plugin " ]]; then
continue
fi

CHECKED_PLUGINS+=("$plugin")

# Check for both codeception.dist.yml and composer.json
if [ -f "plugins/$plugin/codeception.dist.yml" ] && [ -f "plugins/$plugin/composer.json" ]; then
PLUGINS_WITH_CONFIG+=("$plugin")
echo "✅ Found test config for plugin: $plugin (codeception.dist.yml + composer.json)"
else
echo "ℹ️ Missing test config for plugin: $plugin, skipping tests"
if [ ! -f "plugins/$plugin/codeception.dist.yml" ]; then
echo " - Missing: codeception.dist.yml"
fi
if [ ! -f "plugins/$plugin/composer.json" ]; then
echo " - Missing: composer.json"
fi
fi
done
PLUGIN="${{ steps.plugin.outputs.slug }}"

# Convert to JSON array
if [ ${#PLUGINS_WITH_CONFIG[@]} -gt 0 ]; then
PLUGINS_JSON=$(printf '%s\n' "${PLUGINS_WITH_CONFIG[@]}" | jq -R -s -c 'split("\n")[:-1]')
echo "plugins=${PLUGINS_JSON}" >> $GITHUB_OUTPUT
if [ -f "plugins/$PLUGIN/codeception.dist.yml" ]; then
echo "plugins=[\"$PLUGIN\"]" >> $GITHUB_OUTPUT
echo "has-plugins=true" >> $GITHUB_OUTPUT
echo "Found ${#PLUGINS_WITH_CONFIG[@]} plugin(s) with test config: ${PLUGINS_WITH_CONFIG[*]}"
echo "Found codeception.dist.yml for plugin: $PLUGIN"
else
echo "plugins=[]" >> $GITHUB_OUTPUT
echo "has-plugins=false" >> $GITHUB_OUTPUT
echo "No plugins found with test configuration"
echo "ℹ️ No codeception.dist.yml found for plugin: $PLUGIN, skipping automated tests"
fi

continuous_integration:
Expand Down
72 changes: 61 additions & 11 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,74 @@
# This does the following:
# 1. Detects modified plugins that have .wp-env.json configuration
# 2. Runs Playwright E2E tests on those plugins using the custom action
# 3. Creates a matrix job for each plugin that has a quality configuration
# Bonus: This means you can have plugin specific badges e.g.
# [![E2E Te](https://img.shields.io/github/check-runs/wpengine/hwptoolkit/main?checkName=hwp-previews%20Playwright%20E2E%20Tests&label=End-to-End%20Tests)](https://github.com/wpengine/hwptoolkit/actions)


name: End-to-End Tests

on:
push:
branches:
- main
paths:
- 'plugins/hwp-previews/**.php'
- 'plugins/hwp-previews/**.js'
- 'plugins/hwp-previews/**.css'
- 'plugins/hwp-previews/**.json'

- 'plugins/**.php'
- 'plugins/**.js'
- 'plugins/**.css'
- 'plugins/**.json'
pull_request:
branches:
- main
paths:
- "plugins/hwp-previews/**"
- "plugins/**"

jobs:
detect-plugin:
runs-on: ubuntu-latest
name: Detect plugin with E2E tests
outputs:
plugin: ${{ steps.detect.outputs.plugin }}
has-plugin: ${{ steps.detect.outputs.has-plugin }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get changed plugin directory
id: plugin
run: |
bash .github/scripts/get-plugin-slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}

- name: Detect changed plugin with E2E config
id: detect
run: |
if [ -z "${{ steps.plugin.outputs.slug }}" ]; then
echo "No plugin slug detected"
echo "plugin=" >> $GITHUB_OUTPUT
echo "has-plugin=false" >> $GITHUB_OUTPUT
exit 0
fi

PLUGIN="${{ steps.plugin.outputs.slug }}"

# Check for .wp-env.json file in the plugin directory
if [ -f "plugins/$PLUGIN/.wp-env.json" ]; then
echo "plugin=$PLUGIN" >> $GITHUB_OUTPUT
echo "has-plugin=true" >> $GITHUB_OUTPUT
echo "✅ Found .wp-env.json for plugin: $PLUGIN"
else
echo "plugin=" >> $GITHUB_OUTPUT
echo "has-plugin=false" >> $GITHUB_OUTPUT
echo "ℹ️ No .wp-env.json found for plugin: $PLUGIN, skipping E2E tests"
fi

playwright-e2e-tests:
needs: detect-plugin
if: needs.detect-plugin.outputs.has-plugin == 'true'
runs-on: ubuntu-24.04
name: ${{ needs.detect-plugin.outputs.plugin }} Playwright E2E Tests
env:
PLUGIN: ${{ needs.detect-plugin.outputs.plugin }}

steps:
- name: Checkout code
Expand All @@ -37,22 +87,22 @@ jobs:
uses: ./.github/actions/setup-php-composer
with:
php-version: 8.2
working-directory: plugins/hwp-previews
working-directory: plugins/${{ env.PLUGIN }}
composer-options: '--no-progress --optimize-autoloader --no-dev'

- name: Install playwright browsers
run: npx playwright install --with-deps
working-directory: plugins/hwp-previews
working-directory: plugins/${{ env.PLUGIN }}

- name: Start wp-env
run: |
npm run wp-env start
working-directory: plugins/hwp-previews
working-directory: plugins/${{ env.PLUGIN }}

- name: Run Playwright tests
run: npm run test:e2e
working-directory: plugins/hwp-previews
working-directory: plugins/${{ env.PLUGIN }}

- name: Stop wp-env
run: npm run wp-env stop
working-directory: plugins/hwp-previews
working-directory: plugins/${{ env.PLUGIN }}
14 changes: 6 additions & 8 deletions .github/workflows/plugin-artifact-for-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ jobs:
- name: Get changed plugin directory
id: plugin
run: |
git fetch --prune --unshallow
plugin=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' | head -1 | cut -d/ -f2)
echo "slug=$plugin" >> $GITHUB_OUTPUT
bash .github/scripts/get-plugin-slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}

- name: Create plugin artifact
uses: ./.github/actions/create-plugin-artifact
Expand All @@ -44,20 +42,20 @@ jobs:
const artifactUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
const slug = process.env.PLUGIN_SLUG;
const body = `ℹ️ [Download the latest ${slug} plugin zip from this PR](${artifactUrl})\n<em>(See the 'Artifacts' section at the bottom)</em>`;

// Find existing comment from this bot
const comments = await github.rest.issues.listComments({
issue_number: pr.number,
owner: context.repo.owner,
repo: context.repo.repo
});
const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&

const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.user.login === 'github-actions[bot]' &&
comment.body.includes(`ℹ️ [Download the latest ${slug} plugin zip from this PR]`)
);

if (botComment) {
// Update existing comment
core.info(`Updating existing comment with ID: ${botComment.id}`);
Expand Down
Loading
Loading