From 085b39c7afd2cfbaa241722b5c99e43772b2aaa1 Mon Sep 17 00:00:00 2001 From: R Midhun Suresh Date: Thu, 16 Nov 2023 21:41:03 +0530 Subject: [PATCH] Use knapsack pro to speed up cypress tests (#11863) * Install knapsack pro * Use knapsack pro command * Lint * Use chrome * Add test file pattern * Use two different tokens for knapsack * Use the correct secret * Update lockfile * Fix conflict * Remove redundant options * Add explaining comment * Remove outdated variables and steps * Update comment * Fix conflict * Use the chrome we setup earlier * Add back percy config * Set knapsack pro branch * Use github_env to get browser path * Add badge to readme * Update .github/workflows/cypress.yaml Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> * Apply prettier --------- Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --- .github/workflows/cypress.yaml | 53 ++------ README.md | 3 +- package.json | 1 + yarn.lock | 230 +++++++++++++++++++++++++++++++-- 4 files changed, 239 insertions(+), 48 deletions(-) diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index d42cc0df44..fc1dc78dbd 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -41,9 +41,6 @@ jobs: outputs: uuid: ${{ steps.uuid.outputs.value }} pr_id: ${{ steps.prdetails.outputs.pr_id }} - commit_message: ${{ steps.commit.outputs.message }} - commit_author: ${{ steps.commit.outputs.author }} - commit_email: ${{ steps.commit.outputs.email }} percy_enable: ${{ steps.percy.outputs.value || '0' }} steps: # We create the status here and then update it to success/failure in the `report` stage @@ -63,21 +60,6 @@ jobs: owner: ${{ github.event.workflow_run.head_repository.owner.login }} branch: ${{ github.event.workflow_run.head_branch }} - - name: Get commit details - id: commit - if: github.event.workflow_run.event == 'pull_request' || github.event.workflow_run.event == 'merge_group' - uses: actions/github-script@v7 - with: - script: | - const response = await github.rest.git.getCommit({ - owner: context.repo.owner, - repo: context.repo.repo, - commit_sha: "${{ github.event.workflow_run.head_sha }}", - }); - core.setOutput("message", response.data.message); - core.setOutput("author", response.data.author.name); - core.setOutput("email", response.data.author.email); - # Percy is disabled while we're figuring out https://github.com/vector-im/wat-internal/issues/36 # and https://github.com/vector-im/wat-internal/issues/56. We're hoping to turn it back on or switch # to an alternative in the future. @@ -108,11 +90,13 @@ jobs: strategy: fail-fast: false matrix: - # Naive segmentation of tests - segment: ["a-i", "j-p", "q-s", "t-z"] # Run tests using both crypto stacks crypto: [legacy, rust] + ci_node_total: [4] + ci_node_index: [0, 1, 2, 3] steps: + # The version of chrome shipped by default may not be consistent across runners + # so we explicitly use a specific version of chrome here. - uses: browser-actions/setup-chrome@803ef6dfb4fdf22089c9563225d95e4a515820a0 # v1 - run: echo "BROWSER_PATH=$(which chrome)" >> $GITHUB_ENV @@ -154,23 +138,24 @@ jobs: run: | echo "CYPRESS_RUST_CRYPTO=1" >> "$GITHUB_ENV" - - name: Run Cypress tests + - name: Run Cypress tests via knapsack pro uses: cypress-io/github-action@ebe8b24c4428922d0f793a5c4c96853a633180e3 # v6.6.0 with: working-directory: matrix-react-sdk - # The built-in Electron runner seems to grind to a halt trying to run the tests, so use chrome. - browser: ${{ steps.setup-chrome.outputs.chrome-path }} headed: true start: npx serve -p 8080 -L ../webapp wait-on: "http://localhost:8080" - record: true + record: false parallel: false - command-prefix: "yarn percy exec --parallel --" - ci-build-id: ${{ needs.prepare.outputs.uuid }}-${{ matrix.crypto }} - spec: cypress/e2e/[${{ matrix.segment }}]*/** + # The built-in Electron runner seems to grind to a halt trying to run the tests, so use chrome. + command: yarn percy exec --parallel -- npx knapsack-pro-cypress --config trashAssetsBeforeRuns=false --browser "$BROWSER_PATH" env: - # pass the Dashboard record key as an environment variable - CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} + # Knapsack token and config + KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS: ${{ matrix.crypto == 'rust' && secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS_RUST || secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS_LEGACY }} + KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }} + KNAPSACK_PRO_CI_NODE_INDEX: ${{ matrix.ci_node_index }} + KNAPSACK_PRO_TEST_FILE_PATTERN: cypress/e2e/**/*.spec.ts + KNAPSACK_PRO_BRANCH: ${{ github.event.workflow_run.head_branch }} # Use existing chromium rather than downloading another PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true @@ -181,16 +166,6 @@ jobs: # make Node's os.tmpdir() return something where we actually have permissions TMPDIR: ${{ runner.temp }} - # tell Cypress more details about the context of this run - COMMIT_INFO_BRANCH: ${{ github.event.workflow_run.head_branch }} - COMMIT_INFO_SHA: ${{ github.event.workflow_run.head_sha }} - COMMIT_INFO_REMOTE: ${{ github.repositoryUrl }} - COMMIT_INFO_MESSAGE: ${{ needs.prepare.outputs.commit_message }} - COMMIT_INFO_AUTHOR: ${{ needs.prepare.outputs.commit_author }} - COMMIT_INFO_EMAIL: ${{ needs.prepare.outputs.commit_email }} - CYPRESS_PULL_REQUEST_ID: ${{ needs.prepare.outputs.pr_id }} - CYPRESS_PULL_REQUEST_URL: https://github.com/${{ github.repository }}/pull/${{ needs.prepare.outputs.pr_id }} - # pass the Percy token as an environment variable PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }} diff --git a/README.md b/README.md index 39d1f600e2..ffb516b90a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ [![npm](https://img.shields.io/npm/v/matrix-react-sdk)](https://www.npmjs.com/package/matrix-react-sdk) ![Tests](https://github.com/matrix-org/matrix-react-sdk/actions/workflows/tests.yml/badge.svg) ![Static Analysis](https://github.com/matrix-org/matrix-react-sdk/actions/workflows/static_analysis.yaml/badge.svg) -[![matrix-react-sdk](https://img.shields.io/endpoint?url=https://dashboard.cypress.io/badge/simple/ppvnzg/develop&style=flat&logo=cypress)](https://dashboard.cypress.io/projects/ppvnzg/runs) +[![Knapsack Pro Parallel CI builds for Cypress Test - Legacy Crypto](https://img.shields.io/badge/Knapsack%20Pro-Parallel%20%2F%20Cypress%20Test%20--%20Legacy%20Crypto-%230074ff)](https://knapsackpro.com/dashboard/organizations/3882/projects/2469/test_suites/3724/builds?utm_campaign=organization-id-3882&utm_content=test-suite-id-3724&utm_medium=readme&utm_source=knapsack-pro-badge&utm_term=project-id-2469) +[![Knapsack Pro Parallel CI builds for Cypress Test - Rust Crypto](https://img.shields.io/badge/Knapsack%20Pro-Parallel%20%2F%20Cypress%20Test%20--%20Rust%20Crypto-%230074ff)](https://knapsackpro.com/dashboard/organizations/3882/projects/2469/test_suites/3729/builds?utm_campaign=organization-id-3882&utm_content=test-suite-id-3729&utm_medium=readme&utm_source=knapsack-pro-badge&utm_term=project-id-2469)