-
Notifications
You must be signed in to change notification settings - Fork 1
107 lines (100 loc) · 3.97 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: Run lighthouse CI
on:
pull_request:
branches: [main]
jobs:
Lighthouse-CI:
name: Lighthouse CI
runs-on: ubuntu-latest
strategy:
matrix:
node: [16.x]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- name: Dependency Install
uses: ./.github/actions/yarn-install
- name: Build
run: |
yarn build
- name: Run Lighthouse CI
env:
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
run: |
npm install -g @lhci/cli
lhci autorun || echo "Fail to Run Lighthouse CI!"
- name: Format lighthouse score
id: format_lighthouse_score
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const results = JSON.parse(fs.readFileSync("./lhci_reports/manifest.json"));
const tries = 3;
const triesArr = Array.from({ length: tries }, (_, idx) => idx + 1);
let comments = "JJINN Lighthouse 성능 측정 결과 🤾♀️" + "\n\n";
results.forEach((result, i) => {
const { summary, jsonPath } = result;
const details = JSON.parse(fs.readFileSync(jsonPath));
const { audits } = details;
const formatResult = (res) => Math.round(res * 100);
Object.keys(summary).forEach(
(key) => (summary[key] = formatResult(summary[key]))
);
const score = (res) => (res >= 90 ? "🟢" : res >= 50 ? "🟠" : "🔴");
const comment = [
`try ${triesArr[i]}`,
`| Category | Score |`,
`| --- | --- |`,
`| ${score(summary.performance)} Performance | ${summary.performance} |`,
`| ${score(summary.accessibility)} Accessibility | ${summary.accessibility} |`,
`| ${score(summary["best-practices"])} Best-Practices | ${summary["best-practices"]} |`,
`| ${score(summary.seo)} SEO | ${summary.seo} |`,
`| ${score(summary.pwa)} PWA | ${summary.pwa} |`
].join("\n");
const detail = [
`| Category | Score |`,
`| --- | --- |`,
`| ${score(
audits["first-contentful-paint"].score * 100
)} First Contentful Paint | ${
audits["first-contentful-paint"].displayValue
} |`,
`| ${score(
audits["largest-contentful-paint"].score * 100
)} Largest Contentful Paint | ${
audits["largest-contentful-paint"].displayValue
} |`,
`| ${score(
audits["first-meaningful-paint"].score * 100
)} First Meaningful Paint | ${
audits["first-meaningful-paint"].displayValue
} |`,
`| ${score(
audits["speed-index"].score * 100
)} Speed Index | ${
audits["speed-index"].displayValue
} |`,
`| ${score(
audits["total-blocking-time"].score * 100
)} Total Blocking Time | ${
audits["total-blocking-time"].displayValue
} |`,
].join("\n");
comments += comment + "\n" +"\n"+ detail + "\n" + "\n";
});
core.setOutput('comments', comments)
- uses: jwalton/gh-find-current-pr@v1
id: finder
- uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ steps.finder.outputs.pr }}
message: |
${{ github.sha }}
Lighthouse CI ended successfully.
${{ steps.format_lighthouse_score.outputs.comments}}