-
Notifications
You must be signed in to change notification settings - Fork 1
164 lines (141 loc) · 6.02 KB
/
main.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
name: Lighthouse CI
on:
pull_request:
jobs:
lighthouse:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
- run: echo "💡 The ${{ github.repository }} repository (${{ github.ref }} branch) has been cloned to the runner (${{ runner.os }}), triggeded by a ${{ github.event_name }} event."
- name: Add comment to PR
id: loading_lighthouse_comment_to_pr
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ github.event.pull_request.number }}
header: lighthouse
message: |
🚦 Running Lighthouse audit...
- name: Add comment to PR
id: loading_budget_comment_to_pr
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ github.event.pull_request.number }}
header: budget
message: |
⏱ Running budget checks...
- name: Wait for the Netlify deploy preview to be ready
id: wait_for_netlify
uses: jakepartusch/[email protected]
with:
site_name: annaburd
max_timeout: 180
- name: Audit URLs using Lighthouse
id: lighthouse_audit
uses: treosh/lighthouse-ci-action@v10
with:
urls: |
${{ steps.wait_for_netlify.outputs.url }}
${{ steps.wait_for_netlify.outputs.url }}en/work/real-estate-app
${{ steps.wait_for_netlify.outputs.url }}ru/work/translator-app
budgetPath: ".github/lighthouse/budget.json" # test performance budgets https://web.dev/articles/use-lighthouse-for-performance-budgets
uploadArtifacts: true # save results as an action artifacts
temporaryPublicStorage: true # upload lighthouse report to the temporary storage
runs: 2 # number of times to run Lighthouse
- name: Format lighthouse results
id: lighthouse_result
if: ${{ always() }}
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const links = ${{ steps.lighthouse_audit.outputs.links }};
const results = ${{ steps.lighthouse_audit.outputs.manifest }}.filter(result => result.isRepresentativeRun);
const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴';
const excludeKeysFromSummary = ["pwa"];
const resultSummaryKeys = (summary) =>
Object.keys(summary).filter((key) => !excludeKeysFromSummary.includes(key));
const toTitleCase = (str) => {
return str.replace(/\w\S*/g, function (txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
};
const tableHeader =
`| Preview URL and Report | ` +
resultSummaryKeys(results[0].summary)
.map((key) => ` ${key === "seo" ? key.toUpperCase() : toTitleCase(key)} |`)
.join("");
const tableDivider =
`| --- | ` +
resultSummaryKeys(results[0].summary)
.map(() => ` --- |`)
.join("");
const tableRows = results
.map((result) => {
const url = result.url;
const summary = result.summary;
return `| 🌎 [${url.replace(
"${{ steps.wait_for_netlify.outputs.url }}",
"/",
)}](${url}) <br /> ⚡️ [Lighthouse report](${
links[url]
}) | ${resultSummaryKeys(summary)
.map((key) => {
const percentage = Math.round(summary[key] * 100);
return ` ${score(percentage)} ${percentage} `;
})
.join("|")} |`;
})
.join("\n");
let output = '**Lighthouse Performance Results**\n\n';
output += tableHeader + '\n';
output += tableDivider + '\n';
output += tableRows + '\n';
core.setOutput("comment", output);
- name: Format budget result
id: budget_result
if: ${{ always() }}
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const assertions = ${{ steps.lighthouse_audit.outputs.assertionResults }};
if (!assertions.length) {
core.setOutput("comment", '✅ Budget met, nothing to see here');
} else {
const comment = assertions.map((result) => {
return `
❌ **${result.auditProperty || ''}.${result.auditId}** failure on [${result.url}](${result.url})
*${result.auditTitle}* - [docs](${result.auditDocumentationLink})
| Actual | Expected |
| --- | --- |
| ${result.actual} | ${result.operator} ${result.expected} |
`;
}).join('---');
core.setOutput("comment", comment);
}
- name: Add Lighthouse results comment to PR
id: lighthouse_comment_to_pr
if: ${{ always() }}
uses: marocchino/sticky-pull-request-comment@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ github.event.pull_request.number }}
header: lighthouse
message: |
${{ steps.lighthouse_result.outputs.comment }}
- name: Add Budget results comment to PR
id: budget_comment_to_pr
if: ${{ always() }}
uses: marocchino/sticky-pull-request-comment@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ github.event.pull_request.number }}
header: budget
message: |
${{ steps.budget_result.outputs.comment }}