Skip to content

Commit 0e600a1

Browse files
authored
Add PR comment logic (#84)
1 parent 5d97a01 commit 0e600a1

4 files changed

Lines changed: 75 additions & 19 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: 'test-pr-comment'
2+
on: # rebuild any PRs and main branch changes
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
- 'releases/*'
8+
9+
jobs:
10+
basic:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Run performance tests
17+
uses: ./
18+
with:
19+
urls: |
20+
/
21+
/sample-page/
22+
create-comment: true
23+
github-token: ${{ secrets.PR_COMMENT_TOKEN }}

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ See [action.yml](action.yml)
2323
# Default: ${{ github.token }}
2424
github-token: ''
2525

26+
# Whether to create PR comments with performance results.
27+
# Might require a custom `github-token` to be set.
28+
#
29+
# Default: false
30+
create-comment: ''
31+
2632
# Whether to log additional debugging information
2733
#
2834
# Default: ${{ runner.debug == '1' }}

action.yml

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ inputs:
99
description: 'The GitHub token used to create PR comments.'
1010
required: false
1111
default: ${{ github.token }}
12+
create-comment:
13+
description: 'Whether to create PR comments with performance results.'
14+
required: false
15+
default: ''
1216
debug:
1317
description: 'Whether to log additional debugging information.'
1418
default: ${{ runner.debug == '1' }}
@@ -90,18 +94,20 @@ runs:
9094
cache: ''
9195

9296
- name: Install dependencies
93-
run: npm ci
97+
run: npm ci ${{ inputs.debug != 'true' && '--silent' }}
9498
shell: 'bash'
9599
working-directory: ${{ github.action_path }}/env
96100

97101
- name: Install Playwright Browsers
98-
run: npx playwright install --with-deps
102+
run: npx ${{ inputs.debug != 'true' && '--silent' }} playwright install --with-deps
99103
if: ${{ inputs.action == 'test' }}
100104
shell: 'bash'
101105
working-directory: ${{ github.action_path }}/env
102106

103107
- name: Prepare wp-env
104108
run: |
109+
echo "Preparing wp-env..."
110+
105111
PLUGINS=${PLUGINS%$'\n'}
106112
THEMES=${THEMES%$'\n'}
107113
@@ -177,7 +183,10 @@ runs:
177183
'{core: $wp, phpVersion: $php, plugins: [($rp | split("\n")), ($p | split("\n"))] | add, themes: [($rt | split("\n")), ($t | split("\n"))] | add}' \
178184
> ${{ env.ABS_ACTION_PATH }}/env/.wp-env.override.json
179185
180-
cat ${{ env.ABS_ACTION_PATH }}/env/.wp-env.override.json
186+
if [[ ${{ inputs.debug == 'true' }} == true ]]; then
187+
echo "Generated .wp-env.override.json file:"
188+
cat ${{ env.ABS_ACTION_PATH }}/env/.wp-env.override.json
189+
fi
181190
if: ${{ inputs.action == 'test' }}
182191
env:
183192
PLUGINS: ${{ inputs.plugins }}
@@ -187,46 +196,46 @@ runs:
187196
shell: 'bash'
188197

189198
- name: Start WordPress
190-
run: npm run wp-env start
199+
run: npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env start
191200
if: ${{ inputs.action == 'test' }}
192201
shell: 'bash'
193202
working-directory: ${{ github.action_path }}/env
194203

195204
- name: Update permalink structure
196-
run: npm run wp-env run tests-cli wp rewrite structure '/%postname%/' -- --hard
205+
run: npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env run tests-cli wp rewrite structure '/%postname%/' -- --hard
197206
if: ${{ inputs.action == 'test' }}
198207
shell: 'bash'
199208
working-directory: ${{ github.action_path }}/env
200209

201210
- name: Import mock data
202211
run: |
203-
npm run wp-env run tests-cli wp plugin list
204-
npm run wp-env run tests-cli curl -s https://raw.githubusercontent.com/WordPress/theme-test-data/b9752e0533a5acbb876951a8cbb5bcc69a56474c/themeunittestdata.wordpress.xml -- --output /tmp/themeunittestdata.wordpress.xml
205-
npm run wp-env run tests-cli wp import /tmp/themeunittestdata.wordpress.xml -- --authors=create --quiet
206-
npm run wp-env run tests-cli wp plugin deactivate wordpress-importer --quiet
212+
npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env run tests-cli wp plugin list
213+
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
214+
npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env run tests-cli wp import /tmp/themeunittestdata.wordpress.xml -- --authors=create --quiet
215+
npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env run tests-cli wp plugin deactivate wordpress-importer --quiet
207216
if: ${{ inputs.action == 'test' }}
208217
shell: 'bash'
209218
working-directory: ${{ github.action_path }}/env
210219

211220
- name: Prepare test site
212221
run: |
213-
npm run wp-env run tests-cli wp theme activate $THEME --quiet
214-
npm run wp-env run tests-cli wp config set WP_HTTP_BLOCK_EXTERNAL true --raw --type=constant
215-
npm run wp-env run tests-cli wp config set DISABLE_WP_CRON true --raw --type=constant
222+
npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env run tests-cli wp theme activate $THEME --quiet
223+
npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env run tests-cli wp config set WP_HTTP_BLOCK_EXTERNAL true --raw --type=constant
224+
npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env run tests-cli wp config set DISABLE_WP_CRON true --raw --type=constant
216225
if: ${{ inputs.action == 'test' }}
217226
env:
218227
THEME: ${{ inputs.active-theme }}
219228
shell: 'bash'
220229
working-directory: ${{ github.action_path }}/env
221230

222231
- name: List defined constants
223-
run: npm run wp-env run tests-cli wp config list --path=/var/www/${{ env.LOCAL_DIR }}
232+
run: npm run ${{ inputs.debug != 'true' && '--silent' }} wp-env run tests-cli wp config list --path=/var/www/${{ env.LOCAL_DIR }}
224233
if: ${{ inputs.action == 'test' && inputs.debug == 'true' }}
225234
shell: 'bash'
226235
working-directory: ${{ github.action_path }}/env
227236

228237
- name: Run tests
229-
run: npm run test:performance $ADDITIONAL_ARGS
238+
run: npm run ${{ inputs.debug != 'true' && '--silent' }} test:performance $ADDITIONAL_ARGS
230239
if: ${{ inputs.action == 'test' }}
231240
env:
232241
WP_ARTIFACTS_PATH: ${{ github.action_path }}/env/artifacts
@@ -247,17 +256,17 @@ runs:
247256
path: performance-blob-report
248257

249258
- name: Merge into single performance report
250-
run: npm run test:performance:merge-reports ${{steps.download.outputs.download-path}}
259+
run: npm run ${{ inputs.debug != 'true' && '--silent' }} test:performance:merge-reports ${{steps.download.outputs.download-path}}
251260
if: ${{ inputs.action == 'merge' }}
252261
shell: 'bash'
253262
working-directory: ${{ github.action_path }}/env
254263

255264
- name: Print results
256265
run: |
257266
if [ ! -z $PREVIOUS_RESULTS ] && [ -f $PREVIOUS_RESULTS ]; then
258-
npm run test:performance:results $WP_ARTIFACTS_PATH/performance-results.json $PREVIOUS_RESULTS
267+
npm run ${{ inputs.debug != 'true' && '--silent' }} test:performance:results $WP_ARTIFACTS_PATH/performance-results.json $PREVIOUS_RESULTS
259268
else
260-
npm run test:performance:results
269+
npm run ${{ inputs.debug != 'true' && '--silent' }} test:performance:results
261270
fi;
262271
if: ${{ inputs.action == 'test' || inputs.action == 'merge' }}
263272
env:
@@ -275,6 +284,24 @@ runs:
275284
shell: 'bash'
276285
working-directory: ${{ github.action_path }}/env
277286

287+
- name: Check if a comment was already made
288+
id: find-comment
289+
if: ${{ inputs.create-comment == 'true' }}
290+
uses: peter-evans/find-comment@a54c31d7fa095754bfef525c0c8e5e5674c4b4b1
291+
with:
292+
issue-number: ${{ github.event.pull_request.number }}
293+
body-includes: Performance test results for
294+
295+
- name: Comment on PR with test results
296+
uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa
297+
if: ${{ inputs.create-comment == 'true' }}
298+
with:
299+
issue-number: ${{ github.event.pull_request.number }}
300+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
301+
edit-mode: replace
302+
body-path: ${{ github.action_path }}/env/artifacts/performance-results.md
303+
token: ${{ inputs.github-token }}
304+
278305
- name: Share raw results
279306
id: share-results
280307
run: echo "results=$WP_ARTIFACTS_PATH/performance-results.json" >> $GITHUB_OUTPUT

env/tests/performance/playwright.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ const reporter: ReporterDescription[] = [
2323
[ './config/performance-reporter.ts' ],
2424
];
2525

26-
if ( process.env.SHARD ) {
26+
if ( process.env.SHARD !== '' ) {
2727
reporter.unshift( [ 'blob', { outputDir: process.env.BLOB_REPORT_PATH } ] );
2828
}
2929

30-
if ( process.env.DEBUG ) {
30+
if ( process.env.DEBUG == 'true' ) {
3131
reporter.unshift( [ 'list' ] );
3232
}
3333

0 commit comments

Comments
 (0)