Skip to content

Commit d1cff32

Browse files
authored
ci: Added ci option for snapshot (#38261)
## Description Adding workflow for updating snapshot with github CI. Fixes #[`36419` ](#36419) ## Automation /ok-to-test tags="@tag.Sanity" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/12426577557> > Commit: 2660c07 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12426577557&attempt=2" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Fri, 20 Dec 2024 07:02:16 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced CI workflow with new input parameters for snapshot updates and spec execution. - Added steps for uploading existing and new snapshot data during Cypress tests. - **Bug Fixes** - Improved artifact management and error handling in the CI process. - **Documentation** - Added comments for better understanding of workflow logic and input parameters. - **Refactor** - Streamlined job execution logic and conditional checks for test reruns. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 71c5171 commit d1cff32

File tree

3 files changed

+72
-7
lines changed

3 files changed

+72
-7
lines changed

.github/workflows/build-client-server-count.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
matrix_count: ${{steps.matrix.outputs.matrix_count}}
1818
run_count: ${{ steps.countArgs.outputs.run_count }}
1919
is-pg-build: ${{steps.args.outputs.is-pg-build}}
20+
update_snapshot: ${{steps.args.outputs.update_snapshot}}
21+
specs_to_run: ${{steps.args.outputs.specs_to_run}}
2022
steps:
2123
- name: Checkout the head commit of the branch
2224
uses: actions/checkout@v4
@@ -38,6 +40,21 @@ jobs:
3840
runId=$((checkArg + 0))
3941
echo "runId=$runId" >> $GITHUB_OUTPUT
4042
fi
43+
44+
# Check for update_snapshot
45+
checkArg=${{ github.event.client_payload.slash_command.args.named.update_snapshot }}
46+
if [[ -z "$checkArg" ]]; then
47+
echo "update_snapshot=false" >> $GITHUB_OUTPUT
48+
else
49+
echo "update_snapshot=$checkArg" >> $GITHUB_OUTPUT
50+
fi
51+
# Check for spec file
52+
checkArg=${{ github.event.client_payload.slash_command.args.named.specs_to_run }}
53+
if [[ -z "$checkArg" ]]; then
54+
echo "specs_to_run=''" >> $GITHUB_OUTPUT
55+
else
56+
echo "specs_to_run=$checkArg" >> $GITHUB_OUTPUT
57+
fi
4158
4259
- name: Set run count
4360
id: countArgs
@@ -97,7 +114,7 @@ jobs:
97114
body: |
98115
Tests running at: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}>.
99116
[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)
100-
PR: #${{ fromJson(steps.args.outputs.pr) }}.
117+
PR: #${{ fromJson(steps.args.outputs.pr) }} with spec: ${{steps.args.outputs.specs_to_run}} .
101118
102119
server-build:
103120
name: server-build
@@ -149,6 +166,8 @@ jobs:
149166
with:
150167
pr: ${{fromJson(needs.file-check.outputs.pr)}}
151168
run_count: ${{fromJson(needs.file-check.outputs.run_count)}}
169+
update_snapshot: ${{fromJson(needs.file-check.outputs.update_snapshot)}}
170+
specs_to_run: ${{needs.file-check.outputs.specs_to_run}}
152171

153172

154173
ci-test-limited-existing-docker-image:
@@ -162,6 +181,8 @@ jobs:
162181
pr: ${{fromJson(needs.file-check.outputs.pr)}}
163182
previous-workflow-run-id: ${{ fromJson(needs.file-check.outputs.runId) }}
164183
run_count: ${{fromJson(needs.file-check.outputs.run_count)}}
184+
update_snapshot: ${{fromJson(needs.file-check.outputs.update_snapshot)}}
185+
specs_to_run: ${{needs.file-check.outputs.specs_to_run}}
165186

166187
ci-test-limited-result:
167188
needs: [file-check, ci-test-limited]

.github/workflows/ci-test-limited-with-count.yml

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ on:
1919
required: false
2020
type: number
2121
default: 1
22+
update_snapshot:
23+
description: 'Give option to update snapshot (true/false)'
24+
required: false
25+
type: boolean
26+
default: false
27+
specs_to_run:
28+
description: 'Cypress spec file(s) to run'
29+
required: false
30+
type: string
31+
2232
workflow_call:
2333
inputs:
2434
pr:
@@ -35,6 +45,15 @@ on:
3545
required: false
3646
type: number
3747
default: 1
48+
update_snapshot:
49+
description: 'Give option to update snapshot (true/false)'
50+
required: false
51+
type: boolean
52+
default: false
53+
specs_to_run:
54+
description: 'Cypress spec file(s) to run'
55+
required: false
56+
type: string
3857

3958
jobs:
4059
ci-test-limited:
@@ -111,10 +130,18 @@ jobs:
111130
else
112131
echo "rerun=false" >> $GITHUB_OUTPUT
113132
fi
133+
134+
- name: Upload existing snapshot data
135+
if: always()
136+
uses: actions/upload-artifact@v4
137+
with:
138+
name: cypress-existing-compare-snapshots
139+
path: ${{ github.workspace }}/app/client/cypress/snapshots
140+
overwrite: true
114141

115142
# Get specs to run
116143
- name: Get specs to run
117-
if: steps.run_result.outputs.run_result != 'success' && steps.run_result.outputs.run_result != 'failedtest'
144+
if: ${{ (inputs.specs_to_run == '' || inputs.specs_to_run == null) && steps.run_result.outputs.run_result != 'success' && steps.run_result.outputs.run_result != 'failedtest' }}
118145
run: |
119146
specs_to_run=""
120147
while IFS= read -r line
@@ -349,10 +376,19 @@ jobs:
349376
NODE_ENV: development
350377
run: |
351378
cd app/client
352-
npx cypress-repeat-pro run -n ${{ inputs.run_count }} --force \
353-
--spec ${{ env.specs_to_run }} \
379+
if [[ "${{ inputs.update_snapshot }}" == "true" ]]; then
380+
echo "Running Cypress with snapshot updates..."
381+
CYPRESS_updateSnapshots=true npx cypress-repeat-pro run -n "${{ inputs.run_count }}" --force \
382+
--spec "${{ inputs.specs_to_run }}" \
354383
--config-file "cypress_ci_custom.config.ts" \
355-
--browser ${{ env.BROWSER_PATH }}
384+
--browser "${{ env.BROWSER_PATH }}"
385+
else
386+
echo "Running Cypress tests without snapshot updates..."
387+
npx cypress-repeat-pro run -n "${{ inputs.run_count }}" --force \
388+
--spec "${{ env.specs_to_run }}" \
389+
--config-file "cypress_ci_custom.config.ts" \
390+
--browser "${{ env.BROWSER_PATH }}"
391+
fi
356392
cat cy-repeat-summary.txt
357393
# Define the path for the failure flag file
358394
FAILURE_FLAG_FILE="ci_test_status.txt"
@@ -453,9 +489,17 @@ jobs:
453489
if: always()
454490
with:
455491
name: server-logs
456-
path: app/server/server-logs.log
492+
path: ${{ github.workspace }}/app/server/server-logs.log
457493
overwrite: true
458494

495+
- name: Upload new compared snapshot data
496+
if: always()
497+
uses: actions/upload-artifact@v4
498+
with:
499+
name: cypress-new-compare-snapshots
500+
path: ${{ github.workspace }}/app/client/cypress/snapshots
501+
overwrite: true
502+
459503
# Set status = success
460504
- name: Save the status of the run
461505
run: |

.github/workflows/ci-test-limited.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ jobs:
418418
if: failure()
419419
with:
420420
name: server-logs
421-
path: app/server/server-logs.log
421+
path: ${{ github.workspace }}/app/server/server-logs.log
422422
overwrite: true
423423

424424
# Set status = success

0 commit comments

Comments
 (0)