-
Notifications
You must be signed in to change notification settings - Fork 1
334 lines (292 loc) Β· 11.5 KB
/
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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
name: CI
on:
pull_request:
branches: [main]
push:
branches: [main]
env:
CACHED_DEPENDENCY_PATHS: ${{ github.workspace }}/node_modules
CACHED_BUILD_PATHS: ${{ github.workspace }}/.next
BUILD_CACHE_KEY: ${{ github.sha }}
DEFAULT_NODE_VERSION: '16'
jobs:
job_install_dependencies:
name: Install Dependencies
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v2
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: ${{ env.DEFAULT_NODE_VERSION }}
- name: Compute dependency cache key
id: compute_lockfile_hash
run: echo "::set-output name=hash::${{ hashFiles('yarn.lock') }}"
- name: Check dependency cache
uses: actions/cache@v3
id: cache_dependencies
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ steps.compute_lockfile_hash.outputs.hash }}
- name: Install dependencies
if: steps.cache_dependencies.outputs.cache-hit == ''
run: yarn install --ignore-engines --frozen-lockfile
outputs:
dependency_cache_key: ${{ steps.compute_lockfile_hash.outputs.hash }}
job_build:
name: Build
needs: [job_install_dependencies]
runs-on: ubuntu-latest
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v2
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: ${{ env.DEFAULT_NODE_VERSION }}
- name: Create env file
run: |
touch .env
echo NEXT_PUBLIC_FIREBASE_API_KEY = ${{ secrets.FIREBASE_API_KEY }} >> .env
echo NEXT_PUBLIC_FIREBASE_APP_ID = ${{ secrets.FIREBASE_APP_ID }} >> .env
echo NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN = ${{ secrets.FIREBASE_AUTH_DOMAIN }} >> .env
echo NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID = ${{ secrets.FIREBASE_MEASUREMENT_ID }} >> .env
echo NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID = ${{ secrets.FIREBASE_MESSAGING_SENDER_ID }} >> .env
echo NEXT_PUBLIC_FIREBASE_PROJECT_ID = ${{ secrets.FIREBASE_PROJECT_ID }} >> .env
echo NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET = ${{ secrets.FIREBASE_STORAGE_BUCKET }} >> .env
echo NEXT_PUBLIC_FIREBASE_ADMIN_PRIVATE_KEY = ${{ secrets.FIREBASE_ADMIN_PRIVATE_KEY }} >> .env
echo NEXT_PUBLIC_FIREBASE_ADMIN_CLIENT_EMAIL = ${{ secrets.FIREBASE_ADMIN_CLIENT_EMAIL }} >> .env
echo NEXT_PUBLIC_FIREBASE_ADMIN_PROJECT_ID = ${{ secrets.FIREBASE_ADMIN_PROJECT_ID }} >> .env
echo NEXT_PUBLIC_SENTRY_DSN = ${{ secrets.NEXT_PUBLIC_SENTRY_DSN }} >> .env
echo SENTRY_AUTH_TOKEN = ${{ secrets.SENTRY_AUTH_TOKEN }} >> .env
cat .env
- name: Check dependency cache
uses: actions/cache@v3
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ needs.job_install_dependencies.outputs.dependency_cache_key }}
- name: Check build cache
uses: actions/cache@v3
id: cache_built_packages
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}
- name: Build
if: steps.cache_built_packages.outputs.cache-hit == ''
run: yarn build
outputs:
dependency_cache_key: ${{ needs.job_install_dependencies.outputs.dependency_cache_key }}
job_continuous_integration:
name: check unit test & lint
runs-on: ubuntu-latest
needs: [job_install_dependencies]
timeout-minutes: 15
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: ${{ env.DEFAULT_NODE_VERSION }}
- name: Check dependency cache
uses: actions/cache@v3
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ needs.job_install_dependencies.outputs.dependency_cache_key }}
- name: Check Lint
if: ${{ github.event_name == 'pull_request' }}
run: yarn lint:changed-since
- name: Check Unit Test
run: yarn test:unit:changed-since
job_codecov_test_coverage:
name: set codecov test coverage
runs-on: ubuntu-latest
needs: [job_install_dependencies]
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: ${{ env.DEFAULT_NODE_VERSION }}
- name: Check dependency cache
uses: actions/cache@v3
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ needs.job_install_dependencies.outputs.dependency_cache_key }}
- name: Create Unit Test Coverage
run: yarn test:coverage
- name: Set unit test coverage
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
job_check_e2e_test:
name: check e2e test
if: github.event_name != 'push'
needs: [job_install_dependencies]
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v2
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: ${{ env.DEFAULT_NODE_VERSION }}
- name: Check dependency cache
uses: actions/cache@v3
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ needs.job_install_dependencies.outputs.dependency_cache_key }}
- name: Install cypress dependencies
run: yarn add cypress
- name: Cypress run
uses: cypress-io/github-action@v4
with:
install: false
start: yarn dev
browser: chrome
headed: true
record: true
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_PROJECT_ID }}
job_lhci:
name: Lighthouse CI
if: github.event_name != 'push'
needs: [job_build]
runs-on: ubuntu-latest
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v2
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: ${{ env.DEFAULT_NODE_VERSION }}
- name: Check dependency cache
uses: actions/cache@v3
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Check build cache
uses: actions/cache@v3
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}
- name: Install global @lhci/cli dependencies
run: yarn global add @lhci/cli
- name: Run Lighthouse CI
env:
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
run: lhci autorun || echo "Fail to Run Lighthouse CI!"
- name: Format lighthouse score
id: format_lighthouse_score
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const results = JSON.parse(fs.readFileSync('${{ github.workspace }}/lhci_reports/manifest.json'));
let comments = '';
results.forEach((result, index) => {
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]);
});
// https://web.dev/performance-scoring/#color-coding
const score = (res) => {
if (res >= 90) {
return 'π’';
}
if (res >= 50) {
return 'π ';
}
return 'π΄';
};
const comment = [
`β‘οΈ ${index + 1} Lighthouse report!`,
'| 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.interactive.score * 100)} Time to Interactive | ${audits.interactive.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} |`,
`| ${score(audits['largest-contentful-paint'].score * 100)} Largest Contentful Paint | ${audits['largest-contentful-paint'].displayValue} |`,
`| ${score(audits['cumulative-layout-shift'].score * 100)} Cumulative Layout Shift | ${audits['cumulative-layout-shift'].displayValue} |`,
].join('\n');
comments += `${comment}\n\n${detail}\n\n`;
});
core.setOutput('comments', comments);
- name: comment PR
uses: unsplash/comment-on-pr@v1.3.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
msg: ${{ steps.format_lighthouse_score.outputs.comments }}
check_for_duplicate_msg: false
job_nextjs_bundle_analysis:
name: nextjs bundle analysis
needs: [job_build]
runs-on: ubuntu-latest
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v2
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: ${{ env.DEFAULT_NODE_VERSION }}
- name: Check dependency cache
uses: actions/cache@v3
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Check build cache
uses: actions/cache@v3
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}
- name: Analyze bundle sizes
uses: transferwise/actions-next-bundle-analyzer@master
with:
workflow-id: ci.yml
base-branch: main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
job_publish_storybook_chromatic:
name: Chromatic Publish
runs-on: ubuntu-latest
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: ${{ env.DEFAULT_NODE_VERSION }}
- run: yarn
- uses: chromaui/action@v1
env:
NODE_OPTIONS: --max-old-space-size=6144
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
skip: 'dependabot/**'