-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
130 lines (121 loc) · 3.23 KB
/
index.js
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
const { axios } = require('axios');
const chromeLauncher = require('chrome-launcher');
const core = require('@actions/core');
const config = require('./config/lighthouserc.js');
const fs = require('fs');
const lighthouse = require('lighthouse');
function status(category) {
let color = ''
if (category > 89)
color="#339900"
else if (category <= 89 && category >= 49)
color="#f2c744"
else if (category < 49 )
color="#cc3300"
return color
}
const dir = './report-lhci';
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
(async () => {
const chrome = await chromeLauncher.launch({chromeFlags: ['--headless']});
const runnerResult = await lighthouse(core.getInput('URL') , config);
// `.report` is the HTML report as a string
const reportHtml = runnerResult.report;
fs.writeFileSync('report-lhci/lhreport.html', reportHtml, 'utf-8');
// kill chrome
await chrome.kill();
const performance = runnerResult.lhr.categories.performance.score * 100
const accessibility = runnerResult.lhr.categories.accessibility.score * 100
const bestPractices = runnerResult.lhr.categories['best-practices'].score * 100
const seo = runnerResult.lhr.categories.seo.score * 100
const pwa = runnerResult.lhr.categories.pwa.score * 100
const performance_color = status(performance)
const accessibility_color = status(accessibility)
const bestPractice_color = status(bestPractices)
const seo_color = status(seo)
const pwa_color = status(pwa)
// Send webhook
try {
axios.post(core.getInput('SLACK_WEBHOOK_URL'), {
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Rapport LightHouse.\n*URL:*"+core.getInput('URL')
}
},
{
"type": "divider"
}
],
"attachments": [
{
"color": performance_color,
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Performance:*"+performance
}
}
]
},
{
"color": accessibility_color,
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Accessibilité:*"+accessibility
}
}
]
},
{
"color": bestPractice_color,
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Bonnes pratiques:*"+bestPractices
}
}
]
},
{
"color": seo_color,
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*SEO:*"+seo
}
}
]
},
{
"color": pwa_color,
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*PWA:*"+pwa
}
}
]
}
]
})
}
catch (error) {
core.setFailed(error.message)
}
})();