11name : Bundle Size
22
33on :
4- pull_request :
4+ # We use `pull_request_target` to split trust boundaries across jobs:
5+ # - `benchmark-pr` checks out PR merge code and runs it as untrusted with read-only permissions.
6+ # - `comment-pr` runs trusted base-repo code with limited write access to upsert the PR comment.
7+ pull_request_target :
58 push :
69 branches : [main]
710 workflow_dispatch :
@@ -11,26 +14,58 @@ concurrency:
1114 cancel-in-progress : true
1215
1316permissions :
14- contents : write
15- pull-requests : write
17+ contents : read
1618
1719jobs :
1820 benchmark-pr :
1921 name : Benchmark PR
20- if : github.event_name == 'pull_request '
22+ if : github.event_name == 'pull_request_target '
2123 runs-on : ubuntu-latest
24+ outputs :
25+ current_json_b64 : ${{ steps.capture.outputs.current_json_b64 }}
2226 steps :
2327 - name : Checkout
2428 uses : actions/checkout@v6.0.1
2529 with :
30+ ref : refs/pull/${{ github.event.pull_request.number }}/merge
2631 fetch-depth : 0
32+ persist-credentials : false
2733
2834 - name : Setup Tools
2935 uses : tanstack/config/.github/setup@main
3036
3137 - name : Measure Bundle Size
3238 run : pnpm nx run tanstack-router-e2e-bundle-size:build --outputStyle=stream --skipRemoteCache
3339
40+ - name : Capture Benchmark Outputs
41+ id : capture
42+ run : |
43+ {
44+ echo "current_json_b64=$(base64 -w 0 < e2e/bundle-size/results/current.json)"
45+ } >> "$GITHUB_OUTPUT"
46+
47+ comment-pr :
48+ name : Upsert PR Comment
49+ if : github.event_name == 'pull_request_target'
50+ runs-on : ubuntu-latest
51+ needs : benchmark-pr
52+ permissions :
53+ contents : read
54+ pull-requests : write
55+ steps :
56+ - name : Checkout
57+ uses : actions/checkout@v6.0.1
58+ with :
59+ fetch-depth : 0
60+ persist-credentials : false
61+
62+ - name : Restore Benchmark Outputs
63+ env :
64+ CURRENT_JSON_B64 : ${{ needs.benchmark-pr.outputs.current_json_b64 }}
65+ run : |
66+ mkdir -p e2e/bundle-size/results
67+ node -e "const fs=require('node:fs'); fs.writeFileSync('e2e/bundle-size/results/current.json', Buffer.from(process.env.CURRENT_JSON_B64 || '', 'base64'))"
68+
3469 - name : Read Historical Data (if available)
3570 run : |
3671 mkdir -p e2e/bundle-size/results
6499 name : Publish Bundle Size History
65100 if : github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository_owner == 'TanStack'
66101 runs-on : ubuntu-latest
102+ permissions :
103+ contents : write
67104 steps :
68105 - name : Checkout
69106 uses : actions/checkout@v6.0.1
0 commit comments