1
+ name : Lighthouse CI
2
+
3
+ on :
4
+ push :
5
+ branches :
6
+ - main
7
+ workflow_dispatch :
8
+ inputs :
9
+ url :
10
+ description : ' URL to run Lighthouse on'
11
+ required : false
12
+ default : ' http://localhost:8080'
13
+
14
+ jobs :
15
+ lhci :
16
+ name : Lighthouse
17
+ runs-on : ubuntu-latest
18
+ steps :
19
+ - uses : actions/checkout@v4
20
+ - name : Use Node.js 20
21
+ uses : actions/setup-node@v4
22
+ with :
23
+ node-version : 20
24
+ - name : Install dependencies
25
+ run : |
26
+ npm install -g @lhci/[email protected]
27
+ npm install -g http-server
28
+ - name : Start local server
29
+ run : http-server . -p 8080 &
30
+ - name : Run Lighthouse CI
31
+ run : |
32
+ URL="${{ github.event.inputs.url || 'http://localhost:8080' }}"
33
+ lhci autorun --collect.url=$URL
34
+ - name : Format and Log Lighthouse score
35
+ run : |
36
+ echo "Lighthouse 성능 측정 결과"
37
+ if [ -f .lighthouseci/links.json ]; then
38
+ LATEST_JSON=$(ls -t .lighthouseci/lhr-*.json | head -n1)
39
+ if [ -n "$LATEST_JSON" ]; then
40
+ jq -r '.categories | to_entries[] | "\(.key): \(.value.score * 100 | floor)"' "$LATEST_JSON" | while read line; do
41
+ key=$(echo "$line" | cut -d':' -f1)
42
+ score=$(echo "$line" | cut -d':' -f2)
43
+ if (( $(echo "$score >= 90" | bc -l) )); then
44
+ emoji="🟢"
45
+ elif (( $(echo "$score >= 50" | bc -l) )); then
46
+ emoji="🟠"
47
+ else
48
+ emoji="🔴"
49
+ fi
50
+ echo "$key: $emoji $score"
51
+ done
52
+
53
+ # Try to extract report URL from links.json
54
+ REPORT_URL=$(jq -r '.html' .lighthouseci/links.json)
55
+
56
+ # If the above fails, try to construct the URL from the JSON filename
57
+ if [ "$REPORT_URL" = "null" ] || [ -z "$REPORT_URL" ]; then
58
+ JSON_FILENAME=$(basename $LATEST_JSON)
59
+ HTML_FILENAME="${JSON_FILENAME%.json}.html"
60
+ REPORT_URL="https://storage.googleapis.com/lighthouse-infrastructure.appspot.com/reports/$HTML_FILENAME"
61
+ fi
62
+
63
+ echo "Lighthouse 보고서 전체 보기: $REPORT_URL"
64
+ else
65
+ echo "No JSON report file found in .lighthouseci directory"
66
+ fi
67
+ else
68
+ echo "links.json not found. Unable to process Lighthouse results."
69
+ fi
0 commit comments