-
Notifications
You must be signed in to change notification settings - Fork 327
633 lines (595 loc) · 22.6 KB
/
test-desktop.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
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
name: "@Desktop • Test App"
run-name: "@Desktop • Test App triggered by ${{ github.event_name == 'workflow_dispatch' && inputs.login || github.actor }} ${{ format('on ref {0}', github.ref_name) }}"
on:
push:
branches:
- main
- develop
- release
- hotfix
workflow_dispatch:
inputs:
ref:
description: the branch which triggered this workflow
required: false
login:
description: The GitHub username that triggered the workflow
required: true
base_ref:
description: The base branch to merge the head into when checking out the code
required: false
draft:
description: true if the PR is in draft
required: false
default: "false"
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name != 'develop' && github.ref || github.run_id }}
cancel-in-progress: true
env:
REFNAME: ${{ (github.event_name == 'workflow_dispatch' && (inputs.ref || github.ref_name)) || github.sha }}
jobs:
codechecks:
name: "Desktop code checks"
env:
NODE_OPTIONS: "--max-old-space-size=7168"
FORCE_COLOR: 3
CI_OS: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: LedgerHQ/ledger-live/tools/actions/composites/checkout-merge@develop
with:
ref: ${{ env.REFNAME }}
base: ${{ inputs.base_ref }}
- uses: ./tools/actions/composites/setup-test-desktop
id: setup-test-desktop
with:
skip_builds: true
install_dotnet: true
aws-access-key: ${{ secrets.AWS_S3_CACHE_ACCESS_KEY }}
aws-secret-key: ${{ secrets.AWS_S3_CACHE_SECRET_KEY }}
- name: lint
run: |
pnpm lint --filter="ledger-live-desktop" --api="http://127.0.0.1:${{ steps.turborepo-cache-server.outputs.port }}" --token="yolo" --team="foo" -- --format="json" -o="lint.json"
node -p "require('./node_modules/eslint/lib/cli-engine/formatters/stylish.js')(require('./apps/ledger-live-desktop/lint.json'))"
- name: prettier
run: pnpm desktop prettier:check
- name: typecheck
run: pnpm desktop typecheck
- uses: actions/upload-artifact@v3
name: upload eslint json output
if: always()
with:
name: lint
path: ${{ github.workspace }}/apps/ledger-live-desktop/lint.json
deadcodecheck:
name: "Desktop deadcode check"
env:
NODE_OPTIONS: "--max-old-space-size=7168"
FORCE_COLOR: 3
CI_OS: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: LedgerHQ/ledger-live/tools/actions/composites/checkout-merge@develop
with:
ref: ${{ env.REFNAME }}
base: ${{ inputs.base_ref }}
- uses: ./tools/actions/composites/setup-test-desktop
id: setup-test-desktop
with:
skip_builds: true
aws-access-key: ${{ secrets.AWS_S3_CACHE_ACCESS_KEY }}
aws-secret-key: ${{ secrets.AWS_S3_CACHE_SECRET_KEY }}
- name: check for dead code
run: cd apps/ledger-live-desktop && npx unimported
shell: bash
unit-tests:
name: "Desktop Unit Tests"
env:
NODE_OPTIONS: "--max-old-space-size=7168"
FORCE_COLOR: 3
CI_OS: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: LedgerHQ/ledger-live/tools/actions/composites/checkout-merge@develop
with:
ref: ${{ env.REFNAME }}
base: ${{ inputs.base_ref }}
- uses: ./tools/actions/composites/setup-test-desktop
id: setup-test-desktop
with:
skip_builds: true
aws-access-key: ${{ secrets.AWS_S3_CACHE_ACCESS_KEY }}
aws-secret-key: ${{ secrets.AWS_S3_CACHE_SECRET_KEY }}
- name: Run unit tests
run: pnpm desktop test:jest
e2e-tests-windows:
name: "Desktop E2E (Windows)"
outputs:
status: ${{ steps.tests.outcome }}
env:
NODE_OPTIONS: "--max-old-space-size=7168"
FORCE_COLOR: 3
CI_OS: "windows-latest"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
# DEBUG: "pw:browser*"
# DEBUG_LOGS: 1
runs-on: [ledger-live-4xlarge-windows-2022]
steps:
- uses: LedgerHQ/ledger-live/tools/actions/composites/checkout-merge@develop
with:
ref: ${{ env.REFNAME }}
base: ${{ inputs.base_ref }}
- uses: actions/setup-dotnet@v2
with:
dotnet-version: 2.1.816
- uses: ./tools/actions/composites/setup-test-desktop
id: setup-test-desktop
with:
install_node_gyp: true
install_playwright: true
upgrade_npm: true
install_dotnet: true
aws-access-key: ${{ secrets.AWS_S3_CACHE_ACCESS_KEY }}
aws-secret-key: ${{ secrets.AWS_S3_CACHE_SECRET_KEY }}
- name: Run playwright tests
id: tests
run: |
pnpm desktop test:playwright
shell: bash
- name: upload diffs to imgur
if: always() && !cancelled()
uses: ./tools/actions/upload-images
id: imgur
with:
path: apps/ledger-live-desktop/tests/artifacts/test-results
workspace: ${{ github.workspace }}
os: windows
- name: upload ci suggested screenshots
if: always() && !cancelled()
uses: actions/upload-artifact@v3
with:
name: images
path: images-windows.json
- name: Upload playwright test results [On Failure]
uses: actions/upload-artifact@v3
if: failure() && !cancelled()
with:
name: playwright-results-windows
path: |
apps/ledger-live-desktop/tests/artifacts/test-results
apps/ledger-live-desktop/tests/artifacts/html-report
apps/ledger-live-desktop/tests/artifacts/coverage
apps/ledger-live-desktop/tests/artifacts/videos
apps/ledger-live-desktop/tests/artifacts/logs
apps/ledger-live-desktop/tests/artifacts/*.log
- name: Upload Allure Report
if: always()
uses: actions/upload-artifact@v3
with:
name: allure-results-windows
path: apps/ledger-live-desktop/allure-results
e2e-tests-linux:
name: "Desktop E2E (Linux)"
outputs:
status: ${{ steps.tests.outcome }}
env:
NODE_OPTIONS: "--max-old-space-size=7168"
INSTRUMENT_BUILD: true
FORCE_COLOR: 3
CI_OS: "ubuntu-latest"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
# DEBUG: "pw:browser*"
# DEBUG_LOGS: 1
runs-on: [ledger-live-4xlarge-linux]
steps:
- uses: LedgerHQ/ledger-live/tools/actions/composites/checkout-merge@develop
with:
ref: ${{ env.REFNAME }}
base: ${{ inputs.base_ref }}
- uses: ./tools/actions/composites/setup-test-desktop
id: setup-test-desktop
with:
skip_python: true
skip_ruby: true
install_playwright: true
aws-access-key: ${{ secrets.AWS_S3_CACHE_ACCESS_KEY }}
aws-secret-key: ${{ secrets.AWS_S3_CACHE_SECRET_KEY }}
- name: Run playwright tests [Linux => xvfb-run]
id: tests
run: |
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- pnpm desktop test:playwright
- name: upload diffs to imgur
if: always() && !cancelled()
uses: ./tools/actions/upload-images
id: imgur
with:
path: apps/ledger-live-desktop/tests/artifacts/test-results
workspace: ${{ github.workspace }}
os: linux
- name: upload ci suggested screenshots
if: always() && !cancelled()
uses: actions/upload-artifact@v3
with:
name: images
path: images-linux.json
- name: Upload playwright test results [On Failure]
uses: actions/upload-artifact@v3
if: failure() && !cancelled()
with:
name: playwright-results-linux
path: |
apps/ledger-live-desktop/tests/artifacts/test-results
apps/ledger-live-desktop/tests/artifacts/html-report
apps/ledger-live-desktop/tests/artifacts/coverage
apps/ledger-live-desktop/tests/artifacts/videos
apps/ledger-live-desktop/tests/artifacts/logs
apps/ledger-live-desktop/tests/artifacts/*.log
- name: Upload Allure Report
if: always()
uses: actions/upload-artifact@v3
with:
name: allure-results-linux
path: apps/ledger-live-desktop/allure-results
e2e-tests-mac:
name: "Desktop E2E (macOS X)"
runs-on: [m1, ARM64]
outputs:
status: ${{ steps.tests.outcome }}
env:
NODE_OPTIONS: "--max-old-space-size=7168"
FORCE_COLOR: 3
CI_OS: "macos-latest"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
# DEBUG: "pw:browser*"
# DEBUG_LOGS: 1
steps:
- uses: LedgerHQ/ledger-live/tools/actions/composites/checkout-merge@develop
with:
ref: ${{ env.REFNAME }}
base: ${{ inputs.base_ref }}
- uses: ./tools/actions/composites/setup-test-desktop
id: setup-test-desktop
with:
skip_python: true
skip_ruby: true
install_playwright: true
pnpm_dest: ${{ runner.temp }}/setup-pnpm
aws-access-key: ${{ secrets.AWS_S3_CACHE_ACCESS_KEY }}
aws-secret-key: ${{ secrets.AWS_S3_CACHE_SECRET_KEY }}
- name: Run playwright tests
id: tests
run: |
pnpm desktop test:playwright
- name: upload diffs to imgur
if: always() && !cancelled()
uses: ./tools/actions/upload-images
id: imgur
with:
path: apps/ledger-live-desktop/tests/artifacts/test-results
workspace: ${{ github.workspace }}
os: macos
- name: upload ci suggested screenshots
if: always() && !cancelled()
uses: actions/upload-artifact@v3
with:
name: images
path: images-macos.json
- name: Upload playwright test results [On Failure]
uses: actions/upload-artifact@v3
if: failure() && !cancelled()
with:
name: playwright-results-macos
path: |
apps/ledger-live-desktop/tests/artifacts/test-results
apps/ledger-live-desktop/tests/artifacts/html-report
apps/ledger-live-desktop/tests/artifacts/coverage
apps/ledger-live-desktop/tests/artifacts/videos
apps/ledger-live-desktop/tests/artifacts/logs
apps/ledger-live-desktop/tests/artifacts/*.log
- name: Upload Allure Report
if: always()
uses: actions/upload-artifact@v3
with:
name: allure-results-macos
path: apps/ledger-live-desktop/allure-results
report:
needs:
[codechecks, deadcodecheck, unit-tests, e2e-tests-linux, e2e-tests-windows, e2e-tests-mac]
runs-on: ubuntu-latest
if: always() && !cancelled()
steps:
- uses: LedgerHQ/ledger-live/tools/actions/composites/checkout-merge@develop
with:
ref: ${{ env.REFNAME }}
base: ${{ inputs.base_ref }}
- name: "download linter results"
uses: actions/download-artifact@v3
with:
name: lint
- name: download images artifacts
uses: actions/download-artifact@v3
with:
name: images
- name: parse images
uses: actions/github-script@v6
with:
script: |
const fs = require("fs");
const files = ["images-linux", "images-windows", "images-macos"];
let result = {};
for (const file of files) {
try {
const raw = JSON.parse(fs.readFileSync("${{github.workspace}}/" + file + ".json"));
const key = file.replace("images-", "").replace("-latest", "").trim()
result[key] = raw;
} catch (err) {
console.log(err);
}
}
fs.writeFileSync("./images.json", JSON.stringify(result, null, 2));
- name: prepare comment with screenshots
id: comment
uses: ./tools/actions/prepare-comment-screenshots
with:
images: images.json
no-actor: true
- uses: actions/github-script@v6
name: prepare status
id: status
with:
script: |
const fs = require("fs");
const path = require("path");
const [ owner, repo ] = "${{ github.repository }}".split("/");
const jobs = await github.paginate(github.rest.actions.listJobsForWorkflowRunAttempt, {
owner,
repo,
run_id: "${{ github.run_id }}",
attempt_number: "${{ github.run_attempt }}",
});
const findJobUrl = os =>
jobs.find(job => job.name == `Live Desktop Tests (${os})`)?.html_url;
const keys = {
mac: {
symbol: "🍏",
name: "macOS",
jobUrl: findJobUrl("macOS X")
},
windows: {
symbol: "🪟",
name: "Windows",
jobUrl: findJobUrl("Windows")
},
linux: {
symbol: "🐧",
name: "Linux",
jobUrl: findJobUrl("Linux")
},
};
const typecheck = {
pass: ${{ needs.codechecks.result == 'success' }},
status: "${{ needs.codechecks.result }}",
};
const unitTests = {
pass: ${{ needs.unit-tests.result == 'success' }},
status: "${{ needs.unit-tests.result }}",
};
const deadcodecheck = {
pass: ${{ needs.deadcodecheck.result == 'success' }},
};
const report = {
mac: {
pass: ${{ needs.e2e-tests-mac.outputs.status == 'success' }},
status: "${{ needs.e2e-tests-mac.outputs.status }}",
},
linux: {
pass: ${{ needs.e2e-tests-linux.outputs.status == 'success' }},
status: "${{ needs.e2e-tests-linux.outputs.status }}",
},
windows: {
pass: ${{ needs.e2e-tests-windows.outputs.status == 'success' }},
status: "${{ needs.e2e-tests-windows.outputs.status }}",
},
};
let summary = `### TypeCheck
${typecheck.pass ? "Typechecks are fine" : "Unfortunately typechecks did not pass"}
- ${typecheck.pass ? "✅" : "❌"} **Type checks** ended with status \`${typecheck.status}\`
### Dead Code Check
${deadcodecheck.pass ? "Dead code checks are fine" : "Unfortunately, dead code checks did not pass. Try \`npx unimported\` in apps/ledger-live-desktop"}
- ${deadcodecheck.pass ? "✅" : "❌"}
### Unit Tests (Jest)
${unitTests.pass ? "Unit tests are fine" : "Unit tests did not pass"}
- ${unitTests.pass ? "✅" : "❌"} **Unit tests** ended with status \`${unitTests.status}\`
### Screenshot Tests (Playwright)
`
summary += `|`
const reportKeys = Object.keys(report);
const playwrightSuccess = Object.entries(report).every(([os, values]) => !!values.pass);
reportKeys.forEach((k) => {
summary += ` [${keys[k].symbol} ${keys[k].name}](${keys[k].jobUrl}) |`;
});
summary += `
|`;
for (let i = 0; i < reportKeys.length; i++) {
summary += ` :--: |`;
}
summary += `
|`;
Object.entries(report).forEach(([os, values]) => {
summary += ` ${values.pass ? "✅" : "❌"} (${values.status}) |`;
});
summary += `
${{ steps.comment.outputs.body }}
`
// Store eslint results as annotations
let annotations = []
try {
const lintResult = require("./lint.json");
const LEVELS = {
0: "notice",
1: "warning",
2: "failure"
};
const withErrorOrWarning = lintResult.filter(r => r.errorCount > 0 || r.fatalErrorCount > 0 || r.warningCount > 0);
annotations = withErrorOrWarning.flatMap(({ filePath, messages }) =>
messages.map((m) => {
const sameLine = m.line === m.endLine;
return {
path: path.relative(process.env.GITHUB_WORKSPACE, filePath),
start_line: m.line,
end_line: m.endLine,
// Annotations only support start_column and end_column on the same line. Omit this parameter if start_line and end_line have different values.
// https://docs.github.com/en/rest/reference/checks#create-a-check-run
start_column: sameLine ? m.column : undefined,
end_column: sameLine ? m.endColumn : undefined,
annotation_level: LEVELS[m.severity],
message: m.message,
title: m.ruleId,
}
})
);
} catch(error) {
console.error("Failed processing eslint annotations", error)
}
const output = {
summary,
annotations,
actions: [{
// 20 chars max
label: "Regen. Screenshots",
// 20 chars max
identifier: "regen_screenshots",
// 40 chars max
description: "Will regenerate playwright screenshots",
}, {
// 20 chars max
label: "Run full LLD suite",
// 20 chars max
identifier: "lld_full_suite",
// 40 chars max
description: "Run the full e2e test suite for LLD",
}],
};
fs.writeFileSync("summary.json", JSON.stringify(output), "utf-8");
if (${{ github.event_name != 'push' }}) return;
const slackPayload = {
"text": "[Alert] Ledger Live Desktop tests failed on ${{github.ref_name}}",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":warning: [Alert] Ledger Live Desktop tests failed on ${{ github.ref_name }}",
"emoji": true
}
},
{
"type": "divider"
},
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Checks"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `- typechecks: ${typecheck.pass ? "✅" : "❌"}\n - deadcode checks: ${deadcodecheck.pass ? "✅" : "❌"}\n - unit tests: ${unitTests.pass ? "✅" : "❌"}\n`
}
},
{
"type": "divider"
},
{
"type": "header",
"text": {
"type": "plain_text",
"text": "E2E Tests"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `- 🐧 linux: ${report.linux.pass ? "✅" : "❌"}\n - 🪟 windows: ${report.windows.pass ? "✅" : "❌"}\n - 🍏 macos: ${report.mac.pass ? "✅" : "❌"}\n`
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Commit by ${{ github.event.head_commit.author.username || '' }}\nhttps://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
}
]
};
fs.writeFileSync("payload-slack-content.json", JSON.stringify(slackPayload), "utf-8");
- name: post to a Slack channel
id: slack
uses: slackapi/slack-github-action@v1.23.0
if: always() && !cancelled() && github.event_name == 'push' && contains(join(needs.*.result, ','), 'failure')
with:
channel-id: "C05FKJ7DFAP"
payload-file-path: ${{ github.workspace }}/payload-slack-content.json
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_LIVE_CI_BOT_TOKEN }}
- uses: actions/upload-artifact@v3
name: upload summary
with:
name: summary.json
path: ${{ github.workspace }}/summary.json
allure-report:
name: "Allure Reports Export on Server"
needs: [e2e-tests-windows, e2e-tests-linux, e2e-tests-mac]
runs-on: [ledger-live-medium-linux]
if: ${{ always() && !cancelled() && github.ref_name == 'develop' }}
steps:
- name: checkout
uses: actions/checkout@v3
with:
ref: ${{ (github.event_name == 'workflow_dispatch' && (inputs.ref || github.ref_name)) || github.sha }}
- name: Download Allure Report - Windows
uses: actions/download-artifact@v3
with:
name: allure-results-windows
path: allure-results-windows
- name: Download Allure Report - MacOS
uses: actions/download-artifact@v3
with:
name: allure-results-macos
path: allure-results-macos
- name: Download Allure Report - Linux
uses: actions/download-artifact@v3
with:
name: allure-results-linux
path: allure-results-linux
- name: Send Results and Generate Allure Report - Windows
uses: ./tools/actions/composites/upload-allure-report
if: always()
with:
platform: windows
login: ${{ secrets.ALLURE_LOGIN }}
password: ${{ secrets.ALLURE_PASSWORD }}
path: allure-results-windows
- name: Send Results and Generate Allure Report - MacOS
uses: ./tools/actions/composites/upload-allure-report
if: always()
with:
platform: macos
login: ${{ secrets.ALLURE_LOGIN }}
password: ${{ secrets.ALLURE_PASSWORD }}
path: allure-results-macos
- name: Send Results and Generate Allure Report - Linux
uses: ./tools/actions/composites/upload-allure-report
if: always()
with:
platform: linux
login: ${{ secrets.ALLURE_LOGIN }}
password: ${{ secrets.ALLURE_PASSWORD }}
path: allure-results-linux