Skip to content
Latchkey

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

Run this faster and cheaper on Latchkey managed runners. Start free →