Skip to content

chore: Previews and Workflow Tidy up #98

chore: Previews and Workflow Tidy up

chore: Previews and Workflow Tidy up #98

Workflow file for this run

# 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 Tests](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/**.php'
- 'plugins/**.js'
- 'plugins/**.css'
- 'plugins/**.json'
pull_request:
branches:
- main
paths:
- "plugins/**"
jobs:
detect-plugins:
runs-on: ubuntu-latest
name: Detect plugins with E2E tests
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
run: |
bash .github/scripts/get-plugin-slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}
- name: Detect changed plugins with E2E 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
PLUGIN="${{ steps.plugin.outputs.slug }}"
# Check for .wp-env.json file in the plugin directory
if [ -f "plugins/$PLUGIN/.wp-env.json" ]; then
echo "plugins=[\"$PLUGIN\"]" >> $GITHUB_OUTPUT
echo "has-plugins=true" >> $GITHUB_OUTPUT
echo "✅ Found .wp-env.json for plugin: $PLUGIN"
else
echo "plugins=[]" >> $GITHUB_OUTPUT
echo "has-plugins=false" >> $GITHUB_OUTPUT
echo "ℹ️ No .wp-env.json found for plugin: $PLUGIN, skipping E2E tests"
fi
playwright-e2e-tests:
needs: detect-plugins
if: needs.detect-plugins.outputs.has-plugins == 'true'
runs-on: ubuntu-24.04
strategy:
matrix:
plugin: ${{ fromJson(needs.detect-plugins.outputs.plugins) }}
fail-fast: false
name: ${{ matrix.plugin }} Playwright E2E Tests
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "npm"
- name: Install dependencies
run: npm ci
working-directory: plugins/${{ matrix.plugin }}
- name: Setup PHP with Cached Composer
uses: ./.github/actions/setup-php-composer
with:
php-version: 8.2
working-directory: plugins/${{ matrix.plugin }}
composer-options: '--no-progress --optimize-autoloader --no-dev'
- name: Install playwright browsers
run: npx playwright install --with-deps
working-directory: plugins/${{ matrix.plugin }}
- name: Start wp-env
run: npm run wp-env start
working-directory: plugins/${{ matrix.plugin }}
- name: Run Playwright tests
run: npm run test:e2e
working-directory: plugins/${{ matrix.plugin }}
- name: Stop wp-env
run: npm run wp-env stop
working-directory: plugins/${{ matrix.plugin }}