Skip to content

Commit 0d3e739

Browse files
rlespinasseclaude
andcommitted
ci: add detailed failing audits and HTML reports to Lighthouse CI
- Output both JSON and HTML from Lighthouse runs - Extract failing audits per category into the PR comment using collapsible details blocks - Upload HTML reports as build artifacts (14-day retention) - Link to artifacts from the comment template Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e0a7ce4 commit 0d3e739

3 files changed

Lines changed: 36 additions & 7 deletions

File tree

.github/comment-templates/lighthouse-report.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
{{results}}
88

99
All categories must score 90 or higher.
10+
11+
Full HTML reports are available as [build artifacts](../actions).

.github/workflows/lighthouse.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ jobs:
2828
id: lighthouse
2929
run: just lighthouse
3030

31+
- name: Upload Lighthouse HTML reports
32+
if: always()
33+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
34+
with:
35+
name: lighthouse-reports
36+
path: /tmp/lighthouse-*.report.html
37+
retention-days: 14
38+
3139
- name: Load results for PR comment
3240
if: always() && github.event_name == 'pull_request'
3341
run: |

justfile

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,23 +209,42 @@ lighthouse: build
209209
url="http://localhost:{{ port }}${page}"
210210
echo "Testing $url..."
211211
212+
base_path="/tmp/lighthouse-${page//\//-}"
212213
npx lighthouse "$url" \
213214
--chrome-flags="--headless=new --no-sandbox" \
214-
--output=json \
215-
--output-path=/tmp/lighthouse-${page//\//-}.json \
215+
--output=json,html \
216+
--output-path="$base_path" \
216217
--disable-full-page-screenshot \
217218
--throttling-method=devtools \
218219
> /dev/null 2>&1 || true
219220
220-
if [ -f "/tmp/lighthouse-${page//\//-}.json" ]; then
221-
perf=$(jq '.categories.performance.score * 100' "/tmp/lighthouse-${page//\//-}.json")
222-
access=$(jq '.categories.accessibility.score * 100' "/tmp/lighthouse-${page//\//-}.json")
223-
bp=$(jq '.categories."best-practices".score * 100' "/tmp/lighthouse-${page//\//-}.json")
224-
seo=$(jq '.categories.seo.score * 100' "/tmp/lighthouse-${page//\//-}.json")
221+
json_file="${base_path}.report.json"
222+
if [ -f "$json_file" ]; then
223+
perf=$(jq '.categories.performance.score * 100' "$json_file")
224+
access=$(jq '.categories.accessibility.score * 100' "$json_file")
225+
bp=$(jq '.categories."best-practices".score * 100' "$json_file")
226+
seo=$(jq '.categories.seo.score * 100' "$json_file")
225227
226228
printf "Page: %-20s | Perf: %3.0f | A11y: %3.0f | BP: %3.0f | SEO: %3.0f\n" "$page" "$perf" "$access" "$bp" "$seo"
227229
results_md+=$'\n'"- **$page**: Performance $perf, Accessibility $access, Best Practices $bp, SEO $seo"
228230
231+
# Extract failing audits for categories below 90
232+
failing_audits=$(jq -r '
233+
.audits as $audits |
234+
.categories | to_entries[] | select(.value.score < 0.9) |
235+
.key as $cat |
236+
[.value.auditRefs[].id |
237+
$audits[.] |
238+
select(.score != null and .score < 0.9) |
239+
" - " + .title + " (" + (.score * 100 | floor | tostring) + ")"] |
240+
select(length > 0) |
241+
" - **" + $cat + "**:\n" + join("\n")
242+
' "$json_file" 2>/dev/null || true)
243+
244+
if [ -n "$failing_audits" ]; then
245+
results_md+=$'\n'" <details><summary>Failing audits</summary>"$'\n'$'\n'"$failing_audits"$'\n'" </details>"
246+
fi
247+
229248
for score in "$perf" "$access" "$bp"; do
230249
if (( $(echo "$score < 90" | bc -l) )); then
231250
all_passed=false

0 commit comments

Comments
 (0)