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/metal-kings-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wpengine/hwp-previews-wordpress-plugin": patch
---

chore: Minor changes to testing docs and updating workflows.
83 changes: 68 additions & 15 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# This does the following:
# 1. Detects modified plugins that have phpcs.xml configuration
# 2. Runs PHP Code Quality checks 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.
# [![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)

name: Code Quality

on:
Expand All @@ -11,30 +18,76 @@ on:
- 'plugins/**.php'

jobs:
run:
detect-plugins:
runs-on: ubuntu-latest
name: Check code quality

name: Detect plugins has php code quality configuration
outputs:
plugins: ${{ steps.detect.outputs.plugins }}
has-plugins: ${{ steps.detect.outputs.has-plugins }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get changed plugin directory
id: plugin
- name: Detect changed plugins with quality config
id: detect
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
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' || true)

# We should at least have a phpcs.xml file to run code quality checks
- name: Validate phpcs.xml
run: |
if [ ! -f "plugins/${{ steps.plugin.outputs.slug }}/phpcs.xml" ]; then
echo "Exiting as no phpcs.xml file found for /${{ steps.plugin.outputs.slug }}"
exit 1
if [ -z "$CHANGED_FILES" ]; then
echo "No plugin files changed"
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

# 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
echo "has-plugins=true" >> $GITHUB_OUTPUT
echo "Found ${#PLUGINS_WITH_CONFIG[@]} plugin(s) with quality config: ${PLUGINS_WITH_CONFIG[*]}"
else
echo "plugins=[]" >> $GITHUB_OUTPUT
echo "has-plugins=false" >> $GITHUB_OUTPUT
echo "No plugins found with quality configuration"
fi
quality-checks:
needs: detect-plugins
if: needs.detect-plugins.outputs.has-plugins == 'true'
runs-on: ubuntu-latest
strategy:
matrix:
plugin: ${{ fromJson(needs.detect-plugins.outputs.plugins) }}
fail-fast: false
name: ${{ matrix.plugin }} php code quality checks
steps:
- name: Checkout
uses: actions/checkout@v4

- name: PHP Code Quality
- name: PHP Code Quality for ${{ matrix.plugin }}
uses: ./.github/actions/code-quality
with:
working-directory: plugins/${{ steps.plugin.outputs.slug }}
working-directory: plugins/${{ matrix.plugin }}
108 changes: 83 additions & 25 deletions .github/workflows/codeception.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# This does the following:
# 1. Detects modified plugins that have codeception.dist.yml configuration setup
# 2. Runs Codeception 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.
# [![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)

name: Testing Integration

on:
Expand All @@ -18,12 +25,85 @@ concurrency:
cancel-in-progress: true

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

- name: Detect changed plugins with test config
id: detect
run: |
git fetch --prune --unshallow

# 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"
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

# 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
echo "has-plugins=true" >> $GITHUB_OUTPUT
echo "Found ${#PLUGINS_WITH_CONFIG[@]} plugin(s) with test config: ${PLUGINS_WITH_CONFIG[*]}"
else
echo "plugins=[]" >> $GITHUB_OUTPUT
echo "has-plugins=false" >> $GITHUB_OUTPUT
echo "No plugins found with test configuration"
fi

continuous_integration:
needs: detect-plugins
if: needs.detect-plugins.outputs.has-plugins == 'true'
runs-on: ubuntu-latest
name: WordPress ${{ matrix.wordpress }} on PHP ${{ matrix.php }}
name: ${{ matrix.plugin }} integration tests (WP ${{ matrix.wordpress }}, PHP ${{ matrix.php }})

strategy:
matrix:
plugin: ${{ fromJson(needs.detect-plugins.outputs.plugins) }}
php: ["8.3","8.2","8.1"]
wordpress: ["6.8","6.7","6.6","6.5"]
include:
Expand All @@ -35,32 +115,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- 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

- name: Validate codeception.dist.yml
run: |
if [ ! -f "plugins/${{ steps.plugin.outputs.slug }}/codeception.dist.yml" ]; then
echo "Exiting as no codeception file found for this plugin - /${{ steps.plugin.outputs.slug }}"
exit 1
fi

- name: Validate composer.json
run: |
if [ ! -f "plugins/${{ steps.plugin.outputs.slug }}/composer.json" ]; then
echo "Exiting as no composer file found for this plugin - ${{ steps.plugin.outputs.slug }}"
exit 1
fi

- name: Run Codeception Tests
- name: ${{ matrix.plugin }} codeception tests
uses: ./.github/actions/codeception
with:
working-directory: plugins/${{ steps.plugin.outputs.slug }}
working-directory: plugins/${{ matrix.plugin }}
php: ${{ matrix.php }}
wordpress: ${{ matrix.wordpress }}
extensions: json,mbstring
4 changes: 2 additions & 2 deletions plugins/hwp-previews/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
[![License](https://img.shields.io/badge/license-GPLv2%2B-green)]()
![GitHub forks](https://img.shields.io/github/forks/wpengine/hwptoolkit?style=social)
![GitHub stars](https://img.shields.io/github/stars/wpengine/hwptoolkit?style=social)
[![Testing Integration](https://github.com/wpengine/hwptoolkit/workflows/Testing%20Integration/badge.svg)](https://github.com/wpengine/hwptoolkit/actions?query=workflow%3A%22Testing+Integration%22)
[![Code Quality](https://github.com/wpengine/hwptoolkit/workflows/Code%20Quality/badge.svg)](https://github.com/wpengine/hwptoolkit/actions?query=workflow%3A%22Code+Quality%22)
[![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)
[![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)
[![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)
-----

Expand Down
5 changes: 2 additions & 3 deletions plugins/hwp-previews/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ To generate an HTML coverage report:
```bash
composer run test:unit:coverage-html
```

> [!IMPORTANT]
> 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)
> [!NOTE]
> HTML code coverage can be found here [tests/_output/coverage/index.html](tests/_output/coverage/index.html)


### E2WTests
Expand Down
2 changes: 2 additions & 0 deletions plugins/hwp-previews/src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*
* This class serves as the main entry point for the plugin, handling initialization, action and filter hooks.
*
* @link https://github.com/wpengine/hwptoolkit/tree/main/plugins/hwp-previews
*
* @package HWP\Previews
*/
final class Plugin {
Expand Down
Loading