-
Notifications
You must be signed in to change notification settings - Fork 173
101 lines (83 loc) · 3.17 KB
/
Copy pathlighthouse-ci.yml
File metadata and controls
101 lines (83 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Lighthouse CI
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
lighthouse:
name: Lighthouse CI
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: "npm"
cache-dependency-path: frontend/package-lock.json
- name: Install frontend dependencies
working-directory: frontend
run: npm ci
- name: Build frontend
working-directory: frontend
run: npm run build
- name: Run Lighthouse CI
uses: treosh/lighthouse-ci-action@v10
with:
configPath: ./frontend/lighthouserc.json
uploadArtifacts: true
temporaryPublicStorage: true
- name: Comment PR with Lighthouse scores
if: always() && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const resultsPath = './lhr.json';
if (!fs.existsSync(resultsPath)) {
console.log('Lighthouse results not found');
return;
}
const results = JSON.parse(fs.readFileSync(resultsPath, 'utf8'));
const { categories } = results;
const scores = {
'Performance': categories.performance.score * 100,
'Accessibility': categories.accessibility.score * 100,
'Best Practices': categories['best-practices'].score * 100,
'SEO': categories.seo.score * 100,
};
const thresholds = {
'Performance': 80,
'Accessibility': 90,
'Best Practices': 90,
};
let comment = '## ⚡ Lighthouse CI Results\n\n';
comment += '| Category | Score | Threshold | Status |\n';
comment += '|----------|-------|-----------|--------|\n';
let allPassed = true;
Object.entries(scores).forEach(([category, score]) => {
const threshold = thresholds[category];
const status = threshold ? (score >= threshold ? '✅' : '❌') : '⏭️';
const displayScore = `${Math.round(score)}`;
const displayThreshold = threshold ? `${threshold}` : 'N/A';
if (threshold && score < threshold) {
allPassed = false;
}
comment += `| ${category} | ${displayScore} | ${displayThreshold} | ${status} |\n`;
});
comment += '\n';
if (allPassed) {
comment += '✨ All performance budgets met!';
} else {
comment += '⚠️ Some performance budgets were not met. Please review and optimize.';
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment,
});