Skip to content

Commit 4b9af17

Browse files
authored
Merge pull request #288 from wpengine/chore-split-code-quality-test-workflow-to-skip-rather-than-fail
chore: Updating workflows for code quality and testing integration
2 parents e3bb447 + e92d283 commit 4b9af17

File tree

6 files changed

+162
-45
lines changed

6 files changed

+162
-45
lines changed

.changeset/metal-kings-look.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: Minor changes to testing docs and updating workflows.

.github/workflows/code-quality.yml

Lines changed: 68 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# This does the following:
2+
# 1. Detects modified plugins that have phpcs.xml configuration
3+
# 2. Runs PHP Code Quality checks 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+
# [![Code Quality](https://img.shields.io/github/check-runs/wpengine/hwptoolkit/main?checkName=hwp-previews%20php%20code%20quality%20checks&label=Code%20Quality%20Checks)](https://github.com/wpengine/hwptoolkit/actions)
7+
18
name: Code Quality
29

310
on:
@@ -11,30 +18,76 @@ on:
1118
- 'plugins/**.php'
1219

1320
jobs:
14-
run:
21+
detect-plugins:
1522
runs-on: ubuntu-latest
16-
name: Check code quality
17-
23+
name: Detect plugins has php code quality configuration
24+
outputs:
25+
plugins: ${{ steps.detect.outputs.plugins }}
26+
has-plugins: ${{ steps.detect.outputs.has-plugins }}
1827
steps:
1928
- name: Checkout
2029
uses: actions/checkout@v4
2130

22-
- name: Get changed plugin directory
23-
id: plugin
31+
- name: Detect changed plugins with quality config
32+
id: detect
2433
run: |
2534
git fetch --prune --unshallow
26-
plugin=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' | head -1 | cut -d/ -f2)
27-
echo "slug=$plugin" >> $GITHUB_OUTPUT
35+
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' || true)
2836
29-
# We should at least have a phpcs.xml file to run code quality checks
30-
- name: Validate phpcs.xml
31-
run: |
32-
if [ ! -f "plugins/${{ steps.plugin.outputs.slug }}/phpcs.xml" ]; then
33-
echo "Exiting as no phpcs.xml file found for /${{ steps.plugin.outputs.slug }}"
34-
exit 1
37+
if [ -z "$CHANGED_FILES" ]; then
38+
echo "No plugin files changed"
39+
echo "plugins=[]" >> $GITHUB_OUTPUT
40+
echo "has-plugins=false" >> $GITHUB_OUTPUT
41+
exit 0
42+
fi
43+
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
65+
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
70+
echo "has-plugins=true" >> $GITHUB_OUTPUT
71+
echo "Found ${#PLUGINS_WITH_CONFIG[@]} plugin(s) with quality config: ${PLUGINS_WITH_CONFIG[*]}"
72+
else
73+
echo "plugins=[]" >> $GITHUB_OUTPUT
74+
echo "has-plugins=false" >> $GITHUB_OUTPUT
75+
echo "No plugins found with quality configuration"
3576
fi
77+
quality-checks:
78+
needs: detect-plugins
79+
if: needs.detect-plugins.outputs.has-plugins == 'true'
80+
runs-on: ubuntu-latest
81+
strategy:
82+
matrix:
83+
plugin: ${{ fromJson(needs.detect-plugins.outputs.plugins) }}
84+
fail-fast: false
85+
name: ${{ matrix.plugin }} php code quality checks
86+
steps:
87+
- name: Checkout
88+
uses: actions/checkout@v4
3689

37-
- name: PHP Code Quality
90+
- name: PHP Code Quality for ${{ matrix.plugin }}
3891
uses: ./.github/actions/code-quality
3992
with:
40-
working-directory: plugins/${{ steps.plugin.outputs.slug }}
93+
working-directory: plugins/${{ matrix.plugin }}

.github/workflows/codeception.yml

Lines changed: 83 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# This does the following:
2+
# 1. Detects modified plugins that have codeception.dist.yml configuration setup
3+
# 2. Runs Codeception 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+
# [![Testing Integration](https://img.shields.io/github/check-runs/wpengine/hwptoolkit/main?checkName=hwp-previews%20codeception%20tests&label=Automated%20Tests)](https://github.com/wpengine/hwptoolkit/actions)
7+
18
name: Testing Integration
29

310
on:
@@ -18,12 +25,85 @@ concurrency:
1825
cancel-in-progress: true
1926

2027
jobs:
28+
detect-plugins:
29+
runs-on: ubuntu-latest
30+
name: Detect plugins with test config
31+
outputs:
32+
plugins: ${{ steps.detect.outputs.plugins }}
33+
has-plugins: ${{ steps.detect.outputs.has-plugins }}
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v4
37+
38+
- name: Detect changed plugins with test config
39+
id: detect
40+
run: |
41+
git fetch --prune --unshallow
42+
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"
52+
echo "plugins=[]" >> $GITHUB_OUTPUT
53+
echo "has-plugins=false" >> $GITHUB_OUTPUT
54+
exit 0
55+
fi
56+
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
85+
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
90+
echo "has-plugins=true" >> $GITHUB_OUTPUT
91+
echo "Found ${#PLUGINS_WITH_CONFIG[@]} plugin(s) with test config: ${PLUGINS_WITH_CONFIG[*]}"
92+
else
93+
echo "plugins=[]" >> $GITHUB_OUTPUT
94+
echo "has-plugins=false" >> $GITHUB_OUTPUT
95+
echo "No plugins found with test configuration"
96+
fi
97+
2198
continuous_integration:
99+
needs: detect-plugins
100+
if: needs.detect-plugins.outputs.has-plugins == 'true'
22101
runs-on: ubuntu-latest
23-
name: WordPress ${{ matrix.wordpress }} on PHP ${{ matrix.php }}
102+
name: ${{ matrix.plugin }} integration tests (WP ${{ matrix.wordpress }}, PHP ${{ matrix.php }})
24103

25104
strategy:
26105
matrix:
106+
plugin: ${{ fromJson(needs.detect-plugins.outputs.plugins) }}
27107
php: ["8.3","8.2","8.1"]
28108
wordpress: ["6.8","6.7","6.6","6.5"]
29109
include:
@@ -35,32 +115,10 @@ jobs:
35115
steps:
36116
- name: Checkout
37117
uses: actions/checkout@v4
38-
39-
- name: Get changed plugin directory
40-
id: plugin
41-
run: |
42-
git fetch --prune --unshallow
43-
plugin=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' | head -1 | cut -d/ -f2)
44-
echo "slug=$plugin" >> $GITHUB_OUTPUT
45-
46-
- name: Validate codeception.dist.yml
47-
run: |
48-
if [ ! -f "plugins/${{ steps.plugin.outputs.slug }}/codeception.dist.yml" ]; then
49-
echo "Exiting as no codeception file found for this plugin - /${{ steps.plugin.outputs.slug }}"
50-
exit 1
51-
fi
52-
53-
- name: Validate composer.json
54-
run: |
55-
if [ ! -f "plugins/${{ steps.plugin.outputs.slug }}/composer.json" ]; then
56-
echo "Exiting as no composer file found for this plugin - ${{ steps.plugin.outputs.slug }}"
57-
exit 1
58-
fi
59-
60-
- name: Run Codeception Tests
118+
- name: ${{ matrix.plugin }} codeception tests
61119
uses: ./.github/actions/codeception
62120
with:
63-
working-directory: plugins/${{ steps.plugin.outputs.slug }}
121+
working-directory: plugins/${{ matrix.plugin }}
64122
php: ${{ matrix.php }}
65123
wordpress: ${{ matrix.wordpress }}
66124
extensions: json,mbstring

plugins/hwp-previews/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
[![License](https://img.shields.io/badge/license-GPLv2%2B-green)]()
1313
![GitHub forks](https://img.shields.io/github/forks/wpengine/hwptoolkit?style=social)
1414
![GitHub stars](https://img.shields.io/github/stars/wpengine/hwptoolkit?style=social)
15-
[![Testing Integration](https://github.com/wpengine/hwptoolkit/workflows/Testing%20Integration/badge.svg)](https://github.com/wpengine/hwptoolkit/actions?query=workflow%3A%22Testing+Integration%22)
16-
[![Code Quality](https://github.com/wpengine/hwptoolkit/workflows/Code%20Quality/badge.svg)](https://github.com/wpengine/hwptoolkit/actions?query=workflow%3A%22Code+Quality%22)
15+
[![Testing Integration](https://img.shields.io/github/check-runs/wpengine/hwptoolkit/main?checkName=hwp-previews%20codeception%20tests&label=Automated%20Tests)](https://github.com/wpengine/hwptoolkit/actions)
16+
[![Code Quality](https://img.shields.io/github/check-runs/wpengine/hwptoolkit/main?checkName=hwp-previews%20php%20code%20quality%20checks&label=Code%20Quality%20Checks)](https://github.com/wpengine/hwptoolkit/actions)
1717
[![End-to-End Tests](https://github.com/wpengine/hwptoolkit/workflows/End-to-End%20Tests/badge.svg)](https://github.com/wpengine/hwptoolkit/actions?query=workflow%3A%22End-to-End+Tests%22)
1818
-----
1919

plugins/hwp-previews/TESTING.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ To generate an HTML coverage report:
7878
```bash
7979
composer run test:unit:coverage-html
8080
```
81-
82-
> [!IMPORTANT]
83-
> You can also add coverage e.g. `sh bin/local/run-unit-tests.sh coverage --coverage-html` and the output will be saved in [tests/_output/coverage/dashboard.html](tests/_output/coverage/dashboard.html)
81+
> [!NOTE]
82+
> HTML code coverage can be found here [tests/_output/coverage/index.html](tests/_output/coverage/index.html)
8483
8584

8685
### E2WTests

plugins/hwp-previews/src/Plugin.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*
1414
* This class serves as the main entry point for the plugin, handling initialization, action and filter hooks.
1515
*
16+
* @link https://github.com/wpengine/hwptoolkit/tree/main/plugins/hwp-previews
17+
*
1618
* @package HWP\Previews
1719
*/
1820
final class Plugin {

0 commit comments

Comments
 (0)