Skip to content

Commit 2346d68

Browse files
authored
Merge pull request #292 from wpengine/chore-hwp-previews-docs-workflow-tidy-up
chore: Previews and Workflow Tidy up
2 parents ac72766 + 8ab4aa5 commit 2346d68

File tree

14 files changed

+587
-309
lines changed

14 files changed

+587
-309
lines changed

.changeset/loud-baboons-bake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@wpengine/hwp-previews-wordpress-plugin": patch
3+
---
4+
5+
chore: Updated action and filter docs.

.github/scripts/get-plugin-slug.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
BASE_SHA="$1"
6+
HEAD_SHA="$2"
7+
8+
git fetch --prune --unshallow
9+
10+
# Get changed files in plugins subdirectories
11+
CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" | grep '^plugins/[^/]\+/' || true)
12+
13+
if [ -z "$CHANGED_FILES" ]; then
14+
echo "No plugin files changed"
15+
exit 1
16+
fi
17+
18+
# Extract plugin names from both old and new paths
19+
PLUGINS=()
20+
for file in $CHANGED_FILES; do
21+
plugin=$(echo $file | cut -d/ -f2)
22+
PLUGINS+=("$plugin")
23+
done
24+
25+
# Get unique plugin names
26+
UNIQUE_PLUGINS=($(printf '%s\n' "${PLUGINS[@]}" | sort -u))
27+
28+
# Find the first plugin that actually exists
29+
PLUGIN_SLUG=""
30+
for plugin in "${UNIQUE_PLUGINS[@]}"; do
31+
if [ -d "plugins/$plugin" ]; then
32+
PLUGIN_SLUG="$plugin"
33+
echo "Found existing plugin directory: $PLUGIN_SLUG"
34+
break
35+
fi
36+
done
37+
38+
if [ -z "$PLUGIN_SLUG" ]; then
39+
echo "No valid plugin directory found"
40+
exit 1
41+
fi
42+
43+
echo "slug=$PLUGIN_SLUG" >> "$GITHUB_OUTPUT"

.github/workflows/code-quality.yml

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,51 +28,31 @@ jobs:
2828
- name: Checkout
2929
uses: actions/checkout@v4
3030

31+
- name: Get changed plugin directory
32+
id: plugin
33+
run: |
34+
bash .github/scripts/get-plugin-slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}
35+
3136
- name: Detect changed plugins with quality config
3237
id: detect
3338
run: |
34-
git fetch --prune --unshallow
35-
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' || true)
36-
37-
if [ -z "$CHANGED_FILES" ]; then
38-
echo "No plugin files changed"
39+
if [ -z "${{ steps.plugin.outputs.slug }}" ]; then
40+
echo "No plugin slug detected"
3941
echo "plugins=[]" >> $GITHUB_OUTPUT
4042
echo "has-plugins=false" >> $GITHUB_OUTPUT
4143
exit 0
4244
fi
4345
44-
# Extract unique plugin names and check for phpcs.xml
45-
PLUGINS_WITH_CONFIG=()
46-
CHECKED_PLUGINS=()
47-
48-
for file in $CHANGED_FILES; do
49-
plugin=$(echo $file | cut -d/ -f2)
50-
51-
# Skip if we already checked this plugin
52-
if [[ " ${CHECKED_PLUGINS[@]} " =~ " $plugin " ]]; then
53-
continue
54-
fi
55-
56-
CHECKED_PLUGINS+=("$plugin")
57-
58-
if [ -f "plugins/$plugin/phpcs.xml" ]; then
59-
PLUGINS_WITH_CONFIG+=("$plugin")
60-
echo "✅ Found phpcs.xml for plugin: $plugin"
61-
else
62-
echo "ℹ️ No phpcs.xml found for plugin: $plugin, skipping quality checks"
63-
fi
64-
done
46+
PLUGIN="${{ steps.plugin.outputs.slug }}"
6547
66-
# Convert to JSON array
67-
if [ ${#PLUGINS_WITH_CONFIG[@]} -gt 0 ]; then
68-
PLUGINS_JSON=$(printf '%s\n' "${PLUGINS_WITH_CONFIG[@]}" | jq -R -s -c 'split("\n")[:-1]')
69-
echo "plugins=${PLUGINS_JSON}" >> $GITHUB_OUTPUT
48+
if [ -f "plugins/$PLUGIN/phpcs.xml" ]; then
49+
echo "plugins=[\"$PLUGIN\"]" >> $GITHUB_OUTPUT
7050
echo "has-plugins=true" >> $GITHUB_OUTPUT
71-
echo "Found ${#PLUGINS_WITH_CONFIG[@]} plugin(s) with quality config: ${PLUGINS_WITH_CONFIG[*]}"
51+
echo "Found phpcs.xml for plugin: $PLUGIN"
7252
else
7353
echo "plugins=[]" >> $GITHUB_OUTPUT
7454
echo "has-plugins=false" >> $GITHUB_OUTPUT
75-
echo "No plugins found with quality configuration"
55+
echo "ℹ️ No phpcs.xml found for plugin: $PLUGIN, skipping quality checks"
7656
fi
7757
quality-checks:
7858
needs: detect-plugins

.github/workflows/codeception.yml

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -35,64 +35,31 @@ jobs:
3535
- name: Checkout
3636
uses: actions/checkout@v4
3737

38-
- name: Detect changed plugins with test config
39-
id: detect
38+
- name: Get changed plugin directory
39+
id: plugin
4040
run: |
41-
git fetch --prune --unshallow
41+
bash .github/scripts/get-plugin-slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}
4242
43-
# Get changed files based on event type
44-
if [ "${{ github.event_name }}" = "pull_request" ]; then
45-
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' || true)
46-
else
47-
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD | grep '^plugins/' || true)
48-
fi
49-
50-
if [ -z "$CHANGED_FILES" ]; then
51-
echo "No plugin files changed"
43+
- name: Detect changed plugins with quality config
44+
id: detect
45+
run: |
46+
if [ -z "${{ steps.plugin.outputs.slug }}" ]; then
47+
echo "No plugin slug detected"
5248
echo "plugins=[]" >> $GITHUB_OUTPUT
5349
echo "has-plugins=false" >> $GITHUB_OUTPUT
5450
exit 0
5551
fi
5652
57-
# Extract unique plugin names and check for test config
58-
PLUGINS_WITH_CONFIG=()
59-
CHECKED_PLUGINS=()
60-
61-
for file in $CHANGED_FILES; do
62-
plugin=$(echo $file | cut -d/ -f2)
63-
64-
# Skip if we already checked this plugin
65-
if [[ " ${CHECKED_PLUGINS[@]} " =~ " $plugin " ]]; then
66-
continue
67-
fi
68-
69-
CHECKED_PLUGINS+=("$plugin")
70-
71-
# Check for both codeception.dist.yml and composer.json
72-
if [ -f "plugins/$plugin/codeception.dist.yml" ] && [ -f "plugins/$plugin/composer.json" ]; then
73-
PLUGINS_WITH_CONFIG+=("$plugin")
74-
echo "✅ Found test config for plugin: $plugin (codeception.dist.yml + composer.json)"
75-
else
76-
echo "ℹ️ Missing test config for plugin: $plugin, skipping tests"
77-
if [ ! -f "plugins/$plugin/codeception.dist.yml" ]; then
78-
echo " - Missing: codeception.dist.yml"
79-
fi
80-
if [ ! -f "plugins/$plugin/composer.json" ]; then
81-
echo " - Missing: composer.json"
82-
fi
83-
fi
84-
done
53+
PLUGIN="${{ steps.plugin.outputs.slug }}"
8554
86-
# Convert to JSON array
87-
if [ ${#PLUGINS_WITH_CONFIG[@]} -gt 0 ]; then
88-
PLUGINS_JSON=$(printf '%s\n' "${PLUGINS_WITH_CONFIG[@]}" | jq -R -s -c 'split("\n")[:-1]')
89-
echo "plugins=${PLUGINS_JSON}" >> $GITHUB_OUTPUT
55+
if [ -f "plugins/$PLUGIN/codeception.dist.yml" ]; then
56+
echo "plugins=[\"$PLUGIN\"]" >> $GITHUB_OUTPUT
9057
echo "has-plugins=true" >> $GITHUB_OUTPUT
91-
echo "Found ${#PLUGINS_WITH_CONFIG[@]} plugin(s) with test config: ${PLUGINS_WITH_CONFIG[*]}"
58+
echo "Found codeception.dist.yml for plugin: $PLUGIN"
9259
else
9360
echo "plugins=[]" >> $GITHUB_OUTPUT
9461
echo "has-plugins=false" >> $GITHUB_OUTPUT
95-
echo "No plugins found with test configuration"
62+
echo "ℹ️ No codeception.dist.yml found for plugin: $PLUGIN, skipping automated tests"
9663
fi
9764
9865
continuous_integration:

.github/workflows/e2e-test.yml

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,74 @@
1+
# This does the following:
2+
# 1. Detects modified plugins that have .wp-env.json configuration
3+
# 2. Runs Playwright E2E tests on those plugins using the custom action
4+
# 3. Creates a matrix job for each plugin that has a quality configuration
5+
# Bonus: This means you can have plugin specific badges e.g.
6+
# [![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)
7+
8+
19
name: End-to-End Tests
210

311
on:
412
push:
513
branches:
614
- main
715
paths:
8-
- 'plugins/hwp-previews/**.php'
9-
- 'plugins/hwp-previews/**.js'
10-
- 'plugins/hwp-previews/**.css'
11-
- 'plugins/hwp-previews/**.json'
12-
16+
- 'plugins/**.php'
17+
- 'plugins/**.js'
18+
- 'plugins/**.css'
19+
- 'plugins/**.json'
1320
pull_request:
1421
branches:
1522
- main
1623
paths:
17-
- "plugins/hwp-previews/**"
24+
- "plugins/**"
1825

1926
jobs:
27+
detect-plugin:
28+
runs-on: ubuntu-latest
29+
name: Detect plugin with E2E tests
30+
outputs:
31+
plugin: ${{ steps.detect.outputs.plugin }}
32+
has-plugin: ${{ steps.detect.outputs.has-plugin }}
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v4
36+
37+
- name: Get changed plugin directory
38+
id: plugin
39+
run: |
40+
bash .github/scripts/get-plugin-slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}
41+
42+
- name: Detect changed plugin with E2E config
43+
id: detect
44+
run: |
45+
if [ -z "${{ steps.plugin.outputs.slug }}" ]; then
46+
echo "No plugin slug detected"
47+
echo "plugin=" >> $GITHUB_OUTPUT
48+
echo "has-plugin=false" >> $GITHUB_OUTPUT
49+
exit 0
50+
fi
51+
52+
PLUGIN="${{ steps.plugin.outputs.slug }}"
53+
54+
# Check for .wp-env.json file in the plugin directory
55+
if [ -f "plugins/$PLUGIN/.wp-env.json" ]; then
56+
echo "plugin=$PLUGIN" >> $GITHUB_OUTPUT
57+
echo "has-plugin=true" >> $GITHUB_OUTPUT
58+
echo "✅ Found .wp-env.json for plugin: $PLUGIN"
59+
else
60+
echo "plugin=" >> $GITHUB_OUTPUT
61+
echo "has-plugin=false" >> $GITHUB_OUTPUT
62+
echo "ℹ️ No .wp-env.json found for plugin: $PLUGIN, skipping E2E tests"
63+
fi
64+
2065
playwright-e2e-tests:
66+
needs: detect-plugin
67+
if: needs.detect-plugin.outputs.has-plugin == 'true'
2168
runs-on: ubuntu-24.04
69+
name: ${{ needs.detect-plugin.outputs.plugin }} Playwright E2E Tests
70+
env:
71+
PLUGIN: ${{ needs.detect-plugin.outputs.plugin }}
2272

2373
steps:
2474
- name: Checkout code
@@ -37,22 +87,22 @@ jobs:
3787
uses: ./.github/actions/setup-php-composer
3888
with:
3989
php-version: 8.2
40-
working-directory: plugins/hwp-previews
90+
working-directory: plugins/${{ env.PLUGIN }}
4191
composer-options: '--no-progress --optimize-autoloader --no-dev'
4292

4393
- name: Install playwright browsers
4494
run: npx playwright install --with-deps
45-
working-directory: plugins/hwp-previews
95+
working-directory: plugins/${{ env.PLUGIN }}
4696

4797
- name: Start wp-env
4898
run: |
4999
npm run wp-env start
50-
working-directory: plugins/hwp-previews
100+
working-directory: plugins/${{ env.PLUGIN }}
51101

52102
- name: Run Playwright tests
53103
run: npm run test:e2e
54-
working-directory: plugins/hwp-previews
104+
working-directory: plugins/${{ env.PLUGIN }}
55105

56106
- name: Stop wp-env
57107
run: npm run wp-env stop
58-
working-directory: plugins/hwp-previews
108+
working-directory: plugins/${{ env.PLUGIN }}

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ jobs:
2020
- name: Get changed plugin directory
2121
id: plugin
2222
run: |
23-
git fetch --prune --unshallow
24-
plugin=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' | head -1 | cut -d/ -f2)
25-
echo "slug=$plugin" >> $GITHUB_OUTPUT
23+
bash .github/scripts/get-plugin-slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}
2624
2725
- name: Create plugin artifact
2826
uses: ./.github/actions/create-plugin-artifact
@@ -44,20 +42,20 @@ jobs:
4442
const artifactUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
4543
const slug = process.env.PLUGIN_SLUG;
4644
const body = `ℹ️ [Download the latest ${slug} plugin zip from this PR](${artifactUrl})\n<em>(See the 'Artifacts' section at the bottom)</em>`;
47-
45+
4846
// Find existing comment from this bot
4947
const comments = await github.rest.issues.listComments({
5048
issue_number: pr.number,
5149
owner: context.repo.owner,
5250
repo: context.repo.repo
5351
});
54-
55-
const botComment = comments.data.find(comment =>
56-
comment.user.type === 'Bot' &&
52+
53+
const botComment = comments.data.find(comment =>
54+
comment.user.type === 'Bot' &&
5755
comment.user.login === 'github-actions[bot]' &&
5856
comment.body.includes(`ℹ️ [Download the latest ${slug} plugin zip from this PR]`)
5957
);
60-
58+
6159
if (botComment) {
6260
// Update existing comment
6361
core.info(`Updating existing comment with ID: ${botComment.id}`);

0 commit comments

Comments
 (0)