Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

bundle-size.yml

150 lines5.3 KB

1name: Bundle Size
2​
3on:
4 # We use `pull_request` 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:
8 paths:
9 - 'packages/**'
10 - 'benchmarks/**'
11 - 'scripts/benchmarks/bundle-size/**'
12 - '.nvmrc'
13 - 'package.json'
14 - 'pnpm-lock.yaml'
15 push:
16 branches: [main]
17 paths:
18 - 'packages/**'
19 - 'benchmarks/**'
20 - 'scripts/benchmarks/bundle-size/**'
21 - '.nvmrc'
22 - 'package.json'
23 - 'pnpm-lock.yaml'
24 workflow_dispatch:
25​
26concurrency:
27 group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
28 cancel-in-progress: true
29​
30permissions:
31 contents: read
32​
33env:
34 NX_NO_CLOUD: true
35jobs:
36 benchmark-pr:
37 name: Benchmark PR
38 if: github.event_name == 'pull_request'
39 runs-on: ubuntu-latest
40 outputs:
41 current_json_b64: ${{ steps.capture.outputs.current_json_b64 }}
42 steps:
43 - name: Checkout
44 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
45 with:
46 ref: refs/pull/${{ github.event.pull_request.number }}/merge
47 fetch-depth: 0
48 persist-credentials: false
49​
50 - name: Setup Tools
51 uses: TanStack/config/.github/setup@e4b48f16568324f76f467aa4c2aac2f05db632c3 # main
52​
53 - name: Measure Bundle Size
54 run: pnpm benchmark:bundle-size --outputStyle=stream --skipRemoteCache
55​
56 - name: Capture Benchmark Outputs
57 id: capture
58 run: |
59 {
60 echo "current_json_b64=$(base64 -w 0 < benchmarks/bundle-size/results/current.json)"
61 } >> "$GITHUB_OUTPUT"
62​
63 comment-pr:
64 name: Upsert PR Comment
65 if: github.event_name == 'pull_request'
66 runs-on: ubuntu-latest
67 needs: benchmark-pr
68 permissions:
69 contents: read
70 pull-requests: write
71 steps:
72 - name: Checkout
73 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
74 with:
75 fetch-depth: 0
76 persist-credentials: false
77​
78 - name: Restore Benchmark Outputs
79 env:
80 CURRENT_JSON_B64: ${{ needs.benchmark-pr.outputs.current_json_b64 }}
81 run: |
82 mkdir -p benchmarks/bundle-size/results
83 node -e "const fs=require('node:fs'); fs.writeFileSync('benchmarks/bundle-size/results/current.json', Buffer.from(process.env.CURRENT_JSON_B64 || '', 'base64'))"
84​
85 - name: Read Historical Data (if available)
86 run: |
87 mkdir -p benchmarks/bundle-size/results
88 if git fetch --depth=1 origin gh-pages; then
89 if git show origin/gh-pages:benchmarks/bundle-size/data.js > benchmarks/bundle-size/results/history-data.js 2>/dev/null; then
90 echo "Loaded bundle-size history from gh-pages."
91 else
92 rm -f benchmarks/bundle-size/results/history-data.js
93 echo "No bundle-size history found on gh-pages yet."
94 fi
95 fi
96​
97 - name: Build PR Report
98 env:
99 BASE_SHA: ${{ github.event.pull_request.base.sha }}
100 REPOSITORY_NAME: ${{ github.event.repository.name }}
101 REPOSITORY_OWNER: ${{ github.repository_owner }}
102 run: |
103 node scripts/benchmarks/bundle-size/pr-report.mjs \
104 --current benchmarks/bundle-size/results/current.json \
105 --history benchmarks/bundle-size/results/history-data.js \
106 --output benchmarks/bundle-size/results/pr-comment.md \
107 --base-sha "$BASE_SHA" \
108 --dashboard-url "https://${REPOSITORY_OWNER}.github.io/${REPOSITORY_NAME}/benchmarks/bundle-size/"
109 cat benchmarks/bundle-size/results/pr-comment.md
110​
111 - name: Upsert Sticky PR Comment
112 env:
113 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114 run: |
115 node scripts/benchmarks/common/upsert-pr-comment.mjs \
116 --pr "${{ github.event.pull_request.number }}" \
117 --body-file benchmarks/bundle-size/results/pr-comment.md
118​
119 benchmark-main:
120 name: Publish Bundle Size History
121 if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main' && github.repository_owner == 'TanStack'
122 runs-on: ubuntu-latest
123 permissions:
124 contents: write
125 steps:
126 - name: Checkout
127 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
128 with:
129 fetch-depth: 0
130 persist-credentials: false
131​
132 - name: Setup Tools
133 uses: TanStack/config/.github/setup@e4b48f16568324f76f467aa4c2aac2f05db632c3 # main
134​
135 - name: Measure Bundle Size
136 run: pnpm benchmark:bundle-size --outputStyle=stream --skipRemoteCache
137 - name: Publish Benchmark Dashboard
138 uses: benchmark-action/github-action-benchmark@52576c92bccf6ac60c8223ec7eb2565637cae9ba # v1.22.1
139 with:
140 tool: customSmallerIsBetter
141 name: Bundle Size (gzip)
142 output-file-path: benchmarks/bundle-size/results/benchmark-action.json
143 github-token: ${{ secrets.GITHUB_TOKEN }}
144 auto-push: true
145 gh-pages-branch: gh-pages
146 benchmark-data-dir-path: benchmarks/bundle-size
147 max-items-in-chart: 200
148 summary-always: true
149 comment-on-alert: false
150 fail-on-alert: false