From 33e84e0c308130222dab35f2497dc5ce40e4562a Mon Sep 17 00:00:00 2001
From: Aleksandr Lesnenko <alxnddr@users.noreply.github.com>
Date: Wed, 8 Feb 2023 22:55:17 -0300
Subject: [PATCH] path filtering for FE, snowplow, presto-kerberos (#28048)

---
 .github/file-paths.yaml                       | 88 +++++++++++++++++++
 .github/workflows/frontend-skipped-checks.yml | 79 -----------------
 .github/workflows/frontend.yml                | 56 ++++++------
 ...rberos-integration-test-skipped-checks.yml | 23 -----
 .../presto-kerberos-integration-test.yml      | 23 +++--
 .github/workflows/snowplow-skipped-checks.yml | 19 ----
 .github/workflows/snowplow.yml                | 20 ++++-
 7 files changed, 149 insertions(+), 159 deletions(-)
 create mode 100644 .github/file-paths.yaml
 delete mode 100644 .github/workflows/frontend-skipped-checks.yml
 delete mode 100644 .github/workflows/presto-kerberos-integration-test-skipped-checks.yml
 delete mode 100644 .github/workflows/snowplow-skipped-checks.yml

diff --git a/.github/file-paths.yaml b/.github/file-paths.yaml
new file mode 100644
index 00000000000..c7d90727b02
--- /dev/null
+++ b/.github/file-paths.yaml
@@ -0,0 +1,88 @@
+default: &default
+  - "locales/**"
+  - "bin/**"
+
+ci: &ci
+  - ".github/**"
+
+shared_sources: &shared_sources
+  - "shared/src"
+
+shared_specs: &shared_specs
+  - "shared/test"
+
+frontend_sources: &frontend_sources
+  - *shared_sources
+  - "frontend/**"
+  - "enterprise/frontend/**"
+  - "frontend/!(test)/**"
+  - "yarn.lock"
+  - "**/tsconfig*.json"
+  - "package.json"
+  - "babel.config.json"
+  - "postcss.config.js"
+  - "webpack.config.js"
+  - "webpack.static-viz.config.js"
+
+frontend_specs: &frontend_specs
+  - *shared_specs
+  - "frontend/test/!(__support__|__runner__)/**"
+  - "frontend/**.unit.*"
+  - "jest.config.js"
+
+frontend_all: &frontend_all
+  - *ci
+  - *frontend_sources
+  - *frontend_specs
+
+backend_presto_kerberos:
+  - "**/presto_jdbc/**"
+  - "**/presto_jdbc.clj"
+
+backend_sources: &backend_sources
+  - *shared_sources
+  - "**deps.edn"
+  - "enterprise/backend/src/**"
+  - "src/**"
+  - "modules/drivers/{*,*/{*,!(test)/**}}"
+  - "resources/**"
+  - ".clj-kondo/**"
+
+backend_specs: &backend_specs
+  - *shared_specs
+  - "test/**"
+  - "enterprise/backend/test/**"
+  - "test_modules/**"
+  - "modules/drivers/*/test/**"
+  - "test_config/**"
+  - "dev/**"
+
+backend_all: &backend_all
+  - *default
+  - *ci
+  - *backend_sources
+  - *backend_specs
+  - *frontend_sources # keep it here until we detect static viz changes
+
+sources: &sources
+  - *frontend_sources
+  - *backend_sources
+
+e2e_specs: &e2e_specs
+  - "**.cy.*.js"
+  - "frontend/test/__support__/e2e/**"
+  - "frontend/test/__runner__/*cypress*"
+
+e2e_all:
+  - *default
+  - *ci
+  - *e2e_specs
+  - *sources
+
+snowplow:
+  - *ci
+  - "snowplow/**"
+
+documentation:
+  - "docs/**"
+  - "**.md"
diff --git a/.github/workflows/frontend-skipped-checks.yml b/.github/workflows/frontend-skipped-checks.yml
deleted file mode 100644
index 76a40c5e32b..00000000000
--- a/.github/workflows/frontend-skipped-checks.yml
+++ /dev/null
@@ -1,79 +0,0 @@
-# Required checks with path filtering rules will block pull requests from merging if they change only the excluded files.
-# This is a workaround to allow the PR to be merged.
-# https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks
-name: Frontend
-
-on:
-  push:
-    branches:
-      - 'master'
-      - 'release-**'
-    paths:
-      # documentation
-      - "docs/**"
-      - "**.md"
-      # backend
-      - "enterprise/backend/**"
-      - "src/**"
-      - "test/**"
-      - "*modules/**" # modules/, test_modules/
-      # E2E
-      - "**.cy.*.js" # .cy.spec.js, .cy.snap.js
-      - "frontend/test/__support__/e2e/**"
-      - "frontend/test/__runner__/*cypress*"
-  pull_request:
-    paths:
-      # documentation
-      - "docs/**"
-      - "**.md"
-      # backend
-      - "enterprise/backend/**"
-      - "src/**"
-      - "test/**"
-      - "*modules/**" # modules/, test_modules/
-      # E2E
-      - "**.cy.*.js" # .cy.spec.js, .cy.snap.js
-      - "frontend/test/__support__/e2e/**"
-      - "frontend/test/__runner__/*cypress*"
-
-jobs:
-  fe-linter-prettier:
-    runs-on: ubuntu-20.04
-    timeout-minutes: 10
-    steps:
-      - run: |
-          echo "Didn't run due to conditional filtering"
-
-  fe-linter-eslint:
-    runs-on: ubuntu-20.04
-    timeout-minutes: 20
-    steps:
-      - run: |
-          echo "Didn't run due to conditional filtering"
-
-  fe-type-check:
-    runs-on: ubuntu-20.04
-    timeout-minutes: 10
-    steps:
-      - run: |
-          echo "Didn't run due to conditional filtering"
-
-  fe-tests-unit:
-    runs-on: ubuntu-20.04
-    timeout-minutes: 20
-    steps:
-      - run: |
-          echo "Didn't run due to conditional filtering"
-
-  fe-tests-timezones:
-    runs-on: ubuntu-20.04
-    timeout-minutes: 14
-    steps:
-      - run: |
-          echo "Didn't run due to conditional filtering"
-
-  fe-chromatic:
-    runs-on: ubuntu-20.04
-    steps:
-      - run: |
-          echo "Didn't run due to conditional filtering"
diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml
index efe7b84c70b..114f8204ee0 100644
--- a/.github/workflows/frontend.yml
+++ b/.github/workflows/frontend.yml
@@ -5,37 +5,28 @@ on:
     branches:
       - 'master'
       - 'release-**'
-    paths-ignore:
-      # documentation
-      - "docs/**"
-      - "**.md"
-      # backend
-      - "enterprise/backend/**"
-      - "src/**"
-      - "test/**"
-      - "*modules/**" # modules/, test_modules/
-      # E2E
-      - "**.cy.*.js" # .cy.spec.js, .cy.snap.js
-      - "frontend/test/__support__/e2e/**"
-      - "frontend/test/__runner__/*cypress*"
   pull_request:
     types: [opened, synchronize, reopened, ready_for_review]
-    paths-ignore:
-      # documentation
-      - "docs/**"
-      - "**.md"
-      # backend
-      - "enterprise/backend/**"
-      - "src/**"
-      - "test/**"
-      - "*modules/**" # modules/, test_modules/
-      # E2E
-      - "**.cy.*.js" # .cy.spec.js, .cy.snap.js
-      - "frontend/test/__support__/e2e/**"
-      - "frontend/test/__runner__/*cypress*"
 
 jobs:
+  files-changed:
+    name: Check which files changed
+    runs-on: ubuntu-20.04
+    timeout-minutes: 3
+    outputs:
+      frontend_all: ${{ steps.changes.outputs.frontend_all }}
+    steps:
+      - uses: actions/checkout@v3
+      - name: Test which files changed
+        uses: dorny/paths-filter@v2.11.1
+        id: changes
+        with:
+          token: ${{ github.token }}
+          filters: .github/file-paths.yaml
+
   fe-linter-prettier:
+    needs: files-changed
+    if: needs.files-changed.outputs.frontend_all == 'true'
     runs-on: ubuntu-20.04
     timeout-minutes: 10
     steps:
@@ -46,6 +37,8 @@ jobs:
       name: Run Prettier formatting linter
 
   fe-linter-eslint:
+    needs: files-changed
+    if: needs.files-changed.outputs.frontend_all == 'true'
     runs-on: ubuntu-20.04
     timeout-minutes: 20
     steps:
@@ -60,6 +53,8 @@ jobs:
       name: Run ESLint linter
 
   fe-type-check:
+    needs: files-changed
+    if: needs.files-changed.outputs.frontend_all == 'true'
     runs-on: ubuntu-20.04
     timeout-minutes: 10
     steps:
@@ -76,7 +71,8 @@ jobs:
       name: Check types
 
   fe-tests-unit:
-    if: github.event.pull_request.draft == false
+    needs: files-changed
+    if: github.event.pull_request.draft == false && needs.files-changed.outputs.frontend_all == 'true'
     runs-on: buildjet-2vcpu-ubuntu-2004
     timeout-minutes: 20
     steps:
@@ -96,7 +92,8 @@ jobs:
         flags: front-end
 
   fe-tests-timezones:
-    if: github.event.pull_request.draft == false
+    needs: files-changed
+    if: github.event.pull_request.draft == false && needs.files-changed.outputs.frontend_all == 'true'
     runs-on: ubuntu-20.04
     timeout-minutes: 14
     steps:
@@ -111,7 +108,8 @@ jobs:
       name: Run frontend timezones tests
 
   fe-chromatic:
-    if: github.event.pull_request.draft == false
+    needs: files-changed
+    if: github.event.pull_request.draft == false && needs.files-changed.outputs.frontend_all == 'true'
     runs-on: ubuntu-20.04
     steps:
       - name: Checkout repository
diff --git a/.github/workflows/presto-kerberos-integration-test-skipped-checks.yml b/.github/workflows/presto-kerberos-integration-test-skipped-checks.yml
deleted file mode 100644
index 7ab325ad8e0..00000000000
--- a/.github/workflows/presto-kerberos-integration-test-skipped-checks.yml
+++ /dev/null
@@ -1,23 +0,0 @@
-# Required checks with path filtering rules will block pull requests from merging if they change only the excluded files.
-# This is a workaround to allow the PR to be merged.
-# https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks
-name: Kerberized Presto Integration Test
-
-on:
-  pull_request:
-    paths-ignore:
-    - '**/presto_jdbc/**'
-    - '**/presto_jdbc.clj'
-  push:
-    branches:
-      - 'feature**'
-    paths-ignore:
-    - '**/presto_jdbc/**'
-    - '**/presto_jdbc.clj'
-
-jobs:
-  run-presto-kerberos-test:
-    runs-on: ubuntu-latest
-    steps:
-      - run: |
-          echo "Didn't run due to conditional filtering"
diff --git a/.github/workflows/presto-kerberos-integration-test.yml b/.github/workflows/presto-kerberos-integration-test.yml
index c80eb02a66e..46c581a3b7f 100644
--- a/.github/workflows/presto-kerberos-integration-test.yml
+++ b/.github/workflows/presto-kerberos-integration-test.yml
@@ -2,9 +2,6 @@ name: Kerberized Presto Integration Test
 
 on:
   pull_request:
-    paths:
-    - '**/presto_jdbc/**'
-    - '**/presto_jdbc.clj'
   push:
     branches:
       - master
@@ -12,12 +9,26 @@ on:
       - 'feature**'
     tags:
       - '**'
-    paths:
-    - '**/presto_jdbc/**'
-    - '**/presto_jdbc.clj'
 
 jobs:
+  files-changed:
+    name: Check which files changed
+    runs-on: ubuntu-20.04
+    timeout-minutes: 3
+    outputs:
+      backend_presto_kerberos: ${{ steps.changes.outputs.backend_presto_kerberos }}
+    steps:
+      - uses: actions/checkout@v3
+      - name: Test which files changed
+        uses: dorny/paths-filter@v2.11.1
+        id: changes
+        with:
+          token: ${{ github.token }}
+          filters: .github/file-paths.yaml
+
   run-presto-kerberos-test:
+    needs: files-changed
+    if: needs.files-changed.outputs.backend_presto_kerberos == 'true'
     runs-on: ubuntu-20.04
     timeout-minutes: 40
     steps:
diff --git a/.github/workflows/snowplow-skipped-checks.yml b/.github/workflows/snowplow-skipped-checks.yml
deleted file mode 100644
index 1db3286fbc5..00000000000
--- a/.github/workflows/snowplow-skipped-checks.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-# Required checks with path filtering rules will block pull requests from merging if they change only the excluded files.
-# This is a workaround to allow the PR to be merged.
-# https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks
-name: Snowplow
-
-on:
-  pull_request:
-    branches:
-      - "**"
-    paths-ignore:
-      - "snowplow/**"
-      - ".github/workflows/**"
-
-jobs:
-  lint:
-    runs-on: ubuntu-latest
-    steps:
-      - run: |
-          echo "Didn't run due to conditional filtering"
diff --git a/.github/workflows/snowplow.yml b/.github/workflows/snowplow.yml
index 9d505e78d66..db40125274e 100644
--- a/.github/workflows/snowplow.yml
+++ b/.github/workflows/snowplow.yml
@@ -4,12 +4,26 @@ on:
   pull_request:
     branches:
       - '**'
-    paths:
-      - 'snowplow/**'
-      - '.github/workflows/**'
 
 jobs:
+  files-changed:
+    name: Check which files changed
+    runs-on: ubuntu-20.04
+    timeout-minutes: 3
+    outputs:
+      snowplow: ${{ steps.changes.outputs.snowplow }}
+    steps:
+      - uses: actions/checkout@v3
+      - name: Test which files changed
+        uses: dorny/paths-filter@v2.11.1
+        id: changes
+        with:
+          token: ${{ github.token }}
+          filters: .github/file-paths.yaml
+
   lint:
+    needs: files-changed
+    if: needs.files-changed.outputs.snowplow == 'true'
     runs-on: ubuntu-20.04
     steps:
       - name: Checkout
-- 
GitLab