-
Notifications
You must be signed in to change notification settings - Fork 58
445 lines (380 loc) · 14.6 KB
/
Copy pathpull-request.yml
File metadata and controls
445 lines (380 loc) · 14.6 KB
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# This Github Workflow builds v2 of the mParticle Web SDK, lints with ESLint and Prettier to find errors, and runs all tests
# If the PR is from dependabot, it automatically gets merged if tests run properly.
name: Web SDK Build & Test
on: pull_request
permissions:
contents: read
pull-requests: write
checks: write
id-token: write
jobs:
build-bundle:
name: Build Distribution Bundle
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: NPM install
uses: actions/setup-node@v6
with:
node-version: latest
- name: Run NPM CI
run: npm ci
- name: Lint with ESLint
run: npm run lint
- name: Lint with Prettier
run: npm run prettier
- name: Run Build IIFE
run: npm run build:iife
- name: Display Bundle Diff, but Fancy!
run: git diff --unified=3 dist/mparticle.js | npx diff-so-fancy
- name: Archive Bundle
uses: actions/upload-artifact@v6
with:
name: bundle-local
path: dist
- name: Archive npm failure logs
uses: actions/upload-artifact@v6
if: failure()
with:
name: npm-logs
path: ~/.npm/_logs
# Currently, we're only using Jest to test TypeScript modules
# and they do not require any built files
test-jest:
name: 'Test Jest'
runs-on: 'ubuntu-latest'
strategy:
matrix:
node-version: [18.x, 19.x, 20.x, 21.x, 22.x, 23.x, 24.x, 25.x]
steps:
- name: Checkout
uses: actions/checkout@v6
- name: NPM install
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
- name: Run NPM CI
run: npm ci
- name: Run Jest Tests
run: npm run test:jest
- name: Archive npm failure logs
uses: actions/upload-artifact@v6
if: failure()
with:
name: npm-logs
path: ~/.npm/_logs
test-types:
name: 'Test Type Declarations'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: NPM install
uses: actions/setup-node@v6
with:
node-version: latest
- name: Run NPM CI
run: npm ci
- name: Build and Test Type Declarations
run: npm run test:types
- name: Archive npm failure logs
uses: actions/upload-artifact@v6
if: failure()
with:
name: npm-logs
path: ~/.npm/_logs
# Only Core test requires bundle, but we want to make sure
# that tests only run when the bundle is successfully built
test-core:
name: Core Tests
uses: mParticle/mparticle-workflows/.github/workflows/web-run-test.yml@main
needs:
- test-jest
- build-bundle
with:
test_command_label: Core SDK Tests
test_command: npm run test
build_command: npm run build:iife
branch_name: ${{ vars.GITHUB_SHA }}
# Kit tests: build and test each kit defined in kits/matrix.json
load-kit-matrix:
name: Load Kit Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set.outputs.matrix }}
steps:
- uses: actions/checkout@v6
- id: set
run: |
if [ -f kits/matrix.json ]; then
echo "matrix=$(jq -c . kits/matrix.json)" >> "$GITHUB_OUTPUT"
else
echo "matrix=[]" >> "$GITHUB_OUTPUT"
fi
run-kit-tests:
name: 'Kit Tests: ${{ matrix.kit.name }}'
needs:
- load-kit-matrix
- test-jest
- build-bundle
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
kit: ${{ fromJson(needs.load-kit-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: latest
- name: Install Firefox Latest
uses: browser-actions/setup-firefox@latest
- name: Install, build, and test kit
run: |
cd ${{ matrix.kit.local_path }}
npm ci
npm run build
npm test
- name: Archive npm failure logs
uses: actions/upload-artifact@v6
if: failure()
with:
name: npm-logs-kit-${{ matrix.kit.name }}
path: ~/.npm/_logs
# Test Stub can be run independent of other tests
test-stub:
name: 'Test Stub'
runs-on: ubuntu-latest
needs:
- test-core
- run-kit-tests
- test-jest
- build-bundle
steps:
- name: Checkout
uses: actions/checkout@v6
- name: NPM install
uses: actions/setup-node@v6
with:
node-version: latest
- name: Run NPM CI
run: npm ci
- name: Install Firefox Latest
uses: browser-actions/setup-firefox@latest
- name: Log Firefox Version
run: firefox --version
- name: Run Stub Tests
run: npm run test:stub
- name: Archive npm failure logs
uses: actions/upload-artifact@v6
if: failure()
with:
name: npm-logs
path: ~/.npm/_logs
# Integration Tests run the same suite of tests against various build systems
# to make sure our SDK will run in different environments
test-integrations-require-js:
name: 'Integration Tests: Require JS'
uses: mParticle/mparticle-workflows/.github/workflows/web-run-test.yml@main
needs:
- test-core
- run-kit-tests
- test-jest
- build-bundle
with:
test_command_label: Require JS Test
test_command: npm run test:requirejs
branch_name: ${{ vars.GITHUB_SHA }}
test-integrations-common-js-browserfy:
name: 'Integration Tests: Browserfy Common JS'
uses: mParticle/mparticle-workflows/.github/workflows/web-run-test.yml@main
needs:
- test-core
- run-kit-tests
- test-jest
- build-bundle
with:
test_command_label: Browserfy CJS Test
test_command: npm run test:integrations:cjs:browserfy
branch_name: ${{ vars.GITHUB_SHA }}
build_command: npm run build:npm && npm run build:test-bundle
test-integrations-common-js-webpack:
name: 'Integration Tests: webpack Common JS'
uses: mParticle/mparticle-workflows/.github/workflows/web-run-test.yml@main
needs:
- test-core
- run-kit-tests
- test-jest
- build-bundle
with:
test_command_label: webpack CJS Test
test_command: npm run test:integrations:cjs:webpack
branch_name: ${{ vars.GITHUB_SHA }}
build_command: npm run build:npm && npm run build:test-bundle
test-integrations-common-js-rollup:
name: 'Integration Tests: Rollup Common JS'
uses: mParticle/mparticle-workflows/.github/workflows/web-run-test.yml@main
needs:
- test-core
- run-kit-tests
- test-jest
- build-bundle
with:
test_command_label: Rollup CJS Test
test_command: npm run test:integrations:cjs:rollup
branch_name: ${{ vars.GITHUB_SHA }}
build_command: npm run build:npm && npm run build:test-bundle
test-integrations-module-js-webpack:
name: 'Integration Tests: webpack Module JS'
uses: mParticle/mparticle-workflows/.github/workflows/web-run-test.yml@main
needs:
- test-core
- run-kit-tests
- test-jest
- build-bundle
with:
test_command_label: webpack Module Test
test_command: npm run test:integrations:module:webpack
branch_name: ${{ vars.GITHUB_SHA }}
build_command: npm run build:esm && npm run build:test-bundle
test-integrations-module-js-rollup:
name: 'Integration Tests: Rollup Module JS'
uses: mParticle/mparticle-workflows/.github/workflows/web-run-test.yml@main
needs:
- test-core
- run-kit-tests
- test-jest
- build-bundle
with:
test_command_label: Rollup Module Test
test_command: npm run test:integrations:module:rollup
branch_name: ${{ vars.GITHUB_SHA }}
build_command: npm run build:esm && npm run build:test-bundle
build-local:
name: Get Bundle Size from Current Branch
runs-on: ubuntu-latest
needs: build-bundle
outputs:
bundledLocal: ${{ steps.set-bundled-local.outputs.bundledLocal }}
bundledLocalHuman: ${{ steps.set-bundled-local.outputs.bundledLocalHuman }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: NPM install
uses: actions/setup-node@v6
with:
node-version: latest
- name: Run NPM CI
run: npm ci
- name: Download Local Bundle
uses: actions/download-artifact@v7
with:
name: bundle-local
- name: Compress Bundle
run: npm run bundle
- name: Report Bundle Size
run: |
BUNDLED_LOCAL=$(ls -l dist/mparticle.min.js.gz | awk '{print $5}')
echo "BUNDLED_LOCAL=$BUNDLED_LOCAL" >> $GITHUB_ENV
BUNDLED_LOCAL_HUMAN=$(ls -lh dist/mparticle.min.js.gz | awk '{print $5}')
echo "BUNDLED_LOCAL_HUMAN=$BUNDLED_LOCAL_HUMAN" >> $GITHUB_ENV
- name: Set Local Bundled Size
id: set-bundled-local
run: |
echo "::set-output name=bundledLocal::${{ env.BUNDLED_LOCAL }}"
echo "::set-output name=bundledLocalHuman::${{ env.BUNDLED_LOCAL_HUMAN }}"
- name: Archive npm failure logs
uses: actions/upload-artifact@v6
if: failure()
with:
name: npm-logs
path: ~/.npm/_logs
build-master:
name: Get Bundle Size from Master
runs-on: ubuntu-latest
needs: build-bundle
outputs:
bundledMaster: ${{ steps.set-bundled-master.outputs.bundledMaster }}
bundledMasterHuman: ${{ steps.set-bundled-master.outputs.bundledMasterHuman }}
steps:
- name: Checkout Master
uses: actions/checkout@v6
with:
ref: master
- name: NPM install
uses: actions/setup-node@v6
with:
node-version: latest
- name: Compress Bundle
run: npm run bundle
- name: Report Bundle Size
run: |
BUNDLED_MASTER=$(ls -l dist/mparticle.min.js.gz | awk '{print $5}')
echo "BUNDLED_MASTER=$BUNDLED_MASTER" >> $GITHUB_ENV
BUNDLED_MASTER_HUMAN=$(ls -lh dist/mparticle.min.js.gz | awk '{print $5}')
echo "BUNDLED_MASTER_HUMAN=$BUNDLED_MASTER_HUMAN" >> $GITHUB_ENV
- name: Set Master Bundled Size
id: set-bundled-master
run: |
echo "::set-output name=bundledMaster::${{ env.BUNDLED_MASTER }}"
echo "::set-output name=bundledMasterHuman::${{ env.BUNDLED_MASTER_HUMAN }}"
- name: Archive npm failure logs
uses: actions/upload-artifact@v6
if: failure()
with:
name: npm-logs
path: ~/.npm/_logs
calculate-bundled:
name: Calculate Bundled Diff
uses: ./.github/workflows/calculate-difference.yml
needs:
- build-master
- build-local
with:
initial_bundle_size: ${{ needs.build-master.outputs.bundledMaster }}
updated_bundle_size: ${{ needs.build-local.outputs.bundledLocal }}
generate-report:
name: Generate Report
runs-on: ubuntu-latest
needs:
- build-master
- build-local
- calculate-bundled
steps:
- name: Adding Markdown
run: |
echo '### Calculate Bundle Size Difference' >> $GITHUB_STEP_SUMMARY
echo "| | master | current | % changed |" >> $GITHUB_STEP_SUMMARY
echo "|--|--|--|--|" >> $GITHUB_STEP_SUMMARY
echo "| mparticle.min.js.gz | ${{ needs.build-master.outputs.bundledMasterHuman }} | ${{ needs.build-local.outputs.bundledLocalHuman }} | ${{ needs.calculate-bundled.outputs.diff_percent }} |" >> $GITHUB_STEP_SUMMARY
automerge-dependabot:
name: 'Save PR Number for Dependabot Automerge'
needs:
- test-core
- test-stub
- run-kit-tests
- test-integrations-common-js-browserfy
- test-integrations-common-js-webpack
- test-integrations-common-js-rollup
- test-integrations-module-js-webpack
- test-integrations-module-js-rollup
- test-integrations-require-js
uses: mParticle/mparticle-workflows/.github/workflows/dependabot-save-pr-number.yml@main
pr-notify:
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
needs:
- test-stub
- test-integrations-require-js
- test-integrations-common-js-browserfy
- test-integrations-common-js-webpack
- test-integrations-common-js-rollup
- test-integrations-module-js-webpack
- test-integrations-module-js-rollup
- generate-report
name: Notify GChat
uses: ROKT/rokt-workflows/.github/workflows/oss_pr_opened_notification.yml@main
secrets:
gchat_webhook: ${{ secrets.GCHAT_PRS_WEBHOOK }}