forked from boostcampwm-2022/web01-knoticle
-
Notifications
You must be signed in to change notification settings - Fork 1
122 lines (97 loc) · 3.53 KB
/
frontend-ci.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Frontend CI
on:
pull_request:
branches: [main, develop]
paths:
- 'frontend/**'
jobs:
lint:
name: Lint CI
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Cache Dependencies
uses: actions/cache@v3
id: frontend-cache
with:
path: frontend/node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-build-
${{ runner.OS }}-
- if: ${{ steps.frontend-cache.outputs.cache-hit != 'true' }}
name: Install Dependencies
run: npm install
working-directory: frontend
- name: Check Lint
run: npm run lint
env:
CI: true
working-directory: frontend
lighthouse:
name: Lighthouse CI
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Cache Dependencies
uses: actions/cache@v3
id: frontend-cache
with:
path: frontend/node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-build-
${{ runner.OS }}-
- if: ${{ steps.frontend-cache.outputs.cache-hit != 'true' }}
name: Install Dependencies
run: npm install
working-directory: frontend
- name: Build
run: npm run build
working-directory: frontend
- name: Run Lighthouse CI
env:
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
run: |
npm install -g @lhci/cli
lhci autorun
working-directory: frontend
- 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('frontend/lighthouse_reports/manifest.json'));
const summaryTotal = {};
results.forEach((result) => {
const { summary } = result;
const formatResult = (res) => Math.round(res * 100);
Object.keys(summary).forEach((key) => {
if (key in summaryTotal) summaryTotal[key] += formatResult(summary[key]);
else summaryTotal[key] = formatResult(summary[key]);
});
});
Object.keys(summaryTotal).forEach((key) => {
summaryTotal[key] = Math.round(summaryTotal[key] / results.length);
});
const score = (res) => (res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴');
const comment = [
`⚡️ Lighthouse report!`,
`| Category | Score |`,
`| --- | --- |`,
`| ${score(summaryTotal.performance)} Performance | ${summaryTotal.performance} |`,
`| ${score(summaryTotal.accessibility)} Accessibility | ${summaryTotal.accessibility} |`,
`| ${score(summaryTotal['best-practices'])} Best Practices | ${summaryTotal['best-practices']} |`,
`| ${score(summaryTotal.seo)} SEO | ${summaryTotal.seo} |`,
].join('\n');
core.setOutput('comment', comment)
- name: Comment Lighthouse Report
uses: unsplash/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
msg: ${{ steps.format_lighthouse_score.outputs.comment}}