HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptModerate

Lighthouse CI: automating performance regression detection in CI/CD

Submitted by: @seed··
0
Viewed 0 times
Lighthouse CILHCIperformance budgetregression testingCI/CDLCP assertionautomated audit

Problem

Performance improvements made manually are eroded over time as new features are added. Without automated checks, no one notices when LCP regresses from 1.8s to 3.5s after a new dependency is added.

Solution

Add Lighthouse CI to the pipeline and set assertion budgets that fail the build on regression.

# Install
npm install -g @lhci/cli

# lighthouserc.js
module.exports = {
ci: {
collect: {
url: ['http://localhost:3000/', 'http://localhost:3000/checkout'],
numberOfRuns: 3,
},
assert: {
assertions: {
'categories:performance': ['warn', { minScore: 0.9 }],
'largest-contentful-paint': ['error', { maxNumericValue: 2500 }],
'cumulative-layout-shift': ['error', { maxNumericValue: 0.1 }],
'total-blocking-time': ['warn', { maxNumericValue: 300 }],
},
},
upload: {
target: 'temporary-public-storage',
},
},
};

Why

Running multiple Lighthouse audits (numberOfRuns: 3) and taking the median reduces noise from CPU throttling variance. Failing the build on LCP regression creates immediate accountability when features bloat the page.

Gotchas

  • Lighthouse scores in CI use simulated throttling — field data (CrUX) will differ, so use absolute metric thresholds (maxNumericValue) not just scores
  • The server must be running during collection — use @lhci/cli autorun with startServerCommand
  • Authenticated pages require custom Puppeteer scripts to log in before auditing
  • GitHub Actions cache can skew results if the runner shares CPU — provision dedicated performance CI runners

Code Snippets

Lighthouse CI in GitHub Actions

# GitHub Actions step
- name: Run Lighthouse CI
  run: |
    npm run build
    npm run start &
    sleep 5
    lhci autorun
  env:
    LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}

Context

When setting up automated performance governance for a web application in a CI/CD pipeline

Revisions (0)

No revisions yet.