-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (130 loc) · 5.04 KB
/
lighthouse.yml
File metadata and controls
162 lines (130 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# .github/workflows/lighthouse.yml
#
# Copyright © 2025 Network Pro Strategies (Network Pro™)
# SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
# This file is part of Network Pro
name: Lighthouse Audit
on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:
# cspell:ignore tostring
# Sets permissions of the GITHUB_TOKEN to allow read access to repo and write
# permission for PRs for comment summary
permissions:
contents: read
pull-requests: write
jobs:
audit:
name: Run Lighthouse CI
runs-on: ubuntu-24.04
env:
ENV_MODE: ci
timeout-minutes: 10
steps:
- name: Checkout Repository
uses: actions/checkout@v6
- name: Authenticate GitHub CLI
run: gh auth status
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Log ENV_MODE
run: 'echo "ENV_MODE is set to: $ENV_MODE"'
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
cache-dependency-path: package-lock.json
- name: Upgrade npm
run: |
corepack enable
npm install -g npm@11.7.0
- name: Clean previous Lighthouse reports
run: |
if [ -d ".lighthouseci" ]; then
COUNT=$(find .lighthouseci -type f | wc -l)
echo "🧹 Removing $COUNT file(s) from .lighthouseci/"
rm -rf .lighthouseci
else
echo "🧹 No previous .lighthouseci/ directory to clean."
fi
- name: Install Dependencies
run: npm ci
- name: Build Site
run: npm run build
- name: Install Google Chrome
run: |
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install -y ./google-chrome-stable_current_amd64.deb
- name: Record Chrome version and timestamp
run: |
mkdir -p .lighthouseci
{
echo "Chrome Version: $(google-chrome --version)"
echo "Audit Timestamp: $(date -u +'%Y-%m-%dT%H:%M:%SZ')"
} > .lighthouseci/chrome-version.txt
- name: Collect Lighthouse results
run: |
npx @lhci/cli collect \
--chrome-path="$(which google-chrome)" \
--config=.lighthouserc.cjs
- name: Log Chrome version used
run: cat .lighthouseci/chrome-version.txt
- name: Check for budget.json
run: |
if [ ! -f budget.json ]; then
echo "❌ ERROR: budget.json not found. LHCI budget assertions will be skipped."
exit 1
else
echo "✅ Found budget.json"
fi
- name: Assert Lighthouse results (non-blocking)
run: npx @lhci/cli assert --config=.lighthouserc.cjs
continue-on-error: true
- name: Annotate and Comment on Lighthouse Budget Failures
if: always()
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
REPORT=$(ls -t .lighthouseci/*.report.json .lighthouseci/lhr-*.json 2>/dev/null | head -n 1)
if [ -z "$REPORT" ]; then
echo "::warning ::No valid Lighthouse report found for annotation step."
exit 0
fi
echo "🔍 Parsing $REPORT for failing audits..."
if ! jq -e '.audits' "$REPORT" > /dev/null; then
echo "::warning ::The selected report is not a valid Lighthouse output (missing .audits key)."
exit 0
fi
FAILURES=$(jq -r '.audits | to_entries[] | select(.value.score < 1 and .value.score != null) | [.key, .value.title, (.value.score | tostring)] | @tsv' "$REPORT")
if [ -z "$FAILURES" ]; then
echo "✅ No failing audits found. Lighthouse budgets passed."
exit 0
fi
echo "⚠️ Failing Lighthouse audits:"
COMMENT_BODY="### ⚠️ Lighthouse Budget Issues Detected"
while IFS=$'\t' read -r key title score; do
echo "::warning file=.lighthouseci/report.json,line=1,title=Lighthouse Budget Issue::$title (score: $score)"
COMMENT_BODY="${COMMENT_BODY}"$'\n'"- ${title} (score: ${score})"
done <<< "$FAILURES"
COMMENT_BODY="${COMMENT_BODY}"$'\n\n'"View the full report in the workflow artifacts or in \`.lighthouseci/report.html\`."
if [ "${{ github.event_name }}" = "pull_request" ]; then
gh pr comment ${{ github.event.pull_request.number }} --body "$COMMENT_BODY" || echo "::warning ::Failed to post PR comment"
else
echo "Not a PR — skipping GitHub comment post."
fi
- name: Upload Lighthouse results
run: npx @lhci/cli upload --config=.lighthouserc.cjs
- name: List contents of .lighthouseci
run: ls -al .lighthouseci
- name: Upload full .lighthouseci output
uses: actions/upload-artifact@v4
with:
name: lighthouse-reports
path: .lighthouseci/
include-hidden-files: true
if-no-files-found: error