From 25ac825ae558368c18f7ea41ea7d160fd4b8716d Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 24 Apr 2023 09:24:50 +0100 Subject: [PATCH] Cypress use the simulated merge commit for the source of tests (#10688) * Cypress use the simulated merge commit for the source of tests * Add comments * Update .github/workflows/cypress.yaml Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> --------- Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> --- .github/workflows/cypress.yaml | 29 ++++++++++++++++++++--------- .github/workflows/element-web.yaml | 2 ++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index 8c91f56ad6..374d51da98 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -106,15 +106,6 @@ jobs: # supposed to be covered by STIXGeneral. tools: fonts-stix - - uses: actions/checkout@v3 - with: - # XXX: We're checking out untrusted code in a secure context - # We need to be careful to not trust anything this code outputs/may do - # We need to check this out to access the cypress tests which are on the head branch - repository: ${{ github.event.workflow_run.head_repository.full_name }} - ref: ${{ github.event.workflow_run.head_sha }} - persist-credentials: false - # There's a 'download artifact' action, but it hasn't been updated for the workflow_run action # (https://github.com/actions/download-artifact/issues/60) so instead we get this mess: - name: 📥 Download artifact @@ -124,6 +115,25 @@ jobs: name: previewbuild path: webapp + # The workflow_run.head_sha is the sha of the head commit but the element-web was built using a simulated + # merge commit - https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request + # so use the sha from the tarball for the checkout of the cypress tests + # to make sure we get a matching set of code and tests. + - name: Grab sha from webapp + id: sha + run: | + echo "sha=$(cat webapp/sha)" >> $GITHUB_OUTPUT + + - uses: actions/checkout@v3 + with: + # XXX: We're checking out untrusted code in a secure context + # We need to be careful to not trust anything this code outputs/may do + # We need to check this out to access the cypress tests which are on the head branch + repository: ${{ github.event.workflow_run.head_repository.full_name }} + ref: ${{ steps.sha.outputs.sha }} + persist-credentials: false + path: matrix-react-sdk + - name: Run Cypress tests uses: cypress-io/github-action@a29a621b736c9a8547ba0236cc9cee1e49725bd5 with: @@ -137,6 +147,7 @@ jobs: command-prefix: "yarn percy exec --parallel --" config: '{"reporter":"cypress-multi-reporters", "reporterOptions": { "configFile": "cypress-ci-reporter-config.json" } }' ci-build-id: ${{ needs.prepare.outputs.uuid }} + project: matrix-react-sdk env: # pass the Dashboard record key as an environment variable CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} diff --git a/.github/workflows/element-web.yaml b/.github/workflows/element-web.yaml index e5fb48fb88..022c293abe 100644 --- a/.github/workflows/element-web.yaml +++ b/.github/workflows/element-web.yaml @@ -43,6 +43,7 @@ jobs: run: cp element.io/develop/config.json config.json working-directory: ./element-web + # After building we write the version file and the react-sdk sha so our cypress tests are from the same sha - name: Build env: CI_PACKAGE: true @@ -50,6 +51,7 @@ jobs: run: | yarn build echo $VERSION > webapp/version + echo $GITHUB_SHA > webapp/sha working-directory: ./element-web - name: Upload Artifact