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