Skip to content
Latchkey

How to Run Lighthouse CI with Performance Budgets in GitHub Actions

Performance regressions creep in one PR at a time; Lighthouse CI assertions catch them at the gate.

Use lhci autorun with a lighthouserc config that defines assert budgets, so a score or metric below threshold fails the job.

Steps

  • Add @lhci/cli and a lighthouserc.json with assert budgets.
  • Build the site and serve it (or point at a preview URL).
  • Run lhci autorun to collect and assert.
  • Let the assertion failures fail the job on regression.

Workflow

.github/workflows/lighthouse.yml
name: Lighthouse CI
on: [pull_request]
jobs:
  lhci:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: '20' }
      - run: npm ci && npm run build
      - run: npm i -g @lhci/cli
      - run: lhci autorun

Config

lighthouserc.json
{
  "ci": {
    "collect": { "staticDistDir": "./dist" },
    "assert": {
      "assertions": {
        "categories:performance": ["error", { "minScore": 0.9 }],
        "categories:accessibility": ["error", { "minScore": 0.95 }]
      }
    }
  }
}

Related guides

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