Skip to content

Commit 5176156

Browse files
ci: optimize page load benchmarks (#37210)
## **Description** - Reduces by 2 the number of reusable workflows called by workflow `main` ([there's a limit of 20](https://docs.github.com/en/actions/reference/workflows-and-actions/reusing-workflow-configurations#limitations-of-reusable-workflows)) - This also has the effect of making everything run faster, due to fewer jobs and fewer `action-checkout-and-setup` steps - Folds the `Page Load Benchmark Results` PR comment into the other metamaskbot comment for less disruption ## **Changelog** CHANGELOG entry: null <!--## **Related issues** ## **Manual testing steps** ## **Screenshots/Recordings** ## **Pre-merge author checklist** ## **Pre-merge reviewer checklist**--> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Consolidates page-load benchmark into a single workflow with new artifact/filename, uploads historical data on main, and folds PR comment generation into the build announce with historical comparisons. > > - **CI/Workflows**: > - Replace `page-load-benchmark-pr` and remove `page-load-benchmark-upload`; use unified `page-load-benchmark` workflow with numeric inputs and required secret. > - Run benchmarks on PRs and main; upload artifact `page-load-benchmark-results` and, on `main`, commit stats to `extension_benchmark_stats`. > - Update `main.yml` to call `./.github/workflows/page-load-benchmark.yml` and gate publish on `page-load-benchmark`. > - In `publish-prerelease.yml`, download `page-load-benchmark-results` directly instead of using the deleted action. > - **Scripts**: > - Update `.github/scripts/benchmark-stats-commit.sh` to use `HEAD_COMMIT_HASH`, `OWNER`, and new results path `test-artifacts/benchmarks/page-load-benchmark-results.json`. > - **Bot Comment Integration**: > - Refactor `development/page-load-benchmark-pr-comment.ts` to export `getPageLoadBenchmarkComment` (no direct posting), wrap output in a collapsible section, and compare against recent `main` data with regression warnings. > - Integrate page-load benchmark comment into `development/metamaskbot-build-announce.ts` so a single MetaMask bot comment includes builds, benchmarks, and size diffs. > - **Artifacts/Paths**: > - Rename benchmark output file and artifact from `benchmark-results.json` → `page-load-benchmark-results.json` and update all references. > - **Tests/Docs**: > - Update Playwright spec and README to use the new results filename. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 424ed39. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Norbert Elter <[email protected]>
1 parent f85570e commit 5176156

File tree

10 files changed

+81
-159
lines changed

10 files changed

+81
-159
lines changed

.github/actions/page-load-benchmark-comment/action.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/scripts/benchmark-stats-commit.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ if [[ -z "${EXTENSION_BENCHMARK_STATS_TOKEN:-}" ]]; then
99
exit 1
1010
fi
1111

12-
if [[ -z "${GITHUB_SHA:-}" ]]; then
13-
printf '%s\n' 'GITHUB_SHA environment variable must be set'
12+
if [[ -z "${HEAD_COMMIT_HASH:-}" ]]; then
13+
printf '%s\n' 'HEAD_COMMIT_HASH environment variable must be set'
1414
exit 1
1515
fi
1616

17-
if [[ -z "${GITHUB_REPOSITORY_OWNER:-}" ]]; then
18-
printf '%s\n' 'GITHUB_REPOSITORY_OWNER environment variable must be set'
17+
if [[ -z "${OWNER:-}" ]]; then
18+
printf '%s\n' 'OWNER environment variable must be set'
1919
exit 1
2020
fi
2121

@@ -33,7 +33,7 @@ git fetch origin main:main
3333

3434
git checkout main
3535

36-
BENCHMARK_FILE="../test-artifacts/benchmarks/benchmark-results.json"
36+
BENCHMARK_FILE="../test-artifacts/benchmarks/page-load-benchmark-results.json"
3737
STATS_FILE="stats/page_load_data.json"
3838
TEMP_FILE="stats/page_load_data.temp.json"
3939

@@ -53,13 +53,13 @@ jq . "${BENCHMARK_FILE}" > /dev/null || {
5353
}
5454

5555
# Check if the SHA already exists in the stats file
56-
if jq -e "has(\"${GITHUB_SHA}\")" "${STATS_FILE}" > /dev/null; then
57-
echo "SHA ${GITHUB_SHA} already exists in stats file. No new commit needed."
56+
if jq -e "has(\"${HEAD_COMMIT_HASH}\")" "${STATS_FILE}" > /dev/null; then
57+
echo "SHA ${HEAD_COMMIT_HASH} already exists in stats file. No new commit needed."
5858
exit 0
5959
fi
6060

6161
# Append new benchmark data correctly using jq
62-
jq --arg sha "${GITHUB_SHA}" --argjson data "$(cat "${BENCHMARK_FILE}")" \
62+
jq --arg sha "${HEAD_COMMIT_HASH}" --argjson data "$(cat "${BENCHMARK_FILE}")" \
6363
'. + {($sha): $data}' "${STATS_FILE}" > "${TEMP_FILE}"
6464

6565
# Overwrite the original JSON file with the corrected version
@@ -68,9 +68,9 @@ mv "${TEMP_FILE}" "${STATS_FILE}"
6868
# Only add the JSON file
6969
git add stats/page_load_data.json
7070

71-
git commit --message "Adding page load benchmark data at commit: ${GITHUB_SHA}"
71+
git commit --message "Adding page load benchmark data at commit: ${HEAD_COMMIT_HASH}"
7272

73-
repo_slug="${GITHUB_REPOSITORY_OWNER}/extension_benchmark_stats"
73+
repo_slug="${OWNER}/extension_benchmark_stats"
7474

7575
git push "https://metamaskbot:${EXTENSION_BENCHMARK_STATS_TOKEN}@github.com/${repo_slug}" main
7676

.github/workflows/main.yml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,22 +241,15 @@ jobs:
241241
s3-bucket: ${{ vars.AWS_S3_BUCKET }}/${{ github.event.repository.name }}/${{ github.run_id }}/bundle-size
242242
path: test-artifacts/chrome
243243

244-
page-load-benchmark-pr:
244+
page-load-benchmark:
245245
needs:
246246
- build-test-browserify
247-
if: ${{ github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref_name == 'main') }}
248-
uses: ./.github/workflows/page-load-benchmark-pr.yml
249-
with:
250-
browser-loads: '10'
251-
page-loads: '10'
252-
253-
page-load-benchmark-upload:
254-
needs:
255-
- page-load-benchmark-pr
256-
if: github.ref == 'refs/heads/main'
257-
uses: ./.github/workflows/page-load-benchmark-upload.yml
247+
uses: ./.github/workflows/page-load-benchmark.yml
258248
secrets:
259249
EXTENSION_BENCHMARK_STATS_TOKEN: ${{ secrets.EXTENSION_BENCHMARK_STATS_TOKEN }}
250+
with:
251+
browser-loads: 10
252+
page-loads: 10
260253

261254
needs-e2e:
262255
needs:
@@ -419,6 +412,7 @@ jobs:
419412
- build-test-flask-browserify
420413
- build-test-flask-mv2-browserify
421414
- run-benchmarks
415+
- page-load-benchmark
422416
- bundle-size
423417
- build-storybook
424418
- build-ts-migration-dashboard

.github/workflows/page-load-benchmark-upload.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

.github/workflows/page-load-benchmark-pr.yml renamed to .github/workflows/page-load-benchmark.yml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ on:
66
browser-loads:
77
description: 'Number of browser loads to perform'
88
required: false
9-
type: string
10-
default: '10'
9+
type: number
10+
default: 10
1111
page-loads:
1212
description: 'Number of page loads per browser'
1313
required: false
14-
type: string
15-
default: '10'
14+
type: number
15+
default: 10
16+
secrets:
17+
EXTENSION_BENCHMARK_STATS_TOKEN:
18+
required: true
1619

1720
jobs:
1821
page-load-benchmark-pr:
@@ -23,28 +26,42 @@ jobs:
2326
OWNER: ${{ github.repository_owner }}
2427
REPOSITORY: ${{ github.event.repository.name }}
2528
PR_NUMBER: ${{ github.event.pull_request.number }}
26-
GITHUB_SHA: ${{ github.event.pull_request.head.sha }}
29+
HEAD_COMMIT_HASH: ${{ github.event.pull_request.head.sha || github.sha }}
30+
BENCHMARK_BROWSER_LOADS: ${{ inputs.browser-loads }}
31+
BENCHMARK_PAGE_LOADS: ${{ inputs.page-loads }}
32+
IS_PR_OR_MAIN: ${{ github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref_name == 'main') }}
2733
steps:
2834
- name: Checkout and setup environment
35+
if: ${{ env.IS_PR_OR_MAIN }}
2936
uses: MetaMask/action-checkout-and-setup@v1
3037
with:
3138
is-high-risk-environment: false
3239
skip-allow-scripts: true
3340
use-yarn-hydrate: true
3441

3542
- name: Download artifact 'build-test-browserify'
43+
if: ${{ env.IS_PR_OR_MAIN }}
3644
uses: actions/download-artifact@v4
3745
with:
3846
name: build-test-browserify
3947

4048
- name: Install Playwright browsers
49+
if: ${{ env.IS_PR_OR_MAIN }}
4150
run: yarn playwright install chromium
4251

4352
- name: Run page load benchmarks
53+
if: ${{ env.IS_PR_OR_MAIN }}
4454
run: yarn test:e2e:benchmark
4555

4656
- name: Upload benchmark results (github artifacts)
57+
if: ${{ env.IS_PR_OR_MAIN }}
4758
uses: actions/upload-artifact@v4
4859
with:
49-
name: benchmark-results
50-
path: test-artifacts/benchmarks/benchmark-results.json
60+
name: page-load-benchmark-results
61+
path: test-artifacts/benchmarks/page-load-benchmark-results.json
62+
63+
- name: Upload benchmark results (historical data)
64+
if: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
65+
run: .github/scripts/benchmark-stats-commit.sh
66+
env:
67+
EXTENSION_BENCHMARK_STATS_TOKEN: ${{ secrets.EXTENSION_BENCHMARK_STATS_TOKEN }}

.github/workflows/publish-prerelease.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ jobs:
6767
echo "MERGE_BASE_COMMIT_HASH=${merge_base_commit_hash}" >> "${GITHUB_ENV}"
6868
echo "The merge base commit hash is '${merge_base_commit_hash}'"
6969
70-
- name: Page load benchmark comment
70+
- name: Download page load benchmark results
7171
if: ${{ github.event_name == 'pull_request' }}
72-
uses: ./.github/actions/page-load-benchmark-comment
72+
uses: actions/download-artifact@v4
7373
with:
74-
head-commit-hash: ${{ env.HEAD_COMMIT_HASH }}
75-
pr-comment-token: ${{ secrets.PR_COMMENT_TOKEN }}
74+
name: page-load-benchmark-results
75+
path: test-artifacts/benchmarks
7676

7777
- name: Publish prerelease
7878
if: ${{ env.MERGE_BASE_COMMIT_HASH && env.PR_NUMBER && env.PR_COMMENT_TOKEN && vars.AWS_CLOUDFRONT_URL }}

development/metamaskbot-build-announce.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import startCase from 'lodash/startCase';
22
import { version as VERSION } from '../package.json';
3+
import { getPageLoadBenchmarkComment } from './page-load-benchmark-pr-comment';
34
import { postCommentWithMetamaskBot } from './utils/benchmark-utils';
45

56
const benchmarkPlatforms = ['chrome', 'firefox'];
@@ -330,6 +331,12 @@ async function start(): Promise<void> {
330331
console.log(`No results for ${summaryPlatform} found; skipping benchmark`);
331332
}
332333

334+
// Add the page load benchmark results
335+
const pageLoadBenchmarkComment = await getPageLoadBenchmarkComment();
336+
if (pageLoadBenchmarkComment) {
337+
commentBody += pageLoadBenchmarkComment;
338+
}
339+
333340
try {
334341
const prBundleSizeStatsResponse = await fetch(bundleSizeStatsUrl);
335342
if (!prBundleSizeStatsResponse.ok) {

0 commit comments

Comments
 (0)