-
-
Notifications
You must be signed in to change notification settings - Fork 75
274 lines (246 loc) · 8.56 KB
/
addon-integration-test.yml
File metadata and controls
274 lines (246 loc) · 8.56 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
name: Addon Integration Test
# Reusable workflow for testing Ultimate Multisite addons.
# Called by individual addon repos to run PHPUnit and E2E tests
# against a full WordPress Multisite environment with the core plugin.
#
# Usage in addon repo (.github/workflows/ci.yml):
#
# on: [push, pull_request]
# jobs:
# test:
# uses: Ultimate-Multisite/ultimate-multisite/.github/workflows/addon-integration-test.yml@main
# with:
# addon-slug: multisite-ultimate-plugin-and-theme-manager
# secrets: inherit
on:
workflow_call:
inputs:
addon-slug:
description: "Addon directory name (e.g., multisite-ultimate-plugin-and-theme-manager)"
required: true
type: string
addon-ref:
description: "Git ref to checkout for the addon (default: triggering ref)"
required: false
type: string
default: ""
php-versions:
description: "JSON array of PHP versions to test"
required: false
type: string
default: '["8.2"]'
run-e2e:
description: "Whether to run E2E (Cypress) tests"
required: false
type: boolean
default: false
core-ref:
description: "Git ref for the core plugin (default: main)"
required: false
type: string
default: "main"
jobs:
phpunit:
name: "PHPUnit (PHP ${{ matrix.php }})"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ${{ fromJson(inputs.php-versions) }}
services:
mysql:
image: mariadb:11.4
env:
MYSQL_ROOT_PASSWORD: root
ports: [3306]
options: >-
--health-cmd="healthcheck.sh --connect --innodb_initialized"
--health-interval=10s
--health-timeout=5s
--health-retries=5
container:
image: cimg/php:${{ matrix.php }}
options: --user root
steps:
- name: Checkout core plugin
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
repository: Ultimate-Multisite/ultimate-multisite
ref: ${{ inputs.core-ref }}
path: core
- name: Checkout addon
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
ref: ${{ inputs.addon-ref || github.ref }}
path: addon
- name: Install system dependencies
run: apt-get update && apt-get install -y subversion mariadb-client
- name: Install PHP extensions
run: install-php-extensions mysqli gd bcmath || echo "Extensions may already be installed."
- name: Set up Composer global bin path
run: |
mkdir -p "$HOME/.config/composer/vendor/bin"
echo "PATH=$HOME/.config/composer/vendor/bin:$PATH" >> "$GITHUB_ENV"
- name: Install core Composer dependencies
working-directory: core
run: composer install --no-interaction --prefer-dist
- name: Install addon Composer dependencies
working-directory: addon
run: composer install --no-interaction --prefer-dist
- name: Wait for MySQL
run: |
for i in $(seq 1 30); do
if mysqladmin ping -h mysql --silent; then
echo "MySQL is up"
break
fi
echo "Waiting for MySQL... ($i/30)"
sleep 2
done
- name: Prepare WordPress test suite
working-directory: core
run: |
rm -rf /tmp/wordpress-tests-lib /tmp/wordpress/
bash bin/install-wp-tests.sh wordpress_test root root mysql latest
# Symlink core plugin into WP plugins dir
ln -s "$GITHUB_WORKSPACE/core" /tmp/wordpress/wp-content/plugins/ultimate-multisite
# Symlink addon into WP plugins dir
ln -s "$GITHUB_WORKSPACE/addon" "/tmp/wordpress/wp-content/plugins/${{ inputs.addon-slug }}"
- name: Run addon PHPUnit tests
working-directory: addon
run: |
if [[ -f phpunit.xml.dist ]] || [[ -f phpunit.xml ]]; then
vendor/bin/phpunit
else
echo "No phpunit.xml.dist found — skipping PHPUnit"
fi
e2e:
name: "E2E Tests"
if: inputs.run-e2e
runs-on: ubuntu-latest
timeout-minutes: 30
services:
mailpit:
image: axllent/mailpit:latest
ports:
- 1025:1025
- 8025:8025
options: >-
--health-cmd="wget --spider -q http://localhost:8025 || exit 1"
--health-interval=2s
--health-timeout=2s
--health-retries=10
steps:
- name: Checkout core plugin
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
repository: Ultimate-Multisite/ultimate-multisite
ref: ${{ inputs.core-ref }}
path: core
- name: Checkout addon
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
ref: ${{ inputs.addon-ref || github.ref }}
path: addon
- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 18
- name: Cache NPM dependencies
uses: actions/cache@6f8efc29b200d32929f49075959781ed54ec270c # v3
with:
path: ~/.npm
key: ${{ runner.os }}-npm-e2e
- name: Install core NPM dependencies
working-directory: core
run: npm ci
- name: Install core Composer dependencies
working-directory: core
run: composer install --no-interaction --prefer-dist
- name: Install addon NPM dependencies
working-directory: addon
run: |
if [[ -f package.json ]]; then
npm ci
fi
- name: Install addon Composer dependencies
working-directory: addon
run: |
if [[ -f composer.json ]]; then
composer install --no-interaction --prefer-dist
fi
- name: Generate wp-env override for addon
working-directory: core
run: |
# Create override that includes core + this addon
cat > .wp-env.override.json <<ENDJSON
{
"env": {
"development": {
"plugins": [".", "../addon"]
},
"tests": {
"plugins": [".", "../addon"]
}
}
}
ENDJSON
- name: Start WordPress test environment
working-directory: core
run: npm run env:start:test
- name: Wait for WordPress to be ready
run: |
for i in $(seq 1 60); do
if curl -s http://localhost:8889 | grep -q "WordPress"; then
echo "WordPress is ready"
break
fi
echo "Waiting for WordPress... ($i/60)"
sleep 5
done
- name: Run core setup test (activates plugins)
working-directory: core
run: |
if [[ -f tests/e2e/cypress/integration/000-setup.spec.js ]]; then
npx cypress run \
--config-file cypress.config.test.js \
--spec "tests/e2e/cypress/integration/000-setup.spec.js" \
--browser chrome
fi
- name: Run addon E2E tests
working-directory: addon
run: |
if [[ -d tests/e2e ]] && [[ -f cypress.config.js ]]; then
npx cypress run --browser chrome
elif [[ -d tests/e2e ]]; then
# Use core's Cypress config with addon's test specs
cd "$GITHUB_WORKSPACE/core"
npx cypress run \
--config-file cypress.config.test.js \
--spec "$GITHUB_WORKSPACE/addon/tests/e2e/**/*.spec.js" \
--browser chrome
else
echo "No E2E tests found — skipping"
fi
- name: Upload Cypress screenshots
if: always()
continue-on-error: true
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
with:
name: cypress-screenshots-${{ inputs.addon-slug }}
path: |
core/tests/e2e/cypress/screenshots
addon/tests/e2e/cypress/screenshots
- name: Upload Cypress videos
if: always()
continue-on-error: true
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
with:
name: cypress-videos-${{ inputs.addon-slug }}
path: |
core/tests/e2e/cypress/videos
addon/tests/e2e/cypress/videos
- name: Stop WordPress environment
if: always()
working-directory: core
run: npm run env:stop