@@ -51,33 +51,43 @@ jobs:
51
51
const manifests = ${{ steps.lighthouse_audit.outputs.manifest }};
52
52
const links = ${{ steps.lighthouse_audit.outputs.links }};
53
53
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);
58
57
console.log('Manifests:', JSON.stringify(manifests, null, 2));
59
-
58
+
60
59
let comment = [
61
60
'| Page | Performance | Accessibility | Best practices | SEO | PWA |',
62
61
'| --- | --- | --- | --- | --- | --- |',
63
62
];
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
+ }
74
84
});
75
-
85
+
76
86
comment.push(
77
87
' ',
78
88
'*Lighthouse scores are calculated based on the latest audit results*'
79
89
);
80
-
90
+
81
91
comment = comment.join('\n');
82
92
core.setOutput("comment", comment);
83
93
- name : Find current PR # Find the PR associated with this push, if there is one.
0 commit comments