From 2b98b4070414c4d4caccf3dea0168e5cd24846a8 Mon Sep 17 00:00:00 2001
From: Nemanja Glumac <31325167+nemanjaglumac@users.noreply.github.com>
Date: Mon, 20 Feb 2023 15:49:17 +0100
Subject: [PATCH] [CI] Unify E2E tests workflows (#28431)

---
 .github/workflows/e2e-main.yml  | 222 --------------------------------
 .github/workflows/e2e-tests.yml |  30 +++--
 2 files changed, 20 insertions(+), 232 deletions(-)
 delete mode 100644 .github/workflows/e2e-main.yml

diff --git a/.github/workflows/e2e-main.yml b/.github/workflows/e2e-main.yml
deleted file mode 100644
index 207ca9f455e..00000000000
--- a/.github/workflows/e2e-main.yml
+++ /dev/null
@@ -1,222 +0,0 @@
-name: E2E Tests
-
-on:
-  push:
-    branches:
-      - "master"
-      - 'release-**'
-    paths-ignore:
-      - "docs/**"
-      - "**.md"
-      - ".circleci/**"
-      - "**.unit.spec.*"
-      - "**_test.clj"
-
-jobs:
-
-  build:
-    runs-on: ubuntu-20.04
-    timeout-minutes: 25
-    strategy:
-      matrix:
-        edition: [oss, ee]
-    env:
-      MB_EDITION: ${{ matrix.edition }}
-      INTERACTIVE: false
-    steps:
-    - uses: actions/checkout@v3
-    - name: Prepare front-end environment
-      uses: ./.github/actions/prepare-frontend
-    - name: Prepare back-end environment
-      uses: ./.github/actions/prepare-backend
-      with:
-        m2-cache-key: e2e-main
-
-    - name: Build uberjar with ./bin/build
-      run: >-
-        ./bin/build version translations frontend licenses drivers uberjar
-
-    - name: Prepare uberjar artifact
-      uses: ./.github/actions/prepare-uberjar-artifact
-
-  e2e-tests:
-    runs-on: ubuntu-20.04
-    timeout-minutes: 45
-    needs: build
-    name: e2e-tests-${{ matrix.folder }}${{ matrix.context }}-${{ matrix.edition }}
-    env:
-      MB_EDITION: ${{ matrix.edition }}
-      DISPLAY: ""
-      QA_DB_ENABLED: true
-      MB_PREMIUM_EMBEDDING_TOKEN: ${{ secrets.ENTERPRISE_TOKEN }}
-      MB_SNOWPLOW_AVAILABLE: true
-      MB_SNOWPLOW_URL: "http://localhost:9090"  # Snowplow micro
-      ELECTRON_EXTRA_LAUNCH_ARGS: '--remote-debugging-port=40500' # deploysentinel
-    strategy:
-      fail-fast: false
-      matrix:
-        java-version: [11]
-        edition: [ee]
-        folder:
-          - "admin"
-          - "binning"
-          - "collections"
-          - "custom-column"
-          - "dashboard"
-          - "dashboard-filters"
-          - "downloads"
-          - "embedding"
-          - "filters"
-          - "joins"
-          - "models"
-          - "native"
-          - "native-filters"
-          - "onboarding"
-          - "organization"
-          - "permissions"
-          - "question"
-          - "sharing"
-          - "visualizations"
-        include:
-          - edition: oss
-            context: grep
-            java-version: 11
-    services:
-      maildev:
-        image: maildev/maildev:2.0.5
-        ports:
-          - "1080:1080"
-          - "1025:1025"
-        credentials:
-          username: ${{ secrets.DOCKERHUB_USERNAME }}
-          password: ${{ secrets.DOCKERHUB_TOKEN }}
-      openldap:
-        image: osixia/openldap:1.5.0
-        ports:
-          - "389:389"
-        credentials:
-          username: ${{ secrets.DOCKERHUB_USERNAME }}
-          password: ${{ secrets.DOCKERHUB_TOKEN }}
-      postgres-sample:
-        image: metabase/qa-databases:postgres-sample-12
-        ports:
-          - "5404:5432"
-        credentials:
-          username: ${{ secrets.DOCKERHUB_USERNAME }}
-          password: ${{ secrets.DOCKERHUB_TOKEN }}
-      mongo-sample:
-        image: metabase/qa-databases:mongo-sample-4.0
-        ports:
-          - 27004:27017
-        credentials:
-          username: ${{ secrets.DOCKERHUB_USERNAME }}
-          password: ${{ secrets.DOCKERHUB_TOKEN }}
-      mysql-sample:
-        image: metabase/qa-databases:mysql-sample-8
-        ports:
-          - 3304:3306
-        credentials:
-          username: ${{ secrets.DOCKERHUB_USERNAME }}
-          password: ${{ secrets.DOCKERHUB_TOKEN }}
-    steps:
-    - uses: actions/checkout@v3
-    # Test runs will be recorded using Deploysentinel on `master` only
-    - name: Set conditional ENVs
-      if: github.ref == 'refs/heads/master'
-      run: |
-        echo "CYPRESS_DEPLOYSENTINEL_KEY=${{ secrets.CYPRESS_DEPLOYSENTINEL_KEY }}" >> $GITHUB_ENV
-    - name: Prepare front-end environment
-      uses: ./.github/actions/prepare-frontend
-    - name: Prepare JDK ${{ matrix.java-version }}
-      uses: actions/setup-java@v3
-      with:
-        java-version: ${{ matrix.java-version }}
-        distribution: 'temurin'
-    - name: Prepare cypress environment
-      uses: ./.github/actions/prepare-cypress
-    - name: Run Snowplow micro
-      uses: ./.github/actions/run-snowplow-micro
-
-    - uses: actions/download-artifact@v3
-      name: Retrieve uberjar artifact for ${{ matrix.edition }}
-      with:
-        name: metabase-${{ matrix.edition }}-uberjar
-    - name: Get the version info
-      run: |
-        jar xf target/uberjar/metabase.jar version.properties
-        mv version.properties resources/
-
-    - name: Run OSS-specific Cypress tests
-      if: matrix.edition == 'oss'
-      run: |
-        yarn run test-cypress-run \
-        --env grepTags=@OSS \
-        --spec './frontend/test/metabase/scenarios/**/*.cy.spec.js'
-      env:
-        TERM: xterm
-
-    # These are EE-specific and version-agnostic tests
-    - name: Run Cypress E2E tests against EE uberjar
-      if: matrix.edition == 'ee'
-      run: |
-        yarn run test-cypress-run \
-          --folder ${{ matrix.folder }}
-      env:
-        TERM: xterm
-
-    - name: Upload Cypress Artifacts upon failure
-      uses: actions/upload-artifact@v3
-      if: failure()
-      with:
-        name: cypress-recording-${{ matrix.folder }}${{ matrix.context }}-${{ matrix.edition }}
-        path: |
-          ./cypress
-          ./logs/test.log
-        if-no-files-found: ignore
-
-  visual-regression-tests:
-    if: github.ref == 'refs/heads/master'
-    runs-on: ubuntu-20.04
-    timeout-minutes: 45
-    needs: build
-    name: percy-screenshot-recording-${{ matrix.edition }}
-    env:
-      MB_EDITION: ${{ matrix.edition }}
-      MB_PREMIUM_EMBEDDING_TOKEN: ${{ secrets.ENTERPRISE_TOKEN }}
-    strategy:
-      matrix:
-        java-version: [11]
-        edition: [ee]
-    services:
-      maildev:
-        image: maildev/maildev:2.0.5
-        ports:
-          - "1080:1080"
-          - "1025:1025"
-        credentials:
-          username: ${{ secrets.DOCKERHUB_USERNAME }}
-          password: ${{ secrets.DOCKERHUB_TOKEN }}
-    steps:
-    - uses: actions/checkout@v3
-    - name: Prepare front-end environment
-      uses: ./.github/actions/prepare-frontend
-    - name: Prepare JDK ${{ matrix.java-version }}
-      uses: actions/setup-java@v3
-      with:
-        java-version: ${{ matrix.java-version }}
-        distribution: 'temurin'
-    - name: Prepare Cypress environment
-      uses: ./.github/actions/prepare-cypress
-
-    - uses: actions/download-artifact@v3
-      name: Retrieve uberjar artifact for ${{ matrix.edition }}
-      with:
-        name: metabase-${{ matrix.edition }}-uberjar
-    - name: Get the version info
-      run: |
-        jar xf target/uberjar/metabase.jar version.properties
-        mv version.properties resources/
-    - name: Percy Test
-      run: yarn run test-visual-run
-      env:
-        PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml
index 398debdfc3e..1a8e114de85 100644
--- a/.github/workflows/e2e-tests.yml
+++ b/.github/workflows/e2e-tests.yml
@@ -1,11 +1,15 @@
-name: E2E Tests for PR
+name: E2E Tests
 
 on:
+  push:
+    branches:
+      - "master"
+      - 'release-**'
   pull_request:
     types: [opened, synchronize, reopened, ready_for_review]
 
 concurrency:
-  group: ${{ github.workflow }}-${{ github.ref }}
+  group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
   cancel-in-progress: true
 
 jobs:
@@ -44,7 +48,8 @@ jobs:
         with:
           m2-cache-key: e2e-tests
 
-      - run: ./bin/build version translations frontend licenses drivers uberjar
+      - name: Build uberjar with ./bin/build
+        run: ./bin/build version translations frontend licenses drivers uberjar
 
       - name: Prepare uberjar artifact
         uses: ./.github/actions/prepare-uberjar-artifact
@@ -134,11 +139,10 @@ jobs:
           password: ${{ secrets.DOCKERHUB_TOKEN }}
     steps:
       - uses: actions/checkout@v3
-      - name: Set conditional ENVs
+      - name: Record runs using Deploysentinel except for the release branch
+        if: ${{ github.ref == 'refs/heads/master' || !(startsWith(github.event.pull_request.base.ref, 'release')) }}
         run: |
-          if [[ ${{ github.event.pull_request.base.ref }} != release* ]]; then
-            echo "CYPRESS_DEPLOYSENTINEL_KEY=${{ secrets.CYPRESS_DEPLOYSENTINEL_KEY }}" >> $GITHUB_ENV
-          fi
+          echo "CYPRESS_DEPLOYSENTINEL_KEY=${{ secrets.CYPRESS_DEPLOYSENTINEL_KEY }}" >> $GITHUB_ENV
       - name: Prepare front-end environment
         uses: ./.github/actions/prepare-frontend
       - name: Prepare JDK ${{ matrix.java-version }}
@@ -232,9 +236,9 @@ jobs:
 
   visual-regression-tests:
     runs-on: ubuntu-20.04
-    timeout-minutes: 30
+    timeout-minutes: 45
     needs: build
-    name: percy-tests-sanity-check-${{ matrix.edition }}
+    name: percy-visual-regression-tests
     env:
       MB_EDITION: ${{ matrix.edition }}
       MB_PREMIUM_EMBEDDING_TOKEN: ${{ secrets.ENTERPRISE_TOKEN }}
@@ -253,13 +257,17 @@ jobs:
           password: ${{ secrets.DOCKERHUB_TOKEN }}
     steps:
       - uses: actions/checkout@v3
+      - name: Enable Percy recording on master only
+        if: github.ref == 'refs/heads/master'
+        run: |
+          echo "PERCY_TOKEN=${{ secrets.PERCY_TOKEN }}" >> $GITHUB_ENV
       - name: Prepare front-end environment
         uses: ./.github/actions/prepare-frontend
       - name: Prepare JDK ${{ matrix.java-version }}
         uses: actions/setup-java@v3
         with:
           java-version: ${{ matrix.java-version }}
-          distribution: "temurin"
+          distribution: 'temurin'
       - name: Prepare Cypress environment
         uses: ./.github/actions/prepare-cypress
 
@@ -273,3 +281,5 @@ jobs:
           mv version.properties resources/
       - name: Percy Test
         run: yarn run test-visual-run
+        env:
+          PERCY_TOKEN: ${{ env.PERCY_TOKEN }}
-- 
GitLab