This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 185
194 lines (183 loc) · 9.39 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: Deriv Lighthouse Audit
permissions:
actions: write
checks: write
contents: write
deployments: write
pull-requests: write
statuses: write
on:
workflow_run:
workflows: ['Generate preview link']
types:
- completed
jobs:
generate_lighthouse_audit:
timeout-minutes: 30
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Download artifact
id: download-artifact
uses: dawidd6/action-download-artifact@v2
with:
workflow_conclusion: success
run_id: ${{ github.event.workflow_run.id }}
name: 'pr-${{ github.event.workflow_run.id }}'
path: pr
- name: Retrieve pull request
id: pr_information
run: |
echo "issue_number=$(cat ./pr/NR)" >> $GITHUB_OUTPUT
echo "preview_url=$(cat ./pr/PREVIEW_URL)" >> $GITHUB_OUTPUT
- name: Add comment to PR
id: loading_comment_to_pr
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ steps.pr_information.outputs.issue_number }}
header: lighthouse
message: |
Running Lighthouse audit...
- uses: actions/checkout@v3
- name: Audit preview URL with Lighthouse
id: lighthouse_audit
uses: treosh/lighthouse-ci-action@v9
with:
urls: |
${{ steps.pr_information.outputs.preview_url }}
uploadArtifacts: true
temporaryPublicStorage: true
runs: 5
- name: Format lighthouse score
id: format_lighthouse_score
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const result = ${{ steps.lighthouse_audit.outputs.manifest }}[4].summary
const links = ${{ steps.lighthouse_audit.outputs.links }}
const formatResult = (res) => Math.round((res * 100))
Object.keys(result).forEach(key => result[key] = formatResult(result[key]))
const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴'
const full_report = Object.values(links)[0]
const comment = [
`⚡️ [Lighthouse report](${full_report}) for the changes in this PR:`,
'| Category | Score |',
'| --- | --- |',
`| ${score(result.performance)} Performance | ${result.performance} |`,
`| ${score(result.accessibility)} Accessibility | ${result.accessibility} |`,
`| ${score(result['best-practices'])} Best practices | ${result['best-practices']} |`,
`| ${score(result.seo)} SEO | ${result.seo} |`,
`| ${score(result.pwa)} PWA | ${result.pwa} |`,
' ',
`*Lighthouse ran on [${Object.keys(links)[0]}](${Object.keys(links)[0]})*`
].join('\n')
core.setOutput("comment", comment);
core.setOutput("performance", result.performance);
core.setOutput("seo", result.seo);
core.setOutput("pwa", result.pwa);
core.setOutput("accessibility", result.accessibility);
core.setOutput("best_practices", result['best-practices']);
core.setOutput("performance_color", score(result.performance));
core.setOutput("seo_color", score(result.seo));
core.setOutput("pwa_color", score(result.pwa));
core.setOutput("accessibility_color", score(result.accessibility));
core.setOutput("best_practices_color", score(result['best-practices']));
core.setOutput("full_report", full_report);
- name: Add comment to PR
id: comment_to_pr
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ github.event.issue.number }}
header: lighthouse
message: |
${{ steps.format_lighthouse_score.outputs.comment }}
- name: Slack Notification 📣
uses: 8398a7/action-slack@v3
if: ${{ steps.format_lighthouse_score.outputs.performance < 0 }}
with:
status: custom
fields: workflow,job,commit,repo
custom_payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "plain_text",
"emoji": true,
"text": "It appears that this pull request has not met the required performance score."
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*${{ steps.format_lighthouse_score.outputs.performance_color }} PERFORMANCE:* ${{ steps.format_lighthouse_score.outputs.performance }}\n\n*${{ steps.format_lighthouse_score.outputs.accessibility_color }} ACCESSIBILITY:* ${{ steps.format_lighthouse_score.outputs.accessibility }}\n\n*${{ steps.format_lighthouse_score.outputs.best_practices_color }} BEST PRACTICES:* ${{ steps.format_lighthouse_score.outputs.best_practices }}\n\n*${{ steps.format_lighthouse_score.outputs.seo_color }} SEO:* ${{ steps.format_lighthouse_score.outputs.seo }} \n\n*${{ steps.format_lighthouse_score.outputs.pwa_color }} PWA:* ${{ steps.format_lighthouse_score.outputs.pwa }}"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*User: <${{ github.event.issue.user.url }}|${{ github.event.issue.user.login }}>*\n*Link:* ${{ github.event.issue.pull_request.html_url }}\n*Title:* ${{ github.event.issue.title }}\n*Status:* ${{ github.event.issue.state }}"
},
"accessory": {
"type": "image",
"image_url": "${{ github.event.issue.user.avatar_url }}",
"alt_text": "${{ github.event.issue.user.login }}"
}
},
{
"type": "divider"
},
{
"type": "context",
"elements": [
{
"type": "image",
"image_url": "https://api.slack.com/img/blocks/bkb_template_images/notificationsWarningIcon.png",
"alt_text": "notifications warning icon"
},
{
"type": "mrkdwn",
"text": "*<!subteam^S04RV6RFCTW> please check the PR*"
}
]
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Want the full lighthouse report?"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "View",
"emoji": true
},
"value": "click_me_123",
"url": "${{ steps.format_lighthouse_score.outputs.full_report }}",
"action_id": "button-action"
}
},
{
"type": "divider"
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_LIGHTHOUSE }}