From b9630c69f86eedf45484ba6485fc1c0814a0def9 Mon Sep 17 00:00:00 2001 From: Pauljd Date: Sat, 12 Sep 2026 20:13:44 +0100 Subject: [PATCH] Extract Lighthouse findings --- modules/lighthouse.sh | 4 +++ scripts/parse-lighthouse.php | 53 +++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/modules/lighthouse.sh b/modules/lighthouse.sh index 3440b0c..7218265 100755 --- a/modules/lighthouse.sh +++ b/modules/lighthouse.sh @@ -133,4 +133,8 @@ php .davidson-ci/scripts/parse-lighthouse.php \ echo echo "Parsed report: .davidson-reports/davidson-lighthouse.json" +echo +echo "Davidson Lighthouse summary:" +cat .davidson-reports/davidson-lighthouse.json + set_status "PASS" \ No newline at end of file diff --git a/scripts/parse-lighthouse.php b/scripts/parse-lighthouse.php index fb43c3f..540f097 100644 --- a/scripts/parse-lighthouse.php +++ b/scripts/parse-lighthouse.php @@ -55,6 +55,22 @@ $categoryIds = [ $scores = []; +$auditCategories = []; + +foreach ($categoryIds as $categoryId) { + $auditRefs = $data['categories'][$categoryId]['auditRefs'] ?? []; + + foreach ($auditRefs as $auditRef) { + $auditId = $auditRef['id'] ?? null; + + if ($auditId === null) { + continue; + } + + $auditCategories[$auditId][] = $categoryId; + } +} + foreach ($categoryIds as $categoryId) { $rawScore = $data['categories'][$categoryId]['score'] ?? null; @@ -72,10 +88,45 @@ foreach ($categoryIds as $categoryId) { ]; } +$findings = []; + +$skipModes = [ + 'notApplicable', + 'informative', + 'manual', + 'error', +]; + +foreach ($data['audits'] ?? [] as $auditId => $audit) { + $score = $audit['score'] ?? null; + $scoreDisplayMode = $audit['scoreDisplayMode'] ?? null; + + if ($score === null) { + continue; + } + + if (in_array($scoreDisplayMode, $skipModes, true)) { + continue; + } + + if (!is_numeric($score) || $score >= 1) { + continue; + } + + $findings[] = [ + 'id' => $auditId, + 'categories' => $auditCategories[$auditId] ?? [], + 'title' => $audit['title'] ?? $auditId, + 'problem' => $audit['description'] ?? '', + 'impact' => $audit['displayValue'] ?? null, + 'score' => (int) round($score * 100), + ]; +} + $output = [ 'schemaVersion' => 1, 'scores' => $scores, - 'findings' => [], + 'findings' => $findings, ]; $outputJson = json_encode(