How to Fail a PR if the Bundle Grows in GitHub Actions
Bundle bloat creeps in one PR at a time; a hard size budget in CI stops the regression before it merges.
Build the bundle, measure it, and exit non-zero when it exceeds the budget, using a tool like size-limit or a script.
Steps
- Build the production bundle in the PR.
- Measure the gzipped size of the entry chunks.
- Compare against a committed budget value.
- Exit non-zero when the size exceeds the budget.
Workflow
.github/workflows/bundle-budget.yml
name: Bundle Budget
on: [pull_request]
jobs:
size:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: '20', cache: npm }
- run: npm ci && npm run build
- run: npx size-limit
# .size-limit.json
# [{ "path": "dist/index.js", "limit": "150 KB" }]Notes
- Measure gzipped size, since that is what users actually download.
- Latchkey managed runners run these size-check jobs cheaper and self-heal mid-run.
Related guides
How to Run a Bundle-Size Check on PRs in GitHub ActionsGate pull requests on bundle size in GitHub Actions with size-limit so a PR that bloats the JavaScript payloa…
How to Comment Benchmark Deltas on PRs in GitHub ActionsRun benchmarks against a PR and the base branch in GitHub Actions, compute the delta, and post it as a sticky…