-
Notifications
You must be signed in to change notification settings - Fork 1
130 lines (112 loc) · 4.75 KB
/
lighthouse.yml
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: LightHouse CI
on:
pull_request:
branches:
- main
- release
jobs:
lhci:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'
- name: Install packages
run: yarn install && yarn global add @lhci/[email protected]
- name: Set .env
run: echo "${{ vars.DEVELOPMENT_ENV }}" > .env.local
- name: Build
run: yarn build
- name: Run Lighthouse CI
run: lhci autorun
env:
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
- name: Format lighthouse score
id: format_lighthouse_score
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
// 점수 지표 파일 정보
const fs = require('fs');
const results = JSON.parse(fs.readFileSync("./lhci_reports/manifest.json"));
const totalReports = results.length;
// LightHouse 점수 지표
const averageScores = {
performance: 0,
accessibility: 0,
'best-practices': 0,
seo: 0,
pwa: 0
};
const auditSummaries = {
'first-contentful-paint': 0,
'largest-contentful-paint': 0,
'interactive': 0,
'total-blocking-time': 0,
'cumulative-layout-shift': 0
};
// 점수 평균
results.forEach(result => {
const { summary } = result;
for (const key in averageScores) {
averageScores[key] += summary[key];
};
const details = JSON.parse(fs.readFileSync(result.jsonPath));
['first-contentful-paint', 'largest-contentful-paint', 'interactive', 'total-blocking-time', 'cumulative-layout-shift'].forEach(auditName => {
if (details.audits[auditName]) {
const auditDetails = details.audits[auditName];
auditSummaries[auditName] += parseFloat(auditDetails.displayValue) || 0;
}
});
});
// 점수에 따른 색상 표시
const formatScore = res => (res >= 90 ? "🟢" : res >= 70 ? "🟠" : "🔴");
// 상세 지표의 표준 점수에 따른 색상 표시
const detailScore = (value, metric) => {
switch (metric) {
case 'first-contentful-paint':
return value <= 1.8 ? "🟢" : value <= 3 ? "🟠" : "🔴";
case 'largest-contentful-paint':
return value <= 2.5 ? "🟢" : value <= 4 ? "🟠" : "🔴";
case 'interactive':
return value <= 3.8 ? "🟢" : value <= 7.3 ? "🟠" : "🔴";
case 'total-blocking-time':
return value <= 300 ? "🟢" : value <= 600 ? "🟠" : "🔴";
case 'cumulative-layout-shift':
return value <= 0.1 ? "🟢" : value <= 0.25 ? "🟠" : "🔴";
default:
return "🔴"; // Default to red if metric is unknown
}
};
// comments 업데이트
let comments = "⚡️ Lighthouse Average Scores Across Reports:\n| Category | Score |\n| --- | --- |\n";
Object.keys(averageScores).forEach(key => {
const avgScore = Math.round((averageScores[key] / totalReports) * 100);
comments += `| ${formatScore(avgScore)} ${key.replace(/-/g, ' ')} | ${avgScore} |\n`;
});
comments += "\n⚡️ Average Details Across All Reports:\n| Category | Score |\n| --- | --- |\n";
Object.keys(auditSummaries).forEach(auditName => {
const average = auditSummaries[auditName] / totalReports;
const formattedName = auditName.replace(/-/g, ' ');
const colorCode = detailScore(average, auditName);
const unit = (auditName === 'total-blocking-time' ? 'ms' : auditName === 'cumulative-layout-shift' ? '' : 's');
comments += `| ${colorCode} ${formattedName} | ${average.toFixed(1)}${unit} |\n`;
});
if (comments && context.issue.number) {
const issue_number = context.issue.number;
const repo = context.repo.repo;
const owner = context.repo.owner;
github.issues.createComment({
owner,
repo,
issue_number,
body: comments,
});
} else {
console.log('No PR COMMENT!');
}