Skip to content

Commit 0f274ef

Browse files
authored
Merge pull request #12772 from ethereum/testlighthouseci
Add Lighthouse CI Action
2 parents f901f9a + ee4b63e commit 0f274ef

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

.github/workflows/lighthouse-ci.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Lighthouse CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- staging
8+
- performance/**
9+
10+
jobs:
11+
lighthouse:
12+
runs-on: ubuntu-latest
13+
14+
permissions:
15+
pull-requests: write
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Sleep for 60 minutes
20+
run: sleep 3600
21+
- name: Wait for Netlify Deploy
22+
id: netlify_deploy
23+
uses: probablyup/[email protected]
24+
with:
25+
site_id: "e8f2e766-888b-4954-8500-1b647d84db99"
26+
max_timeout: 900
27+
env:
28+
NETLIFY_TOKEN: ${{ secrets.NETLIFY_TOKEN }}
29+
- name: Audit URLs using Lighthouse
30+
id: lighthouse_audit
31+
uses: treosh/lighthouse-ci-action@v11
32+
with:
33+
urls: |
34+
${{ steps.netlify_deploy.outputs.url }}/en/
35+
${{ steps.netlify_deploy.outputs.url }}/en/wallets/find-wallet/
36+
${{ steps.netlify_deploy.outputs.url }}/en/staking/
37+
${{ steps.netlify_deploy.outputs.url }}/en/whitepaper/
38+
${{ steps.netlify_deploy.outputs.url }}/en/nft/
39+
${{ steps.netlify_deploy.outputs.url }}/en/developers/docs/intro-to-ethereum/
40+
${{ steps.netlify_deploy.outputs.url }}/en/developers/tutorials/creating-a-wagmi-ui-for-your-contract/
41+
runs: 3 # run three times
42+
uploadArtifacts: true # save results as an action artifacts
43+
temporaryPublicStorage: true # upload lighthouse report to the temporary storage
44+
- name: Format lighthouse score
45+
id: format_lighthouse_score
46+
uses: actions/github-script@v3
47+
with:
48+
github-token: ${{ secrets.GITHUB_TOKEN }}
49+
script: |
50+
const manifests = ${{ steps.lighthouse_audit.outputs.manifest }};
51+
const links = ${{ steps.lighthouse_audit.outputs.links }};
52+
const formatResult = (res) => Math.round((res * 100));
53+
54+
console.log('Total manifests:', manifests.length);
55+
console.log('Manifests:', JSON.stringify(manifests, null, 2));
56+
console.log('Links:', JSON.stringify(links, null, 2));
57+
58+
let comment = [
59+
'| Page | Performance | Accessibility | Best practices | SEO | PWA |',
60+
'| --- | --- | --- | --- | --- | --- |',
61+
];
62+
63+
Object.entries(links).forEach(([pageUrl, reportUrl]) => {
64+
const relevantManifests = manifests.filter(manifest => manifest.url === pageUrl);
65+
const results = relevantManifests.map(manifest => manifest.summary);
66+
const averagedResults = {};
67+
68+
if (results.length > 0) {
69+
Object.keys(results[0]).forEach(key => {
70+
averagedResults[key] = formatResult(
71+
results.reduce((acc, cur) => acc + cur[key], 0) / results.length
72+
);
73+
});
74+
75+
const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴';
76+
const urlForTable = pageUrl.includes('/en/') ? pageUrl.substring(pageUrl.indexOf('/en/')) : pageUrl;
77+
78+
comment.push(
79+
`| [${urlForTable}](${reportUrl}) | ${score(averagedResults.performance)} ${averagedResults.performance} | ${score(averagedResults.accessibility)} ${averagedResults.accessibility} | ${score(averagedResults['best-practices'])} ${averagedResults['best-practices']} | ${score(averagedResults.seo)} ${averagedResults.seo} | ${score(averagedResults.pwa)} ${averagedResults.pwa} |`
80+
);
81+
} else {
82+
console.error('No results found for URL:', pageUrl);
83+
}
84+
});
85+
86+
comment.push(
87+
' ',
88+
'*Lighthouse scores are calculated based on the latest audit results*'
89+
);
90+
91+
comment = comment.join('\n');
92+
core.setOutput("comment", comment);
93+
- name: Find current PR # Find the PR associated with this push, if there is one.
94+
uses: jwalton/[email protected]
95+
id: findPr
96+
with:
97+
state: open
98+
- name: Add Lighthouse stats as comment
99+
id: comment_to_pr
100+
uses: marocchino/[email protected]
101+
with:
102+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
103+
number: ${{ steps.findPr.outputs.number }}
104+
header: lighthouse
105+
message: ${{ steps.format_lighthouse_score.outputs.comment }}

0 commit comments

Comments
 (0)