Repository navigation
136 lines (119 loc) · 4.45 KB
/
Copy pathe2e-test.yml
File metadata and controls
136 lines (119 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# 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.
# [](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/*/**.php'
- 'plugins/*/**.js'
- 'plugins/*/**.css'
- 'plugins/*/**.json'
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
with:
# get_plugin_slug.sh diffs against history, so fetch all of it without file contents.
fetch-depth: 0
# Skip the example sites' uploads.zip files (590 MB), which plugin jobs don't use.
filter: blob:none
sparse-checkout-cone-mode: false
sparse-checkout: |
/*
!**/wp-env/uploads.zip
- name: Get changed plugin directory
id: plugin
run: |
if [ "${{ github.event_name }}" = "push" ]; then
bash .github/scripts/get_plugin_slug.sh main
else
bash .github/scripts/get_plugin_slug.sh \
${{ github.event.pull_request.base.sha }} \
${{ github.event.pull_request.head.sha }}
fi
- 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
uses: actions/checkout@v4
with:
# Skip the example sites' uploads.zip files (590 MB), which plugin jobs don't use.
filter: blob:none
sparse-checkout-cone-mode: false
sparse-checkout: |
/*
!**/wp-env/uploads.zip
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "24"
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 10 # Min version required by the repo
- name: Install pnpm
run: pnpm install
- name: Setup PHP with Cached Composer
uses: ./.github/actions/setup-php-composer
with:
php-version: 8.2
working-directory: plugins/${{ env.PLUGIN }}
composer-options: '--no-progress --optimize-autoloader --no-dev'
- name: Install playwright browsers
# Use the locked @playwright/test, and only Chromium since that's all the config runs.
# Skip --with-deps because the runner image has Chromium's libraries and its apt
# step has hung for up to 40 minutes.
run: pnpm exec playwright install chromium
working-directory: plugins/${{ env.PLUGIN }}
- name: Start wp-env
run: |
pnpm wp-env start
working-directory: plugins/${{ env.PLUGIN }}
- name: Run Playwright tests
run: pnpm test:e2e
working-directory: plugins/${{ env.PLUGIN }}