From 657efe9a5ef2ed83f1b763cfe584cc7f32645408 Mon Sep 17 00:00:00 2001 From: Pauljd Date: Sat, 12 Sep 2026 17:10:16 +0100 Subject: [PATCH] Parse Lighthouse results into Davidson report --- modules/lighthouse.sh | 8 +++ scripts/parse-lighthouse.php | 103 +++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 scripts/parse-lighthouse.php diff --git a/modules/lighthouse.sh b/modules/lighthouse.sh index 3a35f0d..3440b0c 100755 --- a/modules/lighthouse.sh +++ b/modules/lighthouse.sh @@ -124,5 +124,13 @@ fi echo echo "Lighthouse completed successfully." echo "Raw report: $RAW_REPORT" +echo "Parsing Lighthouse report..." + +php .davidson-ci/scripts/parse-lighthouse.php \ + "$RAW_REPORT" \ + ".davidson-reports/davidson-lighthouse.json" + +echo +echo "Parsed report: .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 new file mode 100644 index 0000000..fb43c3f --- /dev/null +++ b/scripts/parse-lighthouse.php @@ -0,0 +1,103 @@ += 90) { + return [ + 'status' => 'Good', + 'class' => 'good', + ]; + } + + if ($score >= 50) { + return [ + 'status' => 'Fix', + 'class' => 'fix', + ]; + } + + return [ + 'status' => 'Issue', + 'class' => 'issue', + ]; +} + +$categoryIds = [ + 'performance', + 'accessibility', + 'best-practices', + 'seo', +]; + +$scores = []; + +foreach ($categoryIds as $categoryId) { + $rawScore = $data['categories'][$categoryId]['score'] ?? null; + + if (!is_numeric($rawScore)) { + continue; + } + + $score = (int) round($rawScore * 100); + $status = getScoreStatus($score); + + $scores[$categoryId] = [ + 'score' => $score, + 'status' => $status['status'], + 'class' => $status['class'], + ]; +} + +$output = [ + 'schemaVersion' => 1, + 'scores' => $scores, + 'findings' => [], +]; + +$outputJson = json_encode( + $output, + JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES +); + +if ($outputJson === false) { + fwrite(STDERR, "ERROR: Could not encode Davidson Lighthouse report.\n"); + exit(1); +} + +$outputDir = dirname($outputPath); + +if (!is_dir($outputDir)) { + mkdir($outputDir, 0777, true); +} + +if (file_put_contents($outputPath, $outputJson) === false) { + fwrite(STDERR, "ERROR: Could not write Davidson Lighthouse report.\n"); + exit(1); +} + +echo "Davidson Lighthouse report generated.\n"; +echo "Saved: $outputPath\n"; \ No newline at end of file