Skip to content

Lighthouse CI

Lighthouse CI #91

Workflow file for this run

name: Lighthouse CI
on:
deployment_status:
permissions:
contents: read
pull-requests: write
concurrency:
group: lighthouse-${{ github.event.deployment.ref }}
cancel-in-progress: true
jobs:
lighthouse:
if: github.event.deployment_status.state == 'success' && github.event.deployment_status.environment == 'Preview'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create Lighthouse config
run: |
cat > /tmp/lighthouserc.json << 'TEMPLATE'
{
"ci": {
"collect": {
"settings": {
"extraHeaders": {
"x-vercel-protection-bypass": "BYPASS_SECRET_PLACEHOLDER"
}
}
}
}
}
TEMPLATE
sed -i "s/BYPASS_SECRET_PLACEHOLDER/$VERCEL_BYPASS_SECRET/" /tmp/lighthouserc.json
env:
VERCEL_BYPASS_SECRET: ${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }}
- name: Lighthouse audit
id: lighthouse
uses: treosh/lighthouse-ci-action@v12
with:
urls: |
${{ github.event.deployment_status.target_url }}/
${{ github.event.deployment_status.target_url }}/blog
${{ github.event.deployment_status.target_url }}/about
runs: 3
configPath: /tmp/lighthouserc.json
budgetPath: .github/lighthouse-budget.json
uploadArtifacts: true
- name: Find PR number
id: find-pr
uses: actions/github-script@v7
with:
script: |
const prs = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: `${context.repo.owner}:${context.payload.deployment.ref}`,
state: 'open',
});
if (prs.data.length > 0) {
core.setOutput('number', prs.data[0].number);
}
- name: Format results
id: format
if: always() && steps.find-pr.outputs.number
uses: actions/github-script@v7
with:
script: |
const results = ${{ steps.lighthouse.outputs.manifest }};
let comment = '## Lighthouse Results\n\n';
comment += '| URL | Performance | Accessibility | Best Practices | SEO |\n';
comment += '|-----|------------|---------------|----------------|-----|\n';
for (const result of results) {
const url = new URL(result.url).pathname || '/';
const perf = Math.round(result.summary.performance * 100);
const a11y = Math.round(result.summary.accessibility * 100);
const bp = Math.round(result.summary['best-practices'] * 100);
const seo = Math.round(result.summary.seo * 100);
comment += `| ${url} | ${perf} | ${a11y} | ${bp} | ${seo} |\n`;
}
core.setOutput('comment', comment);
- name: Post comment
if: always() && steps.find-pr.outputs.number
uses: marocchino/sticky-pull-request-comment@v2
with:
header: lighthouse
number: ${{ steps.find-pr.outputs.number }}
message: ${{ steps.format.outputs.comment }}