forked from appsmithorg/appsmith
-
Notifications
You must be signed in to change notification settings - Fork 0
767 lines (687 loc) · 32 KB
/
Copy pathbuild-client-server.yml
File metadata and controls
767 lines (687 loc) · 32 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
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
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
name: Build Client, Server & Run only Cypress
on:
repository_dispatch:
types: [ci-test-limit-command, approve-ci-command]
concurrency:
group: trusted-pr-ci-${{ github.event.client_payload.pull_request.number }}
cancel-in-progress: true
permissions:
actions: read
contents: read
issues: write
packages: write
pull-requests: write
jobs:
file-check:
runs-on: ubuntu-latest
# Set job outputs to values from filter step
outputs:
non_ts_files: ${{ steps.check_files.outputs.non_ts_files }}
non_ts_files_count: ${{ steps.check_files.outputs.non_ts_files_count }}
pr: ${{steps.args.outputs.pr}}
runId: ${{steps.args.outputs.runId}}
matrix_count: ${{steps.matrix.outputs.matrix_count}}
is-pg-build: ${{steps.args.outputs.is-pg-build}}
merge_sha: ${{ steps.approved.outputs.merge_sha }}
steps:
- name: Checkout the PR merge commit
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.client_payload.pull_request.number }}/merge
fetch-depth: 2
- name: Verify the commit approved by the maintainer
id: approved
env:
APPROVED_HEAD_SHA: ${{ github.event.client_payload.pull_request.head.sha }}
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.client_payload.pull_request.number }}
EVENT_ACTION: ${{ github.event.action }}
run: |
current_head_sha="$(
gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}" --jq .head.sha
)"
checked_out_head_sha="$(git rev-parse HEAD^2)"
if [[ "$EVENT_ACTION" == "approve-ci-command" ]]; then
command_name="/approve-ci"
else
command_name="/ci-test-limit"
fi
if [[ "$current_head_sha" != "$APPROVED_HEAD_SHA" ]]; then
echo "::error::PR head changed after ${command_name} was issued. Re-run ${command_name} on the current commit."
if [[ "$EVENT_ACTION" == "approve-ci-command" ]]; then
gh pr comment "$PR_NUMBER" --body "Approval expired: the PR head changed after \`/approve-ci\` was issued (approved \`${APPROVED_HEAD_SHA:0:7}\`, current \`${current_head_sha:0:7}\`). Please re-run \`/approve-ci\` on the latest commit. If Cypress should run on that approval, keep the \`ok-to-test\` label (and optional \`tags=\` on the command or in the PR body)."
fi
exit 1
fi
if [[ "$checked_out_head_sha" != "$APPROVED_HEAD_SHA" ]]; then
echo "::error::The checked-out merge commit does not contain the approved PR head."
exit 1
fi
echo "merge_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
echo "Approved head: $APPROVED_HEAD_SHA" >> "$GITHUB_STEP_SUMMARY"
echo "Pinned merge commit: $(git rev-parse HEAD)" >> "$GITHUB_STEP_SUMMARY"
- name: Record privileged CI approval
if: github.event.action == 'approve-ci-command'
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const issue_number = context.payload.client_payload.pull_request.number;
await github.rest.issues.addLabels({
owner,
repo,
issue_number,
labels: ["ci-approved"],
});
try {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number,
name: "awaiting-maintainer",
});
} catch (error) {
if (error.status !== 404) throw error;
}
- name: Set matrix jobs
id: matrix
run: |
echo "matrix_count=[0, 1, 2]" >> $GITHUB_OUTPUT
- name: Set args
id: args
env:
EVENT_ACTION: ${{ github.event.action }}
NAMED_ARGS: ${{ toJSON(github.event.client_payload.slash_command.args.named) }}
run: |
echo "pr=${{ github.event.client_payload.pull_request.number }}" >> $GITHUB_OUTPUT
echo "is-pg-build=${{ github.event.client_payload.pull_request.base.ref == 'pg' }}" >> $GITHUB_OUTPUT
run_id="$(printf '%s' "$NAMED_ARGS" | jq -r 'if type == "object" and has("runId") then (.runId | tostring) else "0" end')"
# runId reuses the Docker image from an earlier run. /approve-ci exists to
# test the maintainer-approved merge commit, so an image built from some
# other commit would report that commit as validated without ever building
# it. Refuse the shortcut here instead of honouring it.
if [[ "$EVENT_ACTION" == 'approve-ci-command' && "$run_id" != '0' ]]; then
echo "::warning::Ignoring runId=${run_id}: /approve-ci always builds and tests the approved commit."
run_id='0'
fi
echo "runId=$run_id" >> "$GITHUB_OUTPUT"
- name: Get the diff from base branch
continue-on-error: true
id: files
env:
BASE_REF: ${{ github.event.client_payload.pull_request.base.ref }}
run: |
git fetch origin "$BASE_REF"
git diff --name-only --diff-filter=A "remotes/origin/${BASE_REF}...HEAD" -- 'app/client/cypress/e2e' > diff
echo "files_added=$(cat diff)" >> $GITHUB_OUTPUT
cat diff
- name: Check the newly added files are written in ts
id: check_files
run: |
files=(${{steps.files.outputs.files_added}})
non_ts_files=()
for file in "${files[@]}"; do
if [[ $file != *.ts ]]; then
non_ts_files+=("<li> $file")
fi
done
echo "non_ts_files=${non_ts_files[@]}" >> $GITHUB_OUTPUT
echo "non_ts_files_count=${#non_ts_files[@]}" >> $GITHUB_OUTPUT
- name: Print the files
if: steps.check_files.outputs.non_ts_files_count != 0 && steps.args.outputs.pr == '0'
run: |
echo "${{ steps.check_files.outputs.non_ts_files }}"
- name: Comment the filenames if PR is there
if: steps.check_files.outputs.non_ts_files_count != 0 && steps.args.outputs.pr != '0'
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ fromJson(steps.args.outputs.pr) }}
body: |
<b>Below new test files are written in js 🔴 </b>
<b>Expected format ts. Please fix and retrigger ci-test-limit:</b>
<ol>${{ steps.check_files.outputs.non_ts_files }}</ol>
- if: steps.check_files.outputs.non_ts_files_count != 0
run: exit 1
- name: Add a comment on the PR with link to workflow run
if: success() && steps.args.outputs.pr != '0'
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ fromJson(steps.args.outputs.pr) }}
body: |
Tests running at: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}>.
[Cypress dashboard](https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=${{ github.run_id }}&attempt=${{ github.run_attempt }}&selectiontype=test&testsstatus=failed&specsstatus=fail)
PR: #${{ fromJson(steps.args.outputs.pr) }}.
cypress-scope:
needs: [file-check]
if: success()
runs-on: ubuntu-latest
outputs:
run_full_cypress: ${{ steps.scope.outputs.run_full_cypress }}
tags: ${{ steps.scope.outputs.tags }}
spec: ${{ steps.scope.outputs.spec }}
cypress_matrix: ${{ steps.scope.outputs.cypress_matrix }}
steps:
# Trusted checkout: the tag grammar and tag list must never come from the fork.
- uses: actions/checkout@v4
with:
repository: appsmithorg/appsmith
- name: Resolve Cypress scope for approved CI
id: scope
env:
NODE_PATH: ${{ github.workspace }}/.github/workflows/scripts
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const issue_number = context.payload.client_payload.pull_request.number;
const isApproveCi = context.payload.action === "approve-ci-command";
const labels = await github.paginate(
github.rest.issues.listLabelsOnIssue,
{ owner, repo, issue_number },
);
const hasOkToTest = labels.some((label) => label.name === "ok-to-test");
const commandTags = (
context.payload.client_payload.slash_command?.args?.named?.tags || ""
).trim();
// Full Cypress only on /approve-ci when the label is present and/or tags= is given.
const runFull = isApproveCi && (hasOkToTest || commandTags.length > 0);
core.setOutput("run_full_cypress", runFull ? "true" : "false");
if (!runFull) {
core.setOutput("tags", "");
core.setOutput("spec", "");
core.setOutput("cypress_matrix", "[0]");
return;
}
const { data: freshPr } = await github.rest.pulls.get({
owner,
repo,
pull_number: issue_number,
});
// Precedence: command args → PR body → @tag.All (label default).
let bodyForParse = freshPr.body || "";
if (commandTags) {
bodyForParse = `/ok-to-test tags="${commandTags}"\n`;
}
const captured = { tags: "", its: "", spec: "" };
let failedMessage = null;
const shimCore = {
setOutput(name, value) {
captured[name] = value ?? "";
},
setFailed(message) {
failedMessage = message;
},
};
// Suppress write-cypress-status side effects on the fall-through path
// (invalid body tags → default @tag.All) so we don't warn then run All.
const shimGithub = commandTags
? github
: {
...github,
rest: {
...github.rest,
pulls: {
...github.rest.pulls,
async get(...args) {
return github.rest.pulls.get(...args);
},
async update() {
return { data: {} };
},
},
issues: {
...github.rest.issues,
async createComment() {
return { data: {} };
},
},
},
};
if (bodyForParse.trim()) {
require("test-tag-parser.js")({
core: shimCore,
context: {
...context,
payload: {
...context.payload,
pull_request: {
...freshPr,
body: bodyForParse,
},
},
},
github: shimGithub,
});
}
if (failedMessage) {
if (commandTags) {
// Explicit tags on the command must be valid.
core.setFailed(failedMessage);
return;
}
// Unparseable PR body falls through to the label default without warning.
console.log(`PR body tag parse skipped: ${failedMessage}`);
}
let tags = captured.tags || "";
const spec = captured.spec || "";
if (!tags && !spec) {
tags = "@tag.All";
}
let cypress_matrix;
if (spec) {
cypress_matrix = "[0]";
} else if (tags === "@tag.All") {
cypress_matrix =
"[0, 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]";
} else {
cypress_matrix =
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]";
}
core.setOutput("tags", tags);
core.setOutput("spec", spec);
core.setOutput("cypress_matrix", cypress_matrix);
console.log(
`Cypress scope: run_full=${runFull} tags=${tags || "(none)"} spec=${spec || "(none)"}`,
);
server-build:
name: server-build
needs: [file-check]
if: success() && needs.file-check.outputs.runId == '0'
uses: ./.github/workflows/server-build.yml
secrets: inherit
with:
pr: ${{fromJson(needs.file-check.outputs.pr)}}
checkout-ref: ${{ needs.file-check.outputs.merge_sha }}
skip-tests: "true"
is-pg-build: ${{fromJson(needs.file-check.outputs.is-pg-build)}}
client-build:
name: client-build
needs: [file-check]
if: success() && needs.file-check.outputs.runId == '0'
uses: ./.github/workflows/client-build.yml
secrets: inherit
with:
pr: ${{fromJson(needs.file-check.outputs.pr)}}
checkout-ref: ${{ needs.file-check.outputs.merge_sha }}
skip-tests: "true"
mcp-build:
name: mcp-build
needs: [file-check]
if: success() && needs.file-check.outputs.runId == '0'
uses: ./.github/workflows/mcp-build.yml
secrets: inherit
with:
pr: ${{fromJson(needs.file-check.outputs.pr)}}
rts-build:
name: rts-build
needs: [file-check]
if: success() && needs.file-check.outputs.runId == '0'
uses: ./.github/workflows/rts-build.yml
secrets: inherit
with:
pr: ${{fromJson(needs.file-check.outputs.pr)}}
checkout-ref: ${{ needs.file-check.outputs.merge_sha }}
build-docker-image:
needs: [file-check, client-build, server-build, mcp-build, rts-build]
# Only run if the build step is successful
if: success() && needs.file-check.outputs.runId == '0'
name: build-docker-image
uses: ./.github/workflows/build-docker-image.yml
secrets: inherit
with:
pr: ${{fromJson(needs.file-check.outputs.pr)}}
checkout-ref: ${{ needs.file-check.outputs.merge_sha }}
ci-test-limited:
needs: [file-check, cypress-scope, build-docker-image]
# Only run if the build step is successful and full Cypress was not selected
if: success() && needs.file-check.outputs.runId == '0' && needs.cypress-scope.outputs.run_full_cypress != 'true'
name: ci-test-limited
uses: ./.github/workflows/ci-test-limited.yml
secrets: inherit
with:
pr: ${{fromJson(needs.file-check.outputs.pr)}}
checkout-ref: ${{ needs.file-check.outputs.merge_sha }}
ci-test-full:
needs: [file-check, cypress-scope, build-docker-image]
# Sharded Cypress suite for /approve-ci when ok-to-test and/or tags= are present
if: success() && needs.file-check.outputs.runId == '0' && needs.cypress-scope.outputs.run_full_cypress == 'true'
name: ci-test-full
uses: ./.github/workflows/ci-test-custom-script.yml
secrets: inherit
with:
pr: ${{fromJson(needs.file-check.outputs.pr)}}
checkout-ref: ${{ needs.file-check.outputs.merge_sha }}
tags: ${{ needs.cypress-scope.outputs.tags }}
spec: ${{ needs.cypress-scope.outputs.spec }}
matrix: ${{ needs.cypress-scope.outputs.cypress_matrix }}
ci-test-limited-existing-docker-image:
needs: [file-check, cypress-scope]
# Only for /ci-test-limit with a prior runId — not used for full Cypress
if: success() && needs.file-check.outputs.runId != '0' && needs.cypress-scope.outputs.run_full_cypress != 'true'
name: ci-test-limited-existing-image
uses: ./.github/workflows/ci-test-limited.yml
secrets: inherit
with:
pr: ${{fromJson(needs.file-check.outputs.pr)}}
checkout-ref: ${{ needs.file-check.outputs.merge_sha }}
previous-workflow-run-id: ${{ fromJson(needs.file-check.outputs.runId) }}
ci-test-limited-result:
needs: [file-check, cypress-scope, ci-test-limited]
# Only run if the file-check.runId == 0 and limited path was selected
if: always() && needs.file-check.outputs.runId == '0' && needs.cypress-scope.outputs.run_full_cypress != 'true'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Setup node
if: needs.ci-test-limited.result != 'success'
uses: actions/setup-node@v4
with:
node-version-file: app/client/package.json
- name: install pg
if: needs.ci-test-limited.result != 'success'
run: npm install pg
- name: Fetch the failed specs
if: needs.ci-test-limited.result != 'success'
id: failed_specs
env:
DB_HOST: ${{ secrets.CYPRESS_DB_HOST }}
DB_NAME: ${{ secrets.CYPRESS_DB_NAME }}
DB_USER: ${{ secrets.CYPRESS_DB_USER }}
DB_PWD: ${{ secrets.CYPRESS_DB_PWD }}
RUN_ID: ${{ github.run_id }}
ATTEMPT_NUMBER: ${{ github.run_attempt }}
uses: actions/github-script@v7
with:
script: |
const { Pool } = require("pg");
const { DB_HOST, DB_NAME, DB_USER, DB_PWD, RUN_ID, ATTEMPT_NUMBER } = process.env
const client = await new Pool({
user: DB_USER,
host: DB_HOST,
database: DB_NAME,
password: DB_PWD,
port: 5432,
connectionTimeoutMillis: 60000,
}).connect();
const result = await client.query(
`SELECT DISTINCT name FROM public."specs"
WHERE "matrixId" IN
(SELECT id FROM public."matrix"
WHERE "attemptId" = (
SELECT id FROM public."attempt" WHERE "workflowId" = $1 and "attempt" = $2
)
) AND status = 'fail'`,
[RUN_ID, ATTEMPT_NUMBER],
);
client.release();
return result.rows.map((spec) => spec.name);
# In case for any ci job failure, create combined failed spec
- name: combine all specs for CI
id: combine_ci
if: needs.ci-test-limited.result != 'success'
run: |
failed_specs=$(echo ${{steps.failed_specs.outputs.result}} | sed 's/\[\|\]//g' | tr -d ' ' | tr ',' '\n')
while read -r line; do
echo "$line" >> ~/combined_failed_spec_ci
done <<< "$failed_specs"
# Upload combined failed CI spec list to a file
# This is done for debugging.
- name: upload combined failed spec
if: needs.ci-test-limited.result != 'success'
uses: actions/upload-artifact@v4
with:
name: combined_failed_spec_ci
path: ~/combined_failed_spec_ci
overwrite: true
- name: Get Latest flaky Tests
shell: bash
run: |
touch ~/knownfailures
# Verify CI test failures against known failures
- name: Verify CI test failures against known failures
if: needs.ci-test-limited.result != 'success'
shell: bash
run: |
new_failed_spec_env="<ol>$(comm -1 -3 <(sort ~/knownfailures) <(sort -u ~/combined_failed_spec_ci) | sed 's/|cypress|cypress/\n/g' | sed 's/^/<li>/')</ol>"
echo "$new_failed_spec_env"
echo "new_failed_spec_env<<EOF" >> $GITHUB_ENV
echo "$new_failed_spec_env" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Add a comment on the PR with new CI failures
if: needs.ci-test-limited.result != 'success' && needs.file-check.outputs.pr != '0'
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{fromJson(needs.file-check.outputs.pr)}}
body: |
Workflow run: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}>.
Cypress dashboard: <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=${{ github.run_id }}&attempt=${{ github.run_attempt }}&selectiontype=test&testsstatus=failed&specsstatus=fail" target="_blank"> Click here!</a>
The following are new failures, please fix them before merging the PR: ${{env.new_failed_spec_env}}
To know the list of identified flaky tests - <a href="https://internal.appsmith.com/app/cypress-dashboard/identified-flaky-tests-65890b3c81d7400d08fa9ee3?branch=master" target="_blank">Refer here</a>
- name: Add a comment on the PR when ci-test-limited is success
if: needs.ci-test-limited.result == 'success' && needs.file-check.outputs.pr != '0'
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{fromJson(needs.file-check.outputs.pr)}}
body: |
Workflow run: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}>.
Cypress dashboard url: <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=${{ github.run_id }}&attempt=${{ github.run_attempt }}" target="_blank">Click here!</a>
All cypress tests have passed 🎉🎉🎉
- name: Check ci-test-limited set status
if: needs.ci-test-limited.result != 'success'
run: exit 1
ci-test-full-result:
needs: [file-check, cypress-scope, ci-test-full]
# Only run if the file-check.runId == 0 and full Cypress path was selected
if: always() && needs.file-check.outputs.runId == '0' && needs.cypress-scope.outputs.run_full_cypress == 'true'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Setup node
if: needs.ci-test-full.result != 'success'
uses: actions/setup-node@v4
with:
node-version-file: app/client/package.json
- name: install pg
if: needs.ci-test-full.result != 'success'
run: npm install pg
- name: Fetch the failed specs
if: needs.ci-test-full.result != 'success'
id: failed_specs
env:
DB_HOST: ${{ secrets.CYPRESS_DB_HOST }}
DB_NAME: ${{ secrets.CYPRESS_DB_NAME }}
DB_USER: ${{ secrets.CYPRESS_DB_USER }}
DB_PWD: ${{ secrets.CYPRESS_DB_PWD }}
RUN_ID: ${{ github.run_id }}
ATTEMPT_NUMBER: ${{ github.run_attempt }}
uses: actions/github-script@v7
with:
script: |
const { Pool } = require("pg");
const { DB_HOST, DB_NAME, DB_USER, DB_PWD, RUN_ID, ATTEMPT_NUMBER } = process.env
const client = await new Pool({
user: DB_USER,
host: DB_HOST,
database: DB_NAME,
password: DB_PWD,
port: 5432,
connectionTimeoutMillis: 60000,
}).connect();
const result = await client.query(
`SELECT DISTINCT name FROM public."specs"
WHERE "matrixId" IN
(SELECT id FROM public."matrix"
WHERE "attemptId" = (
SELECT id FROM public."attempt" WHERE "workflowId" = $1 and "attempt" = $2
)
) AND status = 'fail'`,
[RUN_ID, ATTEMPT_NUMBER],
);
client.release();
return result.rows.map((spec) => spec.name);
# In case for any ci job failure, create combined failed spec
- name: combine all specs for CI
id: combine_ci
if: needs.ci-test-full.result != 'success'
run: |
failed_specs=$(echo ${{steps.failed_specs.outputs.result}} | sed 's/\[\|\]//g' | tr -d ' ' | tr ',' '\n')
while read -r line; do
echo "$line" >> ~/combined_failed_spec_ci
done <<< "$failed_specs"
# Upload combined failed CI spec list to a file
# This is done for debugging.
- name: upload combined failed spec
if: needs.ci-test-full.result != 'success'
uses: actions/upload-artifact@v4
with:
name: combined_failed_spec_ci
path: ~/combined_failed_spec_ci
overwrite: true
- name: Get Latest flaky Tests
shell: bash
run: |
touch ~/knownfailures
# Verify CI test failures against known failures
- name: Verify CI test failures against known failures
if: needs.ci-test-full.result != 'success'
shell: bash
run: |
new_failed_spec_env="<ol>$(comm -1 -3 <(sort ~/knownfailures) <(sort -u ~/combined_failed_spec_ci) | sed 's/|cypress|cypress/\n/g' | sed 's/^/<li>/')</ol>"
echo "$new_failed_spec_env"
echo "new_failed_spec_env<<EOF" >> $GITHUB_ENV
echo "$new_failed_spec_env" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Add a comment on the PR with new CI failures
if: needs.ci-test-full.result != 'success' && needs.file-check.outputs.pr != '0'
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{fromJson(needs.file-check.outputs.pr)}}
body: |
Workflow run: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}>.
Cypress dashboard: <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=${{ github.run_id }}&attempt=${{ github.run_attempt }}&selectiontype=test&testsstatus=failed&specsstatus=fail" target="_blank"> Click here!</a>
The following are new failures, please fix them before merging the PR: ${{env.new_failed_spec_env}}
To know the list of identified flaky tests - <a href="https://internal.appsmith.com/app/cypress-dashboard/identified-flaky-tests-65890b3c81d7400d08fa9ee3?branch=master" target="_blank">Refer here</a>
- name: Add a comment on the PR when ci-test-full is success
if: needs.ci-test-full.result == 'success' && needs.file-check.outputs.pr != '0'
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{fromJson(needs.file-check.outputs.pr)}}
body: |
Workflow run: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}>.
Cypress dashboard url: <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=${{ github.run_id }}&attempt=${{ github.run_attempt }}" target="_blank">Click here!</a>
All cypress tests have passed 🎉🎉🎉
- name: Check ci-test-full set status
if: needs.ci-test-full.result != 'success'
run: exit 1
ci-test-limited-result-existing:
needs: [file-check, cypress-scope, ci-test-limited-existing-docker-image]
# Only run if the file-check.runId !=0 and limited path was selected
if: always() && needs.file-check.outputs.runId != '0' && needs.cypress-scope.outputs.run_full_cypress != 'true'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Setup node
if: needs.ci-test-limited-existing-docker-image.result != 'success'
uses: actions/setup-node@v4
with:
node-version-file: app/client/package.json
- name: install pg
if: needs.ci-test-limited-existing-docker-image.result != 'success'
run: npm install pg
- name: Fetch the failed specs
if: needs.ci-test-limited-existing-docker-image.result != 'success'
id: failed_specs
env:
DB_HOST: ${{ secrets.CYPRESS_DB_HOST }}
DB_NAME: ${{ secrets.CYPRESS_DB_NAME }}
DB_USER: ${{ secrets.CYPRESS_DB_USER }}
DB_PWD: ${{ secrets.CYPRESS_DB_PWD }}
RUN_ID: ${{ github.run_id }}
ATTEMPT_NUMBER: ${{ github.run_attempt }}
uses: actions/github-script@v7
with:
script: |
const { Pool } = require("pg");
const { DB_HOST, DB_NAME, DB_USER, DB_PWD, RUN_ID, ATTEMPT_NUMBER } = process.env
const client = await new Pool({
user: DB_USER,
host: DB_HOST,
database: DB_NAME,
password: DB_PWD,
port: 5432,
connectionTimeoutMillis: 60000,
}).connect();
const result = await client.query(
`SELECT DISTINCT name FROM public."specs"
WHERE "matrixId" IN
(SELECT id FROM public."matrix"
WHERE "attemptId" = (
SELECT id FROM public."attempt" WHERE "workflowId" = $1 and "attempt" = $2
)
) AND status = 'fail'`,
[RUN_ID, ATTEMPT_NUMBER],
);
client.release();
return result.rows.map((spec) => spec.name);
# In case for any ci job failure, create combined failed spec
- name: combine all specs for CI
id: combine_ci
if: needs.ci-test-limited-existing-docker-image.result != 'success'
run: |
failed_specs=$(echo ${{steps.failed_specs.outputs.result}} | sed 's/\[\|\]//g' | tr -d ' ' | tr ',' '\n')
while read -r line; do
echo "$line" >> ~/combined_failed_spec_ci
done <<< "$failed_specs"
# Upload combined failed CI spec list to a file
# This is done for debugging.
- name: upload combined failed spec
if: needs.ci-test-limited-existing-docker-image.result != 'success'
uses: actions/upload-artifact@v4
with:
name: combined_failed_spec_ci
path: ~/combined_failed_spec_ci
overwrite: true
- name: Get Latest flaky Tests
shell: bash
run: |
touch ~/knownfailures
# Verify CI test failures against known failures
- name: Verify CI test failures against known failures
if: needs.ci-test-limited-existing-docker-image.result != 'success'
shell: bash
run: |
new_failed_spec_env="<ol>$(comm -1 -3 <(sort ~/knownfailures) <(sort -u ~/combined_failed_spec_ci) | sed 's/|cypress|cypress/\n/g' | sed 's/^/<li>/')</ol>"
echo "$new_failed_spec_env"
echo "new_failed_spec_env<<EOF" >> $GITHUB_ENV
echo "$new_failed_spec_env" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Add a comment on the PR with new CI failures
if: needs.ci-test-limited-existing-docker-image.result != 'success' && needs.file-check.outputs.pr != '0'
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{fromJson(needs.file-check.outputs.pr)}}
body: |
Workflow run: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}>.
Cypress dashboard: <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=${{ github.run_id }}&attempt=${{ github.run_attempt }}&selectiontype=test&testsstatus=failed&specsstatus=fail" target="_blank"> Click here!</a>
The following are new failures, please fix them before merging the PR: ${{env.new_failed_spec_env}}
To know the list of identified flaky tests - <a href="https://internal.appsmith.com/app/cypress-dashboard/identified-flaky-tests-65890b3c81d7400d08fa9ee3?branch=master" target="_blank">Refer here</a>
- name: Add a comment on the PR when ci-test-limited-existing-docker-image is success
if: needs.ci-test-limited-existing-docker-image.result == 'success' && needs.file-check.outputs.pr != '0'
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{fromJson(needs.file-check.outputs.pr)}}
body: |
Workflow run: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}>.
Cypress dashboard url: <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=${{ github.run_id }}&attempt=${{ github.run_attempt }}" target="_blank">Click here!</a>
All cypress tests have passed 🎉🎉🎉
- name: Check ci-test-limited-existing-docker-image set status
if: needs.ci-test-limited-existing-docker-image.result != 'success'
run: exit 1