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

bundle-size.yml

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