-
Notifications
You must be signed in to change notification settings - Fork 4
90 lines (83 loc) · 3.01 KB
/
lighthouse.yml
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
name: Lighthouse
on:
pull_request:
branches:
- main
jobs:
audit:
name: Audit
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 1
- name: Comment pull request
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ github.event.pull_request.number }}
header: lighthouse
message: |
# Lighthouse Report
:vertical_traffic_light: Waiting for the Vercel preview ...
- name: Waiting for the Vercel preview
uses: patrickedqvist/[email protected]
id: vercel
with:
token: ${{ secrets.GITHUB_TOKEN }}
max_timeout: 1200
check_interval: 15
- name: Comment preview result
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ github.event.pull_request.number }}
header: lighthouse
message: |
# Lighthouse Report
:hammer_and_wrench: Running Lighthouse audit on ${{ steps.vercel.outputs.url }} ...
- name: Audit using Lighthouse
id: lighthouse
uses: treosh/lighthouse-ci-action@v12
with:
urls: |
${{ steps.vercel.outputs.url }}
${{ steps.vercel.outputs.url }}/posts
${{ steps.vercel.outputs.url }}/tags
${{ steps.vercel.outputs.url }}/books
${{ steps.vercel.outputs.url }}/about
configPath: ./.github/workflows/lighthouserc.json
uploadArtifacts: true
temporaryPublicStorage: true
- name: Format audit result
id: result
uses: actions/github-script@v7
with:
script: |
const links = ${{ steps.lighthouse.outputs.links }}
const results = (${{ steps.lighthouse.outputs.manifest }}).filter(result => result.isRepresentativeRun);
const score = res => res >= 90 ? ':green_circle:' : res >= 50 ? ':yellow_circle:' : ':red_circle:';
const comment = results.map((result) => {
const summary = result.summary;
const url = result.url;
return `
## :sparkles: ${url}
:rocket: [Vercel preview deployment](${url})
:zap: [Lighthouse report](${links[url]})
| Category | Score |
| --- | --- |
${Object.keys(summary).map((key) => {
const percentage = Math.round(summary[key] * 100);
return `| ${score(percentage)} ${key} | ${percentage} |`;
}).join('\n')}
`;
}).join('');
core.setOutput("comment", comment);
- name: Comment audit result
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ github.event.pull_request.number }}
header: lighthouse
message: |
# Lighthouse Report
${{ steps.result.outputs.comment }}