Repository navigation
243 lines (206 loc) · 8.09 KB
/
Copy pathci.yml
File metadata and controls
243 lines (206 loc) · 8.09 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
name: CI
on:
push:
branches: [ develop, master ]
workflow_call:
pull_request:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [ '7.4', '8.5' ]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Cache Composer
uses: actions/cache@v4
with:
path: ~/.composer/cache
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-${{ matrix.php }}-
- name: Install dependencies
run: npm ci
- name: Run linting
run: npm run lint
- name: Run build
run: npm run build
phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
- name: Cache Composer
uses: actions/cache@v4
with:
path: ~/.composer/cache
key: ${{ runner.os }}-composer-phpstan-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-phpstan-
- name: Install Composer dependencies
run: composer install --no-interaction --no-progress
- name: Cache PHPStan result cache
uses: actions/cache@v4
with:
path: .phpstan-cache
key: ${{ runner.os }}-phpstan-${{ hashFiles('**/composer.lock', 'phpstan.neon.dist') }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-phpstan-${{ hashFiles('**/composer.lock', 'phpstan.neon.dist') }}-
${{ runner.os }}-phpstan-
- name: Run PHPStan
run: composer phpstan
unit:
name: Unit (PHPUnit)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Cache Composer
uses: actions/cache@v4
with:
path: ~/.composer/cache
key: ${{ runner.os }}-composer-unit-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-unit-
# This job only needs vendor/bin/phpunit and the wp-env CLI, so it used to
# install @wordpress/env on its own into a scratch prefix rather than run
# a full `npm ci`. That install resolved dependency ranges fresh against
# npm instead of obeying package-lock.json, which made the job depend on
# whatever upstream had published that day: a broken @wp-playground/cli
# release, pulled in transitively by @wordpress/env, failed every run
# while the lockfile-based jobs were unaffected.
#
# `npm ci` installs the locked tree, so the job can no longer break
# because of a third-party release. The postinstall hook runs
# `patch-package && composer install`, which is what provides
# vendor/bin/phpunit, so this single step covers both toolchains.
#
# Deliberately not `--ignore-scripts`, for the same reason as the e2e
# job below: besides skipping the Composer install, that flag made this
# step take 1m30s instead of ~36s from a cold cache.
- name: Install dependencies
run: npm ci
# The wp-env sources directory is deliberately not cached. A restored
# ~/.wp-env carries the previous run's install state, which skipped the
# plugin's activation hook and left the relationships table missing.
# .wp-env.ci.json omits the HTTPS URLs and the proxy lifecycle script
# that .wp-env.json uses for local development. Runners have no local CA
# and no proxy container, so they serve the site over plain HTTP.
- name: Start wp-env
run: npx wp-env start --config .wp-env.ci.json
- name: Run unit tests
run: npx wp-env run tests-cli --config .wp-env.ci.json --env-cwd="wp-content/plugins/$(basename "$PWD")" vendor/bin/phpunit
- name: Stop wp-env
if: always()
run: npx wp-env stop --config .wp-env.ci.json
e2e:
name: E2E (Playwright)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Not needed by Playwright, but every job that has this step completes
# `npm ci` in ~35s while this job, without it, took 2.5 to 4 minutes on
# the same runs (same npm, same cache hit). setup-php also installs
# Composer, which the postinstall hook calls.
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Cache Composer
uses: actions/cache@v4
with:
path: ~/.composer/cache
key: ${{ runner.os }}-composer-e2e-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-e2e-
# Deliberately not `--ignore-scripts`: with the npm 10 that ships with
# the pinned Node, that flag made this step take 4 to 7 minutes instead
# of ~36s (a known npm 10 reify stall around lifecycle-script nodes).
- name: Install dependencies
run: npm ci
- name: Get Playwright version
id: playwright-version
run: echo "version=$(node -p "require('@playwright/test/package.json').version")" >> "$GITHUB_OUTPUT"
- name: Cache Playwright browsers
id: playwright-cache
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}
# wp-env spends most of its time pulling Docker images and installing
# WordPress, none of which depends on the Node-side steps. Run it in the
# background while the browser install and asset build proceed, then
# wait for it. All of this has to live in one step because `wait` only
# sees children of the same shell. wp-env output goes to a file and is
# printed afterwards so the interleaved log stays readable.
- name: Start wp-env, install browsers, build assets
env:
PLAYWRIGHT_CACHE_HIT: ${{ steps.playwright-cache.outputs.cache-hit }}
run: |
npx wp-env start --config .wp-env.ci.json > wp-env-start.log 2>&1 &
wp_env_pid=$!
if [ "$PLAYWRIGHT_CACHE_HIT" = "true" ]; then
# Browser binaries came from cache; only the apt packages they
# need are missing on a fresh runner.
npx playwright install-deps chromium
else
npx playwright install --with-deps chromium
fi
npm run build
echo "::group::wp-env start"
if wait "$wp_env_pid"; then
cat wp-env-start.log
echo "::endgroup::"
else
cat wp-env-start.log
echo "::endgroup::"
exit 1
fi
# Runners have no local CA and no HTTPS proxy, so the suite talks to
# wp-env's published port directly over plain HTTP. WP_BASE_URL is the
# single switch for this; see tests/e2e/playwright.config.js.
- name: Run E2E tests
env:
CLOUDINARY_E2E_URL: ${{ secrets.CLOUDINARY_E2E_URL }}
WP_BASE_URL: http://localhost:8889
run: npm run test:e2e
- name: Stop wp-env
if: always()
run: npx wp-env stop --config .wp-env.ci.json
- name: Upload Playwright artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-artifacts
path: artifacts/
retention-days: 7