4444 # changed if we want to normalize results against a different baseline.
4545 BASE_TAG : ' 6.1.1'
4646 LOCAL_DIR : build
47+ TARGET_REF : ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || '' }}
48+ TARGET_SHA : ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
4749
4850jobs :
4951 # Runs the performance test suite.
6567 # - Install MU plugin.
6668 # - Run performance tests (current commit).
6769 # - Print performance tests results.
70+ # - Check out target commit (target branch or previous commit).
71+ # - Install npm dependencies.
72+ # - Build WordPress.
73+ # - Run performance tests (previous/target commit).
74+ # - Print target performance tests results.
75+ # - Reset to original commit.
6876 # - Set the environment to the baseline version.
6977 # - Run baseline performance tests.
70- # - Print base line performance tests results.
78+ # - Print baseline performance tests results.
79+ # - Compare results with base.
80+ # - Add workflow summary.
7181 # - Set the base sha.
7282 # - Set commit details.
7383 # - Publish performance results.
@@ -152,7 +162,31 @@ jobs:
152162 run : npm run test:performance
153163
154164 - name : Print performance tests results
155- run : " node ./tests/performance/results.js"
165+ run : node ./tests/performance/results.js
166+
167+ - name : Check out target commit (target branch or previous commit)
168+ run : |
169+ if [[ -z "$TARGET_REF" ]]; then
170+ git fetch -n origin $TARGET_SHA
171+ else
172+ git fetch -n origin $TARGET_REF
173+ fi
174+ git reset --hard $TARGET_SHA
175+
176+ - name : Install npm dependencies
177+ run : npm ci
178+
179+ - name : Build WordPress
180+ run : npm run build
181+
182+ - name : Run target performance tests (base/previous commit)
183+ run : npm run test:performance -- --prefix=before
184+
185+ - name : Print target performance tests results
186+ run : node ./tests/performance/results.js --prefix=before
187+
188+ - name : Reset to original commit
189+ run : git reset --hard $GITHUB_SHA
156190
157191 - name : Set the environment to the baseline version
158192 run : |
@@ -162,8 +196,14 @@ jobs:
162196 - name : Run baseline performance tests
163197 run : npm run test:performance -- --prefix=base
164198
165- - name : Print base line performance tests results
166- run : " node ./tests/performance/results.js --prefix=base"
199+ - name : Print baseline performance tests results
200+ run : node ./tests/performance/results.js --prefix=base
201+
202+ - name : Compare results with base
203+ run : node ./tests/performance/compare-results.js ${{ runner.temp }}/summary.md
204+
205+ - name : Add workflow summary
206+ run : cat ${{ runner.temp }}/summary.md >> $GITHUB_STEP_SUMMARY
167207
168208 - name : Set the base sha
169209 # Only needed when publishing results.
0 commit comments