-
Notifications
You must be signed in to change notification settings - Fork 558
331 lines (320 loc) · 11 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
name: Build, Lint, and Test
on:
workflow_call:
secrets:
CODECOV_TOKEN:
required: true
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: [18.x, 20.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
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@v4
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 list --include 'packages/*' --exclude 'packages/examples' --json)"
echo "e2e-workspace-package-names=$(yarn workspaces filter list --include 'packages/examples/packages/**' --exclude 'packages/examples/packages/invoke-snap' --json)"
echo "all-workspace-package-names=$(yarn workspaces filter list --include '{.,packages/**}' --exclude 'packages/snaps-cli/test/snap' --json)"
} >> "$GITHUB_OUTPUT"
shell: bash
build:
name: Build
runs-on: ubuntu-latest
needs: prepare
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn
- run: yarn --immutable --immutable-cache
- name: Build
run: yarn build:ci
- name: Cache build files
uses: actions/cache@v4
with:
path: |
packages/*/dist
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-simulator:
name: Build "@metamask/snaps-simulator"
runs-on: ubuntu-latest
needs: prepare
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn
- run: yarn --immutable --immutable-cache
- name: Restore "@metamask/snaps-execution-environments" build
uses: actions/cache@v4
with:
path: |
packages/snaps-execution-environments/dist/browserify
key: snaps-execution-environments-build-${{ runner.os }}-18.x-${{ github.sha }}
fail-on-cache-miss: true
- name: Cache Webpack vendor
id: cache-webpack-vendor
uses: actions/cache@v4
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@v4
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@v4
- name: Setup Node
uses: actions/setup-node@v4
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@v4
- name: Setup Node
uses: actions/setup-node@v4
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@v4
- name: Setup Node
uses: actions/setup-node@v4
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
- build
strategy:
fail-fast: false
matrix:
node-version: [18.x, 20.x]
package-name: ${{ fromJson(needs.prepare.outputs.test-workspace-package-names) }}
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- name: Restore "@metamask/snaps-execution-environments" build
uses: actions/cache@v4
with:
path: |
packages/snaps-execution-environments/dist/browserify
key: snaps-execution-environments-build-${{ runner.os }}-${{ matrix.node-version }}-${{ github.sha }}
fail-on-cache-miss: true
- name: Restore build files
uses: actions/cache@v4
with:
path: |
packages/*/dist
key: build-source-${{ runner.os }}-${{ github.sha }}
fail-on-cache-miss: true
- run: yarn --immutable --immutable-cache
- name: Install Google Chrome
run: yarn install-chrome
- run: yarn workspace ${{ matrix.package-name }} run test
- 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"
echo "artifact-name=$(echo ${{ matrix.package-name }} | sed 's:.*/::')" >> "$GITHUB_OUTPUT"
shell: bash
- name: Upload coverage artifact
if: ${{ matrix.node-version == '18.x' }}
uses: actions/upload-artifact@v4
with:
name: coverage-${{ steps.get-coverage-folder.outputs.artifact-name }}
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@v4
- name: Download coverage artifact
uses: actions/download-artifact@v4
with:
pattern: coverage-*
merge-multiple: true
- name: Upload coverage results
uses: codecov/codecov-action@6d798873df2b1b8e5846dba6fb86631229fbcb17
with:
files: packages/**/coverage-final.json
token: ${{ secrets.CODECOV_TOKEN }}
test-e2e:
name: E2E Test
runs-on: ubuntu-latest
needs:
- prepare
- build
strategy:
fail-fast: false
matrix:
node-version: [18.x, 20.x]
package-name: ${{ fromJson(needs.prepare.outputs.e2e-workspace-package-names) }}
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- name: Restore "@metamask/snaps-execution-environments" build
uses: actions/cache@v4
with:
path: |
packages/snaps-execution-environments/dist/browserify
key: snaps-execution-environments-build-${{ runner.os }}-${{ matrix.node-version }}-${{ github.sha }}
fail-on-cache-miss: true
- name: Restore build files
uses: actions/cache@v4
with:
path: |
packages/*/dist
key: build-source-${{ runner.os }}-${{ github.sha }}
fail-on-cache-miss: true
- run: yarn --immutable --immutable-cache
- name: Build snap
run: yarn workspace ${{ matrix.package-name }} run build
- name: Run E2E test
run: yarn workspace ${{ matrix.package-name }} run test
- 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@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn
- run: yarn --immutable
- run: yarn build:ci
- run: yarn workspace @metamask/snaps-cli run test