From d1cff32d2b363aa640222430d88e3b64ed370052 Mon Sep 17 00:00:00 2001 From: Sagar Khalasi Date: Fri, 20 Dec 2024 12:37:42 +0530 Subject: [PATCH] ci: Added ci option for snapshot (#38261) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Adding workflow for updating snapshot with github CI. Fixes #[`36419` ](https://github.com/appsmithorg/appsmith/issues/36419) ## Automation /ok-to-test tags="@tag.Sanity" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: 2660c07257f3d78f64371cedc2ee82f247f9d76d > Cypress dashboard. > Tags: `@tag.Sanity` > Spec: >
Fri, 20 Dec 2024 07:02:16 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No ## 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. --- .../workflows/build-client-server-count.yml | 23 +++++++- .../workflows/ci-test-limited-with-count.yml | 54 +++++++++++++++++-- .github/workflows/ci-test-limited.yml | 2 +- 3 files changed, 72 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-client-server-count.yml b/.github/workflows/build-client-server-count.yml index c15a92947b0c..0b78fa2dbda7 100644 --- a/.github/workflows/build-client-server-count.yml +++ b/.github/workflows/build-client-server-count.yml @@ -17,6 +17,8 @@ jobs: matrix_count: ${{steps.matrix.outputs.matrix_count}} run_count: ${{ steps.countArgs.outputs.run_count }} is-pg-build: ${{steps.args.outputs.is-pg-build}} + update_snapshot: ${{steps.args.outputs.update_snapshot}} + specs_to_run: ${{steps.args.outputs.specs_to_run}} steps: - name: Checkout the head commit of the branch uses: actions/checkout@v4 @@ -38,6 +40,21 @@ jobs: runId=$((checkArg + 0)) echo "runId=$runId" >> $GITHUB_OUTPUT fi + + # Check for update_snapshot + checkArg=${{ github.event.client_payload.slash_command.args.named.update_snapshot }} + if [[ -z "$checkArg" ]]; then + echo "update_snapshot=false" >> $GITHUB_OUTPUT + else + echo "update_snapshot=$checkArg" >> $GITHUB_OUTPUT + fi + # Check for spec file + checkArg=${{ github.event.client_payload.slash_command.args.named.specs_to_run }} + if [[ -z "$checkArg" ]]; then + echo "specs_to_run=''" >> $GITHUB_OUTPUT + else + echo "specs_to_run=$checkArg" >> $GITHUB_OUTPUT + fi - name: Set run count id: countArgs @@ -97,7 +114,7 @@ jobs: 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) }}. + PR: #${{ fromJson(steps.args.outputs.pr) }} with spec: ${{steps.args.outputs.specs_to_run}} . server-build: name: server-build @@ -149,6 +166,8 @@ jobs: with: pr: ${{fromJson(needs.file-check.outputs.pr)}} run_count: ${{fromJson(needs.file-check.outputs.run_count)}} + update_snapshot: ${{fromJson(needs.file-check.outputs.update_snapshot)}} + specs_to_run: ${{needs.file-check.outputs.specs_to_run}} ci-test-limited-existing-docker-image: @@ -162,6 +181,8 @@ jobs: pr: ${{fromJson(needs.file-check.outputs.pr)}} previous-workflow-run-id: ${{ fromJson(needs.file-check.outputs.runId) }} run_count: ${{fromJson(needs.file-check.outputs.run_count)}} + update_snapshot: ${{fromJson(needs.file-check.outputs.update_snapshot)}} + specs_to_run: ${{needs.file-check.outputs.specs_to_run}} ci-test-limited-result: needs: [file-check, ci-test-limited] diff --git a/.github/workflows/ci-test-limited-with-count.yml b/.github/workflows/ci-test-limited-with-count.yml index f987d90e0e07..7179819b2fd9 100644 --- a/.github/workflows/ci-test-limited-with-count.yml +++ b/.github/workflows/ci-test-limited-with-count.yml @@ -19,6 +19,16 @@ on: required: false type: number default: 1 + update_snapshot: + description: 'Give option to update snapshot (true/false)' + required: false + type: boolean + default: false + specs_to_run: + description: 'Cypress spec file(s) to run' + required: false + type: string + workflow_call: inputs: pr: @@ -35,6 +45,15 @@ on: required: false type: number default: 1 + update_snapshot: + description: 'Give option to update snapshot (true/false)' + required: false + type: boolean + default: false + specs_to_run: + description: 'Cypress spec file(s) to run' + required: false + type: string jobs: ci-test-limited: @@ -111,10 +130,18 @@ jobs: else echo "rerun=false" >> $GITHUB_OUTPUT fi + + - name: Upload existing snapshot data + if: always() + uses: actions/upload-artifact@v4 + with: + name: cypress-existing-compare-snapshots + path: ${{ github.workspace }}/app/client/cypress/snapshots + overwrite: true # Get specs to run - name: Get specs to run - if: steps.run_result.outputs.run_result != 'success' && steps.run_result.outputs.run_result != 'failedtest' + if: ${{ (inputs.specs_to_run == '' || inputs.specs_to_run == null) && steps.run_result.outputs.run_result != 'success' && steps.run_result.outputs.run_result != 'failedtest' }} run: | specs_to_run="" while IFS= read -r line @@ -349,10 +376,19 @@ jobs: NODE_ENV: development run: | cd app/client - npx cypress-repeat-pro run -n ${{ inputs.run_count }} --force \ - --spec ${{ env.specs_to_run }} \ + if [[ "${{ inputs.update_snapshot }}" == "true" ]]; then + echo "Running Cypress with snapshot updates..." + CYPRESS_updateSnapshots=true npx cypress-repeat-pro run -n "${{ inputs.run_count }}" --force \ + --spec "${{ inputs.specs_to_run }}" \ --config-file "cypress_ci_custom.config.ts" \ - --browser ${{ env.BROWSER_PATH }} + --browser "${{ env.BROWSER_PATH }}" + else + echo "Running Cypress tests without snapshot updates..." + npx cypress-repeat-pro run -n "${{ inputs.run_count }}" --force \ + --spec "${{ env.specs_to_run }}" \ + --config-file "cypress_ci_custom.config.ts" \ + --browser "${{ env.BROWSER_PATH }}" + fi cat cy-repeat-summary.txt # Define the path for the failure flag file FAILURE_FLAG_FILE="ci_test_status.txt" @@ -453,9 +489,17 @@ jobs: if: always() with: name: server-logs - path: app/server/server-logs.log + path: ${{ github.workspace }}/app/server/server-logs.log overwrite: true + - name: Upload new compared snapshot data + if: always() + uses: actions/upload-artifact@v4 + with: + name: cypress-new-compare-snapshots + path: ${{ github.workspace }}/app/client/cypress/snapshots + overwrite: true + # Set status = success - name: Save the status of the run run: | diff --git a/.github/workflows/ci-test-limited.yml b/.github/workflows/ci-test-limited.yml index 5461d5469f35..e6be6dcdaf8c 100644 --- a/.github/workflows/ci-test-limited.yml +++ b/.github/workflows/ci-test-limited.yml @@ -418,7 +418,7 @@ jobs: if: failure() with: name: server-logs - path: app/server/server-logs.log + path: ${{ github.workspace }}/app/server/server-logs.log overwrite: true # Set status = success