-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
319 lines (284 loc) · 11.7 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
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: ''
print-results:
description: 'Whether to add results to the workflow summary'
required: false
default: ''
upload-artifacts:
description: 'Whether to upload any artifacts'
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 plugin directory paths to mount, separated by newline.'
default: ''
themes:
required: false
description: 'List of theme directory paths to mount, separated by newline.'
default: ''
blueprint:
required: false
description: 'Blueprint to use for setting up the environment.'
default: ''
wp-version:
required: false
description: 'WordPress version to use.'
default: 'latest'
php-version:
required: false
description: 'PHP version to use.'
default: '8.2'
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: |
echo "::group::Install dependencies"
npm ci ${{ inputs.debug != 'true' && '--silent' }}
echo "::endgroup::"
shell: 'bash'
working-directory: ${{ github.action_path }}/env
- name: Install Playwright browsers
run: |
echo "::group::Install Playwright browsers"
npx ${{ inputs.debug != 'true' && '--silent' }} playwright install --with-deps
echo "::endgroup::"
if: ${{ inputs.action == 'test' }}
shell: 'bash'
working-directory: ${{ github.action_path }}/env
- name: Set up WordPress Playground
run: |
ARGS=()
echo "::group::Mounting plugin directories"
ARGS+=("--mount=./wp-content/mu-plugins:/wordpress/wp-content/mu-plugins")
echo "./wp-content/mu-plugins:/wordpress/wp-content/mu-plugins"
PLUGINS=${PLUGINS%$'\n'}
THEMES=${THEMES%$'\n'}
IFS=$'\n';
PLUGINS=($PLUGINS)
THEMES=($THEMES)
for i in "${PLUGINS[@]}"; do
if [ ! -z i ]; then
PLUGIN_REALPATH=$(realpath "${{ github.workspace }}/$i");
PLUGIN_BASENAME=$(basename $PLUGIN_REALPATH);
ARGS+=("--mount=$PLUGIN_REALPATH:/wordpress/wp-content/plugins/$PLUGIN_BASENAME")
echo "$PLUGIN_REALPATH:/wordpress/wp-content/plugins/$PLUGIN_BASENAME"
fi
done
echo "::endgroup::"
echo "::group::Mounting theme directories"
for i in "${THEMES[@]}"; do
if [ ! -z i ]; then
THEME_REALPATH=$(realpath "${{ github.workspace }}/$i");
THEME_BASENAME=$(basename $THEME_REALPATH);
ARGS+=("--mount=$THEME_REALPATH:/wordpress/wp-content/themes/$THEME_BASENAME")
echo "$THEME_REALPATH:/wordpress/wp-content/themes/$THEME_BASENAME"
fi
done
echo "::endgroup::"
unset IFS;
echo "::group::Prepare blueprint"
if [ ! -z $BLUEPRINT ]; then
BLUEPRINT=$(realpath "${{ github.workspace }}/$BLUEPRINT");
echo "Provided blueprint file: $BLUEPRINT"
jq -s 'map(to_entries)|flatten|group_by(.key)|map({(.[0].key):map(.value)|add})|add' ./blueprints/setup.json $BLUEPRINT > ./blueprints/tmp-merged.json
ARGS+=(--blueprint=./blueprints/tmp-merged.json)
cat ./blueprints/tmp-merged.json | jq '.'
else
ARGS+=(--blueprint=./blueprints/setup.json)
cat ./blueprints/setup.json | jq '.'
fi
echo "::endgroup::"
ARGS+=(--wp=$WP_VERSION)
ARGS+=(--php=$PHP_VERSION)
echo "::group::Start Playground server"
./node_modules/@wp-playground/cli/wp-playground.js server "${ARGS[@]}" &
echo "::endgroup::"
env:
PLUGINS: ${{ inputs.plugins }}
THEMES: ${{ inputs.themes }}
BLUEPRINT: ${{ inputs.blueprint }}
WP_VERSION: ${{ inputs.wp-version }}
PHP_VERSION: ${{ inputs.php-version }}
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_BASE_URL: 'http://127.0.0.1:9400'
WP_ARTIFACTS_PATH: ${{ github.action_path }}/env/artifacts
BLOB_REPORT_PATH: ${{ github.action_path }}/env/blob-report
SHARD: ${{ inputs.shard != '' && inputs.shard || '' }}
ADDITIONAL_ARGS: ${{ inputs.shard != '' && format('-- --shard={0}', inputs.shard) || '' }}
URLS_TO_TEST: ${{ inputs.urls }}
DEBUG: ${{ inputs.debug == 'true' }}
TEST_ITERATIONS: ${{ inputs.iterations }}
TEST_REPETITIONS: ${{ inputs.repetitions }}
shell: 'bash'
working-directory: ${{ github.action_path }}/env
- name: Stop server
run: npm run stop-server
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: Rename results file
id: prepare-results
run: |
UUID=$(uuidgen)
mv $WP_ARTIFACTS_PATH/performance-results.json $RUNNER_TEMP/performance-results-$UUID.json
echo "results=$RUNNER_TEMP/performance-results-$UUID.json" >> $GITHUB_OUTPUT
if: ${{ ( inputs.action == 'test' || inputs.action == 'merge' ) }}
env:
WP_ARTIFACTS_PATH: ${{ github.action_path }}/env/artifacts
shell: 'bash'
- name: Log results
run: |
if [ ! -z $PREVIOUS_RESULTS ] && [ -f $PREVIOUS_RESULTS ]; then
npm run ${{ inputs.debug != 'true' && '--silent' }} test:performance:results $RESULTS_FILE $PREVIOUS_RESULTS
else
npm run ${{ inputs.debug != 'true' && '--silent' }} test:performance:results $RESULTS_FILE
fi;
if: ${{ inputs.action == 'test' || inputs.action == 'merge' }}
env:
RESULTS_FILE: ${{ steps.prepare-results.outputs.results }}
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 && inputs.print-results != 'false' }}
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=$RESULTS_FILE" >> $GITHUB_OUTPUT
if: ${{ ( inputs.action == 'test' || inputs.action == 'merge' ) && ! inputs.shard }}
env:
RESULTS_FILE: ${{ steps.prepare-results.outputs.results }}
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@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
if: ${{ success() && ( inputs.action == 'test' || inputs.action == 'merge' ) && ! inputs.shard && inputs.upload-artifacts != 'false' }}
with:
name: performance-results
path: ${{ steps.share-results.outputs.results }}
- name: Get blob artifact name
if: ${{ success() && inputs.shard != '' && inputs.upload-artifacts != 'false' }}
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@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
if: ${{ success() && inputs.shard != '' && inputs.upload-artifacts != 'false' }}
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ABS_ACTION_PATH }}/env/blob-report
retention-days: 1