-
Notifications
You must be signed in to change notification settings - Fork 2
90 lines (79 loc) · 3.64 KB
/
Copy pathbundle-size.yml
File metadata and controls
90 lines (79 loc) · 3.64 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
name: Bundle Size
# Measures shipped bundle sizes on the PR head and the merge base, then hands
# both snapshots to the report workflow. This job is untrusted (it builds PR
# code) so it holds only `contents: read` and never posts — the workflow_run
# reporter holds the bot credentials. Same split as the Benchmarks suite.
on:
pull_request:
paths:
# shipped code — the measurement target
- 'packages/**'
- 'src/**'
# build scripts shape the output bytes, so a change here is a real
# (and measurable) size change, not a harness edit
- 'internal-packages/scripts/**'
# this workflow — changes take effect on the PR's own run, so self-test
- '.github/workflows/bundle-size.yml'
# The harness (tools/ci/size/**) is deliberately NOT listed. The measure
# job overlays it from main before every run, so a PR-side harness edit
# can't affect its own comment — harness changes land on main first, same
# as the bench suite.
concurrency:
group: bundle-size-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
measure:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-node@v7
with:
node-version-file: '.node-version'
cache: 'npm'
cache-dependency-path: package-lock.json
- name: Install dependencies
run: npm ci
# Author-neutral scorecard: the size harness (manifest, measure, loc,
# reporter) always comes from main, so a PR can't reshape how its own
# bundles are weighed. Build scripts are deliberately NOT pinned — a real
# minification or tree-shaking win should show up as a win. First-PR
# bootstrap: main has no tools/ci/size yet, so this no-ops and the PR's
# own harness runs (self-test), same as the bench suite.
- name: Overlay size harness from main
run: |
git fetch origin main --depth=1
git checkout origin/main -- tools/ci/size/ 2>/dev/null || true
- name: Build and measure PR head
run: |
npm run build
mkdir -p results
node tools/ci/size/collect.js --root . --label current --out results/current.json
# Swap shipped source and build scripts to the merge base, rebuild, and
# measure. node_modules is reused — a faithful-enough baseline, since
# dep bumps rarely move first-party bundle bytes. Files the PR adds are
# dropped so the lines-of-code delta counts new files honestly.
#
# Root package.json and the lockfile are swapped too: build:packages
# lists each package's :build explicitly, so a PR that adds (or removes)
# a package would otherwise leave the base build pointing at a :build
# target that doesn't exist on the base side.
- name: Build and measure merge base
run: |
git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1
BASELINE_SHA=$(git rev-parse FETCH_HEAD)
ADDED=$(git diff --name-only --diff-filter=A FETCH_HEAD HEAD -- packages src internal-packages || true)
git checkout FETCH_HEAD -- packages src internal-packages package.json package-lock.json 2>/dev/null || true
if [ -n "$ADDED" ]; then echo "$ADDED" | xargs -r rm -f; fi
npm run build
node tools/ci/size/collect.js --root . --label baseline --out results/baseline.json
echo "$BASELINE_SHA" > results/baseline-sha.txt
- name: Upload size snapshots
uses: actions/upload-artifact@v7
with:
name: size-results
path: results/*