The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Run Eastwood against changed tests only (#73951)
Chris Trutera4a8bcc058f1
diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.ymlindex 597ebe2016a..19a20b39b93 100644--- a/.github/workflows/backend.yml+++ b/.github/workflows/backend.yml@@ -37,7 +37,8 @@ jobs:name: Run Eastwood linterbe-linter-eastwood-test:- if: ${{ !inputs.skip && github.ref_name == 'master' }}+ # Master / release safety net: lint every backend test namespace.+ if: ${{ !inputs.skip && github.event_name == 'push' && (github.ref_name == 'master' || startsWith(github.ref_name, 'release-')) }}runs-on: ${{ vars.DEFAULT_RUNNER_KEY }}timeout-minutes: 30name: Eastwood (tests only)@@ -48,6 +49,64 @@ jobs:- run: clojure -X:dev:ee:ee-dev:drivers:drivers-dev:test:eastwood/testname: Run Eastwood linter on our backend tests+ be-linter-eastwood-test-changed:+ # PR / merge queue: lint only the test namespaces touched by the diff.+ if: ${{ !inputs.skip && (github.event_name == 'pull_request' || github.event_name == 'merge_group') }}+ runs-on: ${{ vars.DEFAULT_RUNNER_KEY }}+ timeout-minutes: 15+ name: Eastwood (changed tests only)+ steps:+ - uses: actions/checkout@v4+ with:+ # Enough history for `git merge-base` on a typical PR.+ fetch-depth: 200+ - name: Prepare back-end environment+ uses: ./.github/actions/prepare-backend+ - name: Compute changed test namespaces+ id: changed+ env:+ BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}+ HEAD_SHA: ${{ github.event.pull_request.head.sha || github.event.merge_group.head_sha || github.sha }}+ run: |+ set -euo pipefail++ # Diff from the merge-base so changes that landed on the base branch after the PR was+ # last synced don't widen our scope. Falls back to BASE_SHA if older than fetched depth.+ git fetch --no-tags --depth=200 origin "$BASE_SHA"+ DIFF_BASE=$(git merge-base "$BASE_SHA" "$HEAD_SHA" 2>/dev/null || echo "$BASE_SHA")+ # Test roots we lint: core, EE, and each driver module's test tree.+ # :eastwood/test derives matching :source-paths from the classpath, so any+ # namespace we name here is reachable. Include renames (R) so a test that+ # was just renamed still gets linted under its new name.+ FILES=$(git diff --name-only --diff-filter=AMR "$DIFF_BASE" "$HEAD_SHA" \+ -- 'test/**/*.clj' 'test/**/*.cljc' \+ 'enterprise/backend/test/**/*.clj' 'enterprise/backend/test/**/*.cljc' \+ 'modules/drivers/**/test/**/*.clj' 'modules/drivers/**/test/**/*.cljc')++ if [ -z "$FILES" ]; then+ echo "No backend test files changed; skipping lint."+ echo "namespaces=" >> "$GITHUB_OUTPUT"+ exit 0+ fi++ # Defence-in-depth: paths flow into a subsequent shell command via $GITHUB_OUTPUT.+ if grep -Eqv '^[A-Za-z0-9_./-]+$' <<<"$FILES"; then+ echo "Refusing to lint: unexpected characters in changed file paths:" >&2+ echo "$FILES" >&2+ exit 1+ fi++ NS=$(sed -E 's#^(test/|enterprise/backend/test/|modules/drivers/[^/]+/test/)##; s#\.cljc?$##; s#/#.#g; s#_#-#g' <<<"$FILES" \+ | sort -u \+ | paste -sd' ' -)+ echo "Changed test namespaces: $NS"+ echo "namespaces=$NS" >> "$GITHUB_OUTPUT"+ - name: Run Eastwood on changed test namespaces+ if: steps.changed.outputs.namespaces != ''+ env:+ NAMESPACES: ${{ steps.changed.outputs.namespaces }}+ run: clojure -X:dev:ee:ee-dev:drivers:drivers-dev:test:eastwood/test :namespaces "[$NAMESPACES]"+be-tests:if: ${{ !inputs.skip }}runs-on: ${{ vars.DEFAULT_RUNNER_KEY }}@@ -196,6 +255,7 @@ jobs:needs:- be-linter-eastwood- be-linter-eastwood-test+ - be-linter-eastwood-test-changed- be-linter-clj-kondo- be-cljfmt- be-checkdiff --git a/deps.edn b/deps.ednindex 70fe40d7e34..959eaae577d 100644--- a/deps.edn+++ b/deps.edn@@ -664,10 +664,8 @@;;;; clojure -X:dev:ee:ee-dev:drivers:drivers-dev:test:eastwood/test:eastwood/test- {:exec-fn metabase.linters.eastwood/eastwood- :exec-args {:source-paths ["test"- "enterprise/backend/test"]- :linters [:reflection]+ {:exec-fn metabase.linters.eastwood/eastwood-tests+ :exec-args {:linters [:reflection]:exclude-namespaces[;; byte/1 dispatch value trips up Eastwood's readermetabase.test.http-clientdiff --git a/modules/drivers/bigquery-cloud-sdk/test/metabase/driver/bigquery_cloud_sdk_test.clj b/modules/drivers/bigquery-cloud-sdk/test/metabase/driver/bigquery_cloud_sdk_test.cljindex 14ab5c3cae1..560985ff706 100644--- a/modules/drivers/bigquery-cloud-sdk/test/metabase/driver/bigquery_cloud_sdk_test.clj+++ b/modules/drivers/bigquery-cloud-sdk/test/metabase/driver/bigquery_cloud_sdk_test.clj@@ -28,7 +28,8 @@[metabase.warehouse-schema.models.field-values :as field-values][toucan2.core :as t2])(:import- (com.google.cloud.bigquery BigQuery TableResult)))+ (com.google.cloud.bigquery BigQuery TableResult)+ (com.google.cloud.http HttpTransportOptions)))(set! *warn-on-reflection* true)@@ -1324,7 +1325,7 @@(testing "Read timeout is configured as the query-timeout-ms setting"(let [^BigQuery client (#'bigquery/database-details->client (:details (mt/db)))options (.getOptions client)- transport-options (.getTransportOptions options)]+ ^HttpTransportOptions transport-options (.getTransportOptions options)](is (= driver.settings/*query-timeout-ms*(.getReadTimeout transport-options)))))))diff --git a/modules/drivers/clickhouse/test/metabase/driver/clickhouse_data_types_test.clj b/modules/drivers/clickhouse/test/metabase/driver/clickhouse_data_types_test.cljindex a8645685e2b..d247cd91dfc 100644--- a/modules/drivers/clickhouse/test/metabase/driver/clickhouse_data_types_test.clj+++ b/modules/drivers/clickhouse/test/metabase/driver/clickhouse_data_types_test.clj@@ -274,9 +274,9 @@[nil nil]]]["maps_test"[{:field-name "m", :base-type {:native "Map(String, UInt64)"}}]- [[(java.util.HashMap. {"key1" 1, "key2" 10})]- [(java.util.HashMap. {"key1" 2, "key2" 20})]- [(java.util.HashMap. {"key1" 3, "key2" 30})]]]+ [[(doto (java.util.HashMap.) (.putAll {"key1" 1, "key2" 10}))]+ [(doto (java.util.HashMap.) (.putAll {"key1" 2, "key2" 20}))]+ [(doto (java.util.HashMap.) (.putAll {"key1" 3, "key2" 30}))]]]["datetime_diff_nullable"[{:field-name "idx", :base-type {:native "Int32"}}{:field-name "dt64", :base-type {:native "Nullable(DateTime64(3, 'UTC'))"}}diff --git a/modules/drivers/clickhouse/test/metabase/driver/clickhouse_substitution_test.clj b/modules/drivers/clickhouse/test/metabase/driver/clickhouse_substitution_test.cljindex 63f5a3888e6..b8c89af1e92 100644--- a/modules/drivers/clickhouse/test/metabase/driver/clickhouse_substitution_test.clj+++ b/modules/drivers/clickhouse/test/metabase/driver/clickhouse_substitution_test.clj@@ -8,7 +8,7 @@[metabase.test.data.clickhouse :as ctd][metabase.util :as u][schema.core :as s])- (:import (java.time LocalDate LocalDateTime)))+ (:import (java.time Clock LocalDate LocalDateTime)))(set! *warn-on-reflection* true)@@ -31,7 +31,7 @@:target ["dimension" ["template-tag" "x"]]:id uuid}]}))-(def ^:private clock (t/mock-clock (t/instant "2019-11-30T23:00:00Z") (t/zone-id "UTC")))+(def ^:private ^Clock clock (t/mock-clock (t/instant "2019-11-30T23:00:00Z") (t/zone-id "UTC")))(s/defn ^:private local-date-now :- LocalDate [] (LocalDate/now clock))(s/defn ^:private local-date-time-now :- LocalDateTime [] (LocalDateTime/now clock))diff --git a/modules/drivers/starburst/test/metabase/driver/starburst_test.clj b/modules/drivers/starburst/test/metabase/driver/starburst_test.cljindex 3cb87fbf433..1c13229465e 100644--- a/modules/drivers/starburst/test/metabase/driver/starburst_test.clj+++ b/modules/drivers/starburst/test/metabase/driver/starburst_test.clj@@ -366,7 +366,7 @@driver/*driver* (mt/id) nil(fn [^Connection conn](let [stmt (.prepareStatement conn "select 1" ResultSet/TYPE_FORWARD_ONLY ResultSet/CONCUR_READ_ONLY)- prepared-stmt (#'starburst/proxy-optimized-prepared-statement driver/*driver* conn stmt [])]+ ^PreparedStatement prepared-stmt (#'starburst/proxy-optimized-prepared-statement driver/*driver* conn stmt [])](is (false? (.isClosed prepared-stmt)))(.close stmt)(is (true? (.isClosed prepared-stmt)))))))))diff --git a/test/metabase/linters/eastwood.clj b/test/metabase/linters/eastwood.cljindex 3a0d67b12b7..524ecf11891 100644--- a/test/metabase/linters/eastwood.clj+++ b/test/metabase/linters/eastwood.clj@@ -1,7 +1,10 @@(ns metabase.linters.eastwood(:require[eastwood.lint :as eastwood]- [metabase.linters.common :as common]))+ [metabase.linters.common :as common])+ (:import (java.io File)))++(set! *warn-on-reflection* true)(defn eastwood"Entrypoint for running Eastwood from the CLI. Adds some programatically-determined config options. See comments in@@ -11,3 +14,17 @@(merge{:source-paths (common/source-paths)}options)))++(defn eastwood-tests+ "Entry-point for the :eastwood/test alias. Derives :source-paths from classpath directories+ whose basename is `test` so we don't have to hardcode the per-driver test paths in deps.edn —+ they're already on the classpath via :drivers-dev's :extra-paths. Excludes `.clj-kondo/test`,+ which is for clj-kondo hook tests and uses a different toolchain."+ [options]+ (eastwood/eastwood-from-cmdline+ (merge+ {:source-paths (filterv (fn [^File f]+ (and (= "test" (.getName f))+ (not= ".clj-kondo" (some-> (.getParentFile f) .getName))))+ (common/source-paths))}+ options)))