387 lines (374 loc) · 12.4 KB
/
build-lint-test.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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
name: Build, Lint, and Test
on:
workflow_call:
jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
outputs:
test-workspace-package-names: ${{ steps.workspace-package-names.outputs.test-workspace-package-names }}
e2e-workspace-package-names: ${{ steps.workspace-package-names.outputs.e2e-workspace-package-names }}
all-workspace-package-names: ${{ steps.workspace-package-names.outputs.all-workspace-package-names }}
strategy:
fail-fast: false
matrix:
node-version: [16.x, 18.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- run: yarn --immutable
- name: Cache "@metamask/snaps-execution-environments" build
id: cache-snaps-execution-environments-build
uses: actions/cache@v3
with:
path: |
packages/snaps-execution-environments/dist/browserify
key: snaps-execution-environments-build-${{ runner.os }}-${{ matrix.node-version }}-${{ github.sha }}
- name: Prepare "@metamask/snaps-execution-environments" build
if: steps.cache-snaps-execution-environments-build.outputs.cache-hit != 'true'
run: yarn workspace @metamask/snaps-execution-environments run build:lavamoat
- name: Fetch workspace package names
id: workspace-package-names
run: |
{
echo "test-workspace-package-names=$(yarn workspaces filter --include 'packages/*' --exclude 'packages/examples' --json)"
echo "e2e-workspace-package-names=$(yarn workspaces filter --include 'packages/examples/packages/**' --exclude 'packages/examples/packages/invoke-snap' --json)"
echo "all-workspace-package-names=$(yarn workspaces filter --include '{.,packages/**}' --exclude 'packages/snaps-cli/test/snap' --json)"
} >> "$GITHUB_OUTPUT"
shell: bash
build-source:
name: Build source
runs-on: ubuntu-latest
needs: prepare
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: yarn
- run: yarn --immutable --immutable-cache
- name: Build source
run: yarn build:source
- name: Cache build files
uses: actions/cache@v3
with:
path: |
packages/*/dist/esm
packages/*/dist/cjs
key: build-source-${{ runner.os }}-${{ github.sha }}
- name: Require clean working directory
shell: bash
run: |
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
fi
build-types:
name: Build types
runs-on: ubuntu-latest
needs: prepare
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: yarn
- run: yarn --immutable --immutable-cache
- name: Build types
run: yarn build:types
- name: Cache build files
uses: actions/cache@v3
with:
path: |
packages/*/dist/types
key: build-types-${{ runner.os }}-${{ github.sha }}
- name: Require clean working directory
shell: bash
run: |
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
fi
post-build:
name: Post-build
runs-on: ubuntu-latest
needs:
- build-source
- build-types
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: yarn
- run: yarn --immutable --immutable-cache
- name: Restore build files
uses: actions/cache@v3
with:
path: |
packages/*/dist/esm
packages/*/dist/cjs
key: build-source-${{ runner.os }}-${{ github.sha }}
- name: Restore types files
uses: actions/cache@v3
with:
path: |
packages/*/dist/types
key: build-types-${{ runner.os }}-${{ github.sha }}
- name: Post-build
run: yarn build:post-tsc:ci
build-simulator:
name: Build "@metamask/snaps-simulator"
runs-on: ubuntu-latest
needs: prepare
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: yarn
- run: yarn --immutable --immutable-cache
- name: Restore "@metamask/snaps-execution-environments" build
uses: actions/cache@v3
with:
path: |
packages/snaps-execution-environments/dist/browserify
key: snaps-execution-environments-build-${{ runner.os }}-18.x-${{ github.sha }}
- name: Cache Webpack vendor
id: cache-webpack-vendor
uses: actions/cache@v3
with:
path: |
packages/snaps-simulator/vendor
key: webpack-vendor-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
- name: Build Webpack vendor
if: steps.cache-webpack-vendor.outputs.cache-hit != 'true'
run: yarn workspace @metamask/snaps-simulator run build:vendor
- name: Build
run: yarn workspace @metamask/snaps-simulator run build:webpack
- name: Cache "@metamask/snaps-simulator" build
id: cache-e2e-simulator-build
uses: actions/cache@v3
with:
path: |
packages/snaps-simulator/dist/webpack
key: e2e-simulator-build-${{ runner.os }}-${{ github.sha }}
- name: Require clean working directory
shell: bash
run: |
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
fi
build-test-snaps:
name: Build "@metamask/test-snaps"
runs-on: ubuntu-latest
needs: prepare
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: yarn
- run: yarn --immutable --immutable-cache
- name: Build
run: yarn workspace @metamask/test-snaps run build
- name: Require clean working directory
shell: bash
run: |
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
fi
policy:
name: Generate LavaMoat policy
runs-on: ubuntu-latest
needs: prepare
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: yarn
- run: yarn --immutable --immutable-cache
- name: Generate LavaMoat policy
run: yarn workspace @metamask/snaps-execution-environments build:lavamoat:policy
- name: Require clean working directory
shell: bash
run: |
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
fi
lint:
name: Lint
runs-on: ubuntu-latest
needs: prepare
strategy:
fail-fast: false
matrix:
package-name: ${{ fromJson(needs.prepare.outputs.all-workspace-package-names) }}
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: yarn
- run: yarn --immutable --immutable-cache
- run: yarn workspace ${{ matrix.package-name }} run lint:ci
- name: Require clean working directory
shell: bash
run: |
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
fi
test:
name: Test
runs-on: ubuntu-latest
needs: prepare
strategy:
fail-fast: false
matrix:
node-version: [16.x, 18.x]
package-name: ${{ fromJson(needs.prepare.outputs.test-workspace-package-names) }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- name: Restore "@metamask/snaps-execution-environments" build
uses: actions/cache@v3
with:
path: |
packages/snaps-execution-environments/dist/browserify
key: snaps-execution-environments-build-${{ runner.os }}-${{ matrix.node-version }}-${{ github.sha }}
- run: yarn --immutable --immutable-cache
- name: Install Google Chrome
run: yarn install-chrome
- run: yarn workspace ${{ matrix.package-name }} run test:ci
- name: Get coverage folder
id: get-coverage-folder
run: |
echo "stub" >> stub
echo "coverage-folder=$(yarn workspaces list --json | grep ${{ matrix.package-name }} | jq -r '.location')/coverage" >> "$GITHUB_OUTPUT"
shell: bash
- name: Upload coverage artifact
if: ${{ matrix.node-version == '16.x' }}
uses: actions/upload-artifact@v3
with:
name: coverage
path: |
stub
${{ steps.get-coverage-folder.outputs.coverage-folder }}/**/coverage-final.json
if-no-files-found: warn
retention-days: 1
- name: Require clean working directory
shell: bash
run: |
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
fi
upload-coverage:
name: Upload coverage to Codecov
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v3
- name: Download coverage artifact
uses: actions/download-artifact@v3
with:
name: coverage
- name: Upload coverage results
uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70
with:
files: packages/**/coverage-final.json
test-e2e:
name: E2E Test
runs-on: ubuntu-latest
needs:
- prepare
- build-source
- build-types
- build-simulator
strategy:
fail-fast: false
matrix:
node-version: [16.x, 18.x]
package-name: ${{ fromJson(needs.prepare.outputs.e2e-workspace-package-names) }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- name: Restore "@metamask/snaps-execution-environments" build
uses: actions/cache@v3
with:
path: |
packages/snaps-execution-environments/dist/browserify
key: snaps-execution-environments-build-${{ runner.os }}-${{ matrix.node-version }}-${{ github.sha }}
- name: Restore build files
uses: actions/cache@v3
with:
path: |
packages/*/dist/esm
packages/*/dist/cjs
key: build-source-${{ runner.os }}-${{ github.sha }}
- name: Restore types files
uses: actions/cache@v3
with:
path: |
packages/*/dist/types
key: build-types-${{ runner.os }}-${{ github.sha }}
- name: Restore "@metamask/snaps-simulator" build
uses: actions/cache@v3
with:
path: |
packages/snaps-simulator/dist/webpack
key: e2e-simulator-build-${{ runner.os }}-${{ github.sha }}
- run: yarn --immutable --immutable-cache
- name: Install Google Chrome
run: yarn install-chrome
- name: Build snap
run: yarn workspace ${{ matrix.package-name }} run build
- name: Run E2E test
run: yarn workspace ${{ matrix.package-name }} run test:e2e
- name: Require clean working directory
shell: bash
run: |
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
fi
platform-compatibility-test:
name: Test platform compatibility
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macOS-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: yarn
- run: yarn --immutable
- run: yarn workspace @metamask/snaps-cli run test