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/cliand alighthouserc.jsonwithassertbudgets. - Build the site and serve it (or point at a preview URL).
- Run
lhci autorunto 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 autorunConfig
lighthouserc.json
{
"ci": {
"collect": { "staticDistDir": "./dist" },
"assert": {
"assertions": {
"categories:performance": ["error", { "minScore": 0.9 }],
"categories:accessibility": ["error", { "minScore": 0.95 }]
}
}
}
}Related guides
How to Run Accessibility Tests in GitHub ActionsRun automated accessibility checks in GitHub Actions with axe-core against a built site or running app so WCA…
How to Run k6 Load Tests in GitHub ActionsRun a k6 load test in GitHub Actions and fail the build when latency or error-rate thresholds are breached, u…