Skip to content

Commit e236244

Browse files
authored
account for async lighthouse
1 parent da09fae commit e236244

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

.github/workflows/lighthouse-ci.yml

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,33 +51,43 @@ jobs:
5151
const manifests = ${{ steps.lighthouse_audit.outputs.manifest }};
5252
const links = ${{ steps.lighthouse_audit.outputs.links }};
5353
const formatResult = (res) => Math.round((res * 100));
54-
55-
56-
console.log('Total manifests', manifests.length);
57-
console.log('Total links', links.length);
54+
55+
console.log('Total manifests:', manifests.length);
56+
console.log('Total links:', links.length);
5857
console.log('Manifests:', JSON.stringify(manifests, null, 2));
59-
58+
6059
let comment = [
6160
'| Page | Performance | Accessibility | Best practices | SEO | PWA |',
6261
'| --- | --- | --- | --- | --- | --- |',
6362
];
64-
65-
// Assuming links and manifests are aligned in order
66-
links.forEach((link, index) => {
67-
const result = manifests[index].summary;
68-
Object.keys(result).forEach(key => result[key] = formatResult(result[key]));
69-
const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴';
70-
71-
comment.push(
72-
`| [Link](${link}) | ${score(result.performance)} ${result.performance} | ${score(result.accessibility)} ${result.accessibility} | ${score(result['best-practices'])} ${result['best-practices']} | ${score(result.seo)} ${result.seo} | ${score(result.pwa)} ${result.pwa} |`
73-
);
63+
64+
links.forEach(link => {
65+
const relevantManifests = manifests.filter(manifest => manifest.url === link);
66+
const results = relevantManifests.map(manifest => manifest.summary);
67+
const averagedResults = {};
68+
69+
if (results.length > 0) {
70+
Object.keys(results[0]).forEach(key => {
71+
averagedResults[key] = formatResult(
72+
results.reduce((acc, cur) => acc + cur[key], 0) / results.length
73+
);
74+
});
75+
76+
const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴';
77+
78+
comment.push(
79+
`| [Link](${link}) | ${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:', link);
83+
}
7484
});
75-
85+
7686
comment.push(
7787
' ',
7888
'*Lighthouse scores are calculated based on the latest audit results*'
7989
);
80-
90+
8191
comment = comment.join('\n');
8292
core.setOutput("comment", comment);
8393
- name: Find current PR # Find the PR associated with this push, if there is one.

0 commit comments

Comments
 (0)