-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
343 lines (308 loc) · 13 KB
/
action.yml
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
name: 'WP Performance Tests'
description: 'Measure performance metrics for your WordPress project'
author: 'Pascal Birchler'
branding:
color: 'blue'
icon: 'trending-up'
inputs:
github-token:
description: 'The GitHub token used to create PR comments.'
required: false
default: ${{ github.token }}
create-comment:
description: 'Whether to create PR comments with performance results.'
required: false
default: ''
debug:
description: 'Whether to log additional debugging information.'
default: ${{ runner.debug == '1' }}
urls:
required: true
description: 'URLs to test, separated by newline.'
default: ''
plugins:
required: false
description: 'List of plugins to install, separated by newline. Supports directory paths and ZIP URLs.'
default: ''
themes:
required: false
description: 'List of themes to install, separated by newline. Supports directory paths and ZIP URLs.'
default: ''
active-theme:
required: false
description: 'Theme to activate for the test.'
default: 'twentytwentyone'
wp-version:
required: false
description: 'WordPress version to use.'
default: 'latest'
php-version:
required: false
description: 'PHP version to use.'
default: 'auto'
shard:
required: false
description: 'Shard to use if running tests in parallel in a matrix.'
default: ''
repetitions:
required: false
description: 'Number of times the tests should be repeated.'
default: '2'
iterations:
required: false
description: 'Number of iterations (loops) within a single run.'
default: '20'
action:
description: 'Action to perform, can be either "test" or "merge".'
required: false
default: 'test'
previous-results:
description: 'Path to a file with previous performance results for comparison.'
required: false
default: ''
outputs:
results:
description: "Path to a file with raw results"
value: ${{ steps.share-results.outputs.results }}
blob-report:
description: "Path to the blob report folder"
value: ${{ steps.share-blob-report.outputs.blob-report }}
runs:
using: "composite"
steps:
# Works around https://github.com/actions/upload-artifact/issues/176
- name: Resolve action_path
run: echo "ABS_ACTION_PATH=$(realpath ${{ github.action_path }})" >> $GITHUB_ENV
shell: 'bash'
# setup-node expects paths relative to checked-out repo,
# but we want to use .nvmrc from action repo.
# So we provide a path relative to $GITHUB_WORKSPACE
# See https://github.com/actions/setup-node/issues/852
- name: Get relative action_path
run: |
REL_ACTION_PATH=$(node -p 'require("path").relative(process.env.GITHUB_WORKSPACE, process.env.ABS_ACTION_PATH)')
REL_ACTION_PATH=${REL_ACTION_PATH:-.}
echo "REL_ACTION_PATH=$REL_ACTION_PATH" >> $GITHUB_ENV
shell: 'bash'
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: ${{ env.REL_ACTION_PATH }}/env/.nvmrc
# Disable caching as it is not supported outside $GITHUB_WORKSPACE
cache: ''
- name: Install dependencies
run: npm ci ${{ inputs.debug != 'true' && '--silent' }}
shell: 'bash'
working-directory: ${{ github.action_path }}/env
- name: Install Playwright Browsers
run: npx ${{ inputs.debug != 'true' && '--silent' }} playwright install --with-deps
if: ${{ inputs.action == 'test' }}
shell: 'bash'
working-directory: ${{ github.action_path }}/env
- name: Prepare wp-env
run: |
echo "Preparing wp-env..."
PLUGINS=${PLUGINS%$'\n'}
THEMES=${THEMES%$'\n'}
IFS=$'\n';
PLUGINS=($PLUGINS)
THEMES=($THEMES)
PLUGINS_ARRAY=()
for i in "${PLUGINS[@]}"; do
if [ ! -z i ]; then
if [[ "$i" == *"http"* ]]; then
PLUGINS_ARRAY+=($i)
else
PLUGINS_ARRAY+=$(realpath $i)
fi
fi
done
PLUGINS=$(printf "%s\n" "${PLUGINS_ARRAY[@]}")
THEMES_ARRAY=()
for i in "${THEMES[@]}"; do
if [ ! -z i ]; then
if [[ "$i" == *"http"* ]]; then
THEMES_ARRAY+=($i)
else
THEMES_ARRAY+=$(realpath $i)
fi
fi
done
THEMES=$(printf "%s\n" "${THEMES_ARRAY[@]}")
unset IFS;
REQUIRED_PLUGINS=$(cat <<-END
https://downloads.wordpress.org/plugin/wordpress-importer.zip
https://downloads.wordpress.org/plugin/performance-lab.zip
END
)
REQUIRED_THEMES=$(cat <<-END
https://downloads.wordpress.org/theme/twentytwentyone.zip
https://downloads.wordpress.org/theme/twentytwentythree.zip
END
)
if [[ $WP_VERSION == 'latest' ]]; then
WP_VERSION=null
elif [[ "$WP_VERSION" == "trunk" ]]; then
WP_VERSION="\"WordPress/WordPress#master\""
elif [[ "$WP_VERSION" == "nightly" ]]; then
WP_VERSION="\"https://wordpress.org/nightly-builds/wordpress-latest.zip"\"
elif [[ "$WP_VERSION" == *".zip"* ]]; then
WP_VERSION="\"$WP_VERSION\""
else
WP_VERSION="\"WordPress/WordPress#$WP_VERSION\""
fi
if [[ $PHP_VERSION == 'auto' ]]; then
PHP_VERSION=null
else
PHP_VERSION="\"$PHP_VERSION\""
fi
jq -n \
--argjson wp "$WP_VERSION" \
--argjson php "$PHP_VERSION" \
--arg rp "$REQUIRED_PLUGINS" \
--arg p "$PLUGINS" \
--arg t "$THEMES" \
--arg rt "$REQUIRED_THEMES" \
'{core: $wp, phpVersion: $php, plugins: [($rp | split("\n")), ($p | split("\n"))] | add, themes: [($rt | split("\n")), ($t | split("\n"))] | add}' \
> ${{ env.ABS_ACTION_PATH }}/env/.wp-env.override.json
if [[ ${{ inputs.debug == 'true' }} == true ]]; then
echo "Generated .wp-env.override.json file:"
cat ${{ env.ABS_ACTION_PATH }}/env/.wp-env.override.json
fi
if: ${{ inputs.action == 'test' }}
env:
PLUGINS: ${{ inputs.plugins }}
THEMES: ${{ inputs.themes }}
WP_VERSION: ${{ inputs.wp-version }}
PHP_VERSION: ${{ inputs.php-version }}
shell: 'bash'
- name: Start WordPress
run: npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env start
if: ${{ inputs.action == 'test' }}
shell: 'bash'
working-directory: ${{ github.action_path }}/env
- name: Update permalink structure
run: npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env run tests-cli wp rewrite structure '/%postname%/' -- --hard
if: ${{ inputs.action == 'test' }}
shell: 'bash'
working-directory: ${{ github.action_path }}/env
- name: Import mock data
run: |
npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env run tests-cli wp plugin list
npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env run tests-cli curl -s https://raw.githubusercontent.com/WordPress/theme-test-data/b9752e0533a5acbb876951a8cbb5bcc69a56474c/themeunittestdata.wordpress.xml -- --output /tmp/themeunittestdata.wordpress.xml
npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env run tests-cli wp import /tmp/themeunittestdata.wordpress.xml -- --authors=create --quiet
npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env run tests-cli wp plugin deactivate wordpress-importer --quiet
if: ${{ inputs.action == 'test' }}
shell: 'bash'
working-directory: ${{ github.action_path }}/env
- name: Prepare test site
run: |
npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env run tests-cli wp theme activate $THEME --quiet
npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env run tests-cli wp config set WP_HTTP_BLOCK_EXTERNAL true --raw --type=constant
npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env run tests-cli wp config set DISABLE_WP_CRON true --raw --type=constant
if: ${{ inputs.action == 'test' }}
env:
THEME: ${{ inputs.active-theme }}
shell: 'bash'
working-directory: ${{ github.action_path }}/env
- name: List defined constants
run: npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env run tests-cli wp config list --path=/var/www/${{ env.LOCAL_DIR }}
if: ${{ inputs.action == 'test' && inputs.debug == 'true' }}
shell: 'bash'
working-directory: ${{ github.action_path }}/env
- name: Run tests
run: npm run ${{ inputs.debug != 'true' && '--silent' }} test:performance $ADDITIONAL_ARGS
if: ${{ inputs.action == 'test' }}
env:
WP_ARTIFACTS_PATH: ${{ github.action_path }}/env/artifacts
BLOB_REPORT_PATH: ${{ github.action_path }}/env/blob-report
SHARD: ${{ inputs.shard != '1/1' && inputs.shard || '' }}
ADDITIONAL_ARGS: ${{ inputs.shard != '1/1' && format('-- --shard={0}', inputs.shard) || '' }}
URLS_TO_TEST: ${{ inputs.urls }}
DEBUG: ${{ inputs.debug == 'true' }}
shell: 'bash'
working-directory: ${{ github.action_path }}/env
- name: Download blob reports from GitHub Actions Artifacts
uses: actions/download-artifact@v4
if: ${{ inputs.action == 'merge' }}
id: download
with:
pattern: performance-blob-report-*
merge-multiple: true
- name: Merge into single performance report
run: npm run ${{ inputs.debug != 'true' && '--silent' }} test:performance:merge-reports ${{steps.download.outputs.download-path}}
if: ${{ inputs.action == 'merge' }}
shell: 'bash'
working-directory: ${{ github.action_path }}/env
- name: Print results
run: |
if [ ! -z $PREVIOUS_RESULTS ] && [ -f $PREVIOUS_RESULTS ]; then
npm run ${{ inputs.debug != 'true' && '--silent' }} test:performance:results $WP_ARTIFACTS_PATH/performance-results.json $PREVIOUS_RESULTS
else
npm run ${{ inputs.debug != 'true' && '--silent' }} test:performance:results
fi;
if: ${{ inputs.action == 'test' || inputs.action == 'merge' }}
env:
WP_ARTIFACTS_PATH: ${{ github.action_path }}/env/artifacts
PREVIOUS_RESULTS: ${{ inputs.previous-results }}
REPOSITORY_URL: ${{ github.server_url }}/${{ github.repository }}
shell: 'bash'
working-directory: ${{ github.action_path }}/env
- name: Add workflow summary
run: cat $WP_ARTIFACTS_PATH/performance-results.md >> $GITHUB_STEP_SUMMARY
if: ${{ ( inputs.action == 'test' || inputs.action == 'merge' ) && ! inputs.shard }}
env:
WP_ARTIFACTS_PATH: ${{ github.action_path }}/env/artifacts
shell: 'bash'
working-directory: ${{ github.action_path }}/env
- name: Check if a comment was already made
id: find-comment
if: ${{ github.event_name == 'pull_request' && inputs.create-comment == 'true' }}
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: Performance test results for
- name: Comment on PR with test results
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043
if: ${{ github.event_name == 'pull_request' && inputs.create-comment == 'true' }}
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body-path: ${{ github.action_path }}/env/artifacts/performance-results.md
token: ${{ inputs.github-token }}
- name: Share raw results
id: share-results
run: echo "results=$WP_ARTIFACTS_PATH/performance-results.json" >> $GITHUB_OUTPUT
if: ${{ ( inputs.action == 'test' || inputs.action == 'merge' ) && ! inputs.shard }}
env:
WP_ARTIFACTS_PATH: ${{ github.action_path }}/env/artifacts
shell: 'bash'
- name: Share blob report
id: share-blob-report
run: echo "blob-report=$BLOB_REPORT_PATH" >> $GITHUB_OUTPUT
if: ${{ inputs.shard != '' }}
env:
BLOB_REPORT_PATH: ${{ github.action_path }}/env/blob-report
shell: 'bash'
- name: Upload performance results
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
if: ${{ success() && ( inputs.action == 'test' || inputs.action == 'merge' ) && ! inputs.shard }}
with:
name: performance-results
path: ${{ env.ABS_ACTION_PATH }}/env/artifacts/performance-results.json
- name: Get blob artifact name
if: always()
run: |
ARTIFACT_NAME=${ARTIFACT_NAME//\//-}
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV
env:
ARTIFACT_NAME: performance-blob-report-${{ inputs.shard }}
shell: 'bash'
- name: Upload blob report
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
if: ${{ success() && inputs.shard != '' }}
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ABS_ACTION_PATH }}/env/blob-report
retention-days: 1