Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Run Eastwood weekly and report findings in Linear (#85525)

Chris Truter77c554bf3e43
diff --git a/.github/scripts/eastwood-bisect-check.sh b/.github/scripts/eastwood-bisect-check.sh
new file mode 100755
index 00000000000..c17e3d1b020
--- /dev/null
+++ b/.github/scripts/eastwood-bisect-check.sh
@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+# `git bisect run` check for the weekly Eastwood run: lints one namespace at the checked-out commit.
+#
+# git bisect run eastwood-bisect-check.sh <source|tests> <namespace> <linter> [<baseline.txt>]
+#
+# The baseline is the previous weekly run's warnings.
+# Exits 1 (bad) when the linter gives a warning in that namespace that isn't in the baseline.
+# So a namespace that was already failing still bisects to the commit that made it worse.
+# Exits 0 (good) when there is no such warning.
+# Exits 125 (skip) when Eastwood fails without any warning, as it does on a commit that doesn't compile.
+# Other linters' warnings don't count: they belong to other findings.
+
+set -uo pipefail
+
+target=$1
+namespace=$2
+linter=$3
+baseline=${4:-/dev/null}
+
+case "$target" in
+ source) alias=":dev:ee:ee-dev:drivers:drivers-dev:test:eastwood" ;;
+ tests) alias=":dev:dev/test:ee:ee-dev:drivers:drivers-dev:test:eastwood/test" ;;
+ *)
+ echo "Unknown target: $target" >&2
+ # Above 127 stops the bisect, instead of marking the commit bad.
+ exit 128
+ ;;
+esac
+
+# The warnings from this linter, without line and column, sorted for `comm`.
+# The report script builds the same keys to match findings across runs.
+keys() {
+ sed -E 's/^([^:]+):[0-9]+:[0-9]+: /\1: /' "$1" | grep -E "^[^ ]+: $linter[: ]" | sort
+}
+
+out=$(mktemp)
+clojure -X"$alias" :namespaces "[$namespace]" :out "\"$out\"" < /dev/null
+status=$?
+
+if [ -n "$(comm -23 <(keys "$out") <(keys "$baseline"))" ]; then
+ exit 1
+elif [ "$status" -ne 0 ] && ! grep -qE "^[^ ]+:[0-9]+:[0-9]+: " "$out"; then
+ exit 125
+fi
+exit 0
diff --git a/.github/scripts/eastwood-report.ts b/.github/scripts/eastwood-report.ts
new file mode 100644
index 00000000000..9f1a99dd79f
--- /dev/null
+++ b/.github/scripts/eastwood-report.ts
@@ -0,0 +1,406 @@
+// Turns the weekly Eastwood run's warnings into a Linear report that names the commit behind each finding.
+//
+// bun eastwood-report.ts attribute <findings.json> <base-sha|""> <previous.json|""> <target>=<warnings.txt>...
+// bun eastwood-report.ts bisect-targets <findings.json>
+// bun eastwood-report.ts report <findings.json> <bisected.txt> <final.json>
+// bun eastwood-report.ts sync <report.md> <final.json>
+//
+// A target is `source` or `tests`, the Eastwood alias that produced the warnings file (its `:out`).
+// The base is the commit the previous weekly run linted, and `previous.json` holds what that run reported.
+//
+// `attribute` carries over the findings the previous run already reported, with their causes.
+// It blames each new finding's line: a line changed since the base names its commit.
+// The rest are left for `bisect-targets`, which lists one `<target> <namespace> <linter>` per line to bisect.
+// The workflow writes each result to `bisected.txt` as `<target> <namespace> <linter> <sha>`.
+// `report` folds those in.
+import { execFileSync } from "node:child_process";
+import { existsSync, readFileSync, writeFileSync } from "node:fs";
+
+import { reportIssue } from "./report-issue";
+
+type Cause = { sha: string; subject: string };
+
+export type Finding = {
+ target: string;
+ file: string;
+ line: number;
+ column: number;
+ linter: string;
+ msg: string;
+ /** The warning without its line and column, which stays the same when unrelated edits move the code. */
+ key: string;
+ namespace?: string;
+ cause?: Cause;
+ /** The date of the run that first reported it. */
+ firstSeen?: string;
+ /** True when the previous run reported it too. */
+ carried?: boolean;
+};
+
+/** How many namespaces one run bisects. Each step lints the namespace in a fresh JVM. */
+export const MAX_BISECTS = 3;
+/** How many findings the report lists. */
+export const MAX_LISTED = 300;
+/** How long a listed message can be before it is cut. */
+export const MAX_MSG = 300;
+
+const WARNING = /^(.+?):(\d+):(\d+): ([a-z-]+)(?: \{:kind \S+\})?: (.*)$/;
+const POSITION = /^(.+?):\d+:\d+: /;
+const SOURCE_ROOT =
+ /^(?:enterprise\/backend\/(?:src|test)|modules\/drivers\/[^/]+\/(?:src|test)|dev\/(?:src|test)|src|test)\/(.+)\.clj[cs]?$/;
+
+/** The namespace a source file defines by Clojure's path convention, or undefined outside our source roots. */
+export function namespaceOf(file: string): string | undefined {
+ const match = SOURCE_ROOT.exec(file);
+ return match?.[1].replaceAll("/", ".").replaceAll("_", "-");
+}
+
+/** Warnings from an Eastwood `:out` file. A line that is not a warning continues the previous message. */
+export function parseWarnings(target: string, text: string): Finding[] {
+ const findings: Finding[] = [];
+ for (const line of text.split("\n")) {
+ const match = WARNING.exec(line);
+ if (match) {
+ const [, file, row, column, linter, msg] = match;
+ findings.push({
+ target,
+ file,
+ line: Number(row),
+ column: Number(column),
+ linter,
+ msg,
+ // eastwood-bisect-check.sh builds the same key with sed.
+ key: line.replace(POSITION, "$1: "),
+ namespace: namespaceOf(file),
+ });
+ } else if (line.trim() && !line.startsWith("Entering directory")) {
+ const last = findings.at(-1);
+ if (last) {
+ last.msg += `\n${line}`;
+ }
+ }
+ }
+ return findings;
+}
+
+/** The items grouped by key, in the order each key first appears. */
+function groupBy<T>(items: T[], keyOf: (item: T) => string): Map<string, T[]> {
+ const groups = new Map<string, T[]>();
+ for (const item of items) {
+ const key = keyOf(item);
+ const group = groups.get(key);
+ if (group) {
+ group.push(item);
+ } else {
+ groups.set(key, [item]);
+ }
+ }
+ return groups;
+}
+
+/** What identifies a finding across runs. */
+const matchKey = (finding: Finding) => `${finding.target} ${finding.key}`;
+
+/** What one bisect covers, in the `<target> <namespace> <linter>` form the workflow passes around. */
+const bisectKey = ({
+ target,
+ namespace,
+ linter,
+}: Pick<Finding, "target" | "namespace" | "linter">) =>
+ `${target} ${namespace} ${linter}`;
+
+/**
+ * The current findings, with those the previous run reported marked as carried and given its cause and
+ * first-seen date. Findings match by target and key, each previous one at most once.
+ */
+export function carryOver(
+ current: Finding[],
+ previous: Finding[],
+ today: string,
+): Finding[] {
+ const unmatched = groupBy(previous, matchKey);
+ return current.map((finding) => {
+ const match = unmatched.get(matchKey(finding))?.shift();
+ return match
+ ? {
+ ...finding,
+ cause: match.cause,
+ firstSeen: match.firstSeen,
+ carried: true,
+ }
+ : { ...finding, firstSeen: today };
+ });
+}
+
+/** One `<target> <namespace> <linter>` per new namespace and linter without a cause, at most MAX_BISECTS. */
+export function bisectTargets(findings: Finding[]): string[] {
+ const keys = findings
+ .filter(
+ (finding) => !finding.carried && !finding.cause && finding.namespace,
+ )
+ .map(bisectKey);
+ return [...new Set(keys)].slice(0, MAX_BISECTS);
+}
+
+/** The findings with each bisected commit filled in where a new finding has no cause. */
+export function applyBisected(
+ findings: Finding[],
+ bisected: string,
+ subjectOf: (sha: string) => string,
+): Finding[] {
+ const culprits = new Map<string, string>();
+ for (const line of bisected.split("\n")) {
+ const [target, namespace, linter, sha] = line.trim().split(/\s+/);
+ if (sha) {
+ culprits.set(bisectKey({ target, namespace, linter }), sha);
+ }
+ }
+ return findings.map((finding) => {
+ const sha = culprits.get(bisectKey(finding));
+ return finding.carried || finding.cause || !sha
+ ? finding
+ : { ...finding, cause: { sha, subject: subjectOf(sha) } };
+ });
+}
+
+type ReportContext = {
+ date: string;
+ runUrl: string;
+ /** `https://github.com/<owner>/<repo>` */
+ repoUrl: string;
+ headSha: string;
+ /** The commit the previous run linted, or an empty string when there was none. */
+ baseSha: string;
+};
+
+const short = (sha: string) => sha.slice(0, 11);
+
+function causeLink(cause: Cause | undefined, repoUrl: string): string {
+ if (!cause) {
+ return "Cause not found";
+ }
+ const pr = /^(.*) \(#(\d+)\)$/.exec(cause.subject);
+ return pr
+ ? `[#${pr[2]}](${repoUrl}/pull/${pr[2]}) ${pr[1]}`
+ : `[\`${short(cause.sha)}\`](${repoUrl}/commit/${cause.sha}) ${cause.subject}`;
+}
+
+function message(finding: Finding): string {
+ const flat = finding.msg.replace(/\s+/g, " ");
+ return flat.length > MAX_MSG ? `${flat.slice(0, MAX_MSG)}…` : flat;
+}
+
+function item(finding: Finding, { repoUrl, headSha }: ReportContext): string {
+ const where = `[\`${finding.file}:${finding.line}\`](${repoUrl}/blob/${headSha}/${finding.file}#L${finding.line})`;
+ return `- ${where} \`${finding.linter}\`: ${message(finding)}`;
+}
+
+/** Findings grouped under their cause as a heading and its items, the biggest group first and no cause last. */
+function byCause(
+ findings: Finding[],
+ context: ReportContext,
+ withFirstSeen: boolean,
+): string[][] {
+ const groups = groupBy(findings, (finding) => finding.cause?.sha ?? "");
+ return [...groups.entries()]
+ .sort(
+ ([a, x], [b, y]) =>
+ Number(a === "") - Number(b === "") || y.length - x.length,
+ )
+ .map(([, group]) => {
+ const firstSeen = group
+ .map((finding) => finding.firstSeen ?? "")
+ .sort()[0];
+ const seen =
+ withFirstSeen && firstSeen ? `, first seen ${firstSeen}` : "";
+ return [
+ `### ${causeLink(group[0].cause, context.repoUrl)}${seen}`,
+ ...group.map((finding) => item(finding, context)),
+ ];
+ });
+}
+
+/** The Linear description: new findings, then those still open, each grouped under its likely cause. */
+export function formatReport(
+ findings: Finding[],
+ context: ReportContext,
+): string {
+ const { date, runUrl, repoUrl, baseSha } = context;
+ const fresh = findings.filter((finding) => !finding.carried);
+ const open = findings.filter((finding) => finding.carried);
+
+ const lines = [
+ `> Generated by [\`eastwood.yml\`](${repoUrl}/blob/master/.github/workflows/eastwood.yml). Each weekly run replaces this description, so edits here are lost: comment instead.`,
+ "",
+ ];
+ const sections: [string, string[][]][] = [];
+ if (baseSha) {
+ lines.push(
+ `The weekly Eastwood run found **${findings.length} findings** on ${date} ([run](${runUrl})): ${fresh.length} new since the previous run at [\`${short(baseSha)}\`](${repoUrl}/commit/${baseSha}).`,
+ `A new finding on a line changed since then is listed under that change. The rest are bisected, up to ${MAX_BISECTS} namespaces a run.`,
+ );
+ sections.push(
+ ["New since the previous run", byCause(fresh, context, false)],
+ ["Still open", byCause(open, context, true)],
+ );
+ } else {
+ lines.push(
+ `The weekly Eastwood run found **${findings.length} findings** on ${date} ([run](${runUrl})).`,
+ "No earlier run left a report to compare with, so each finding is listed under the commit that last changed its line.",
+ );
+ sections.push(["Findings", byCause(findings, context, false)]);
+ }
+
+ let budget = MAX_LISTED;
+ for (const [title, groups] of sections) {
+ if (groups.length === 0 || budget <= 0) {
+ continue;
+ }
+ lines.push("", `## ${title}`);
+ for (const [heading, ...items] of groups) {
+ if (budget <= 0) {
+ break;
+ }
+ lines.push("", heading, "", ...items.slice(0, budget));
+ budget -= items.length;
+ }
+ }
+ if (findings.length > MAX_LISTED) {
+ lines.push("", `…and ${findings.length - MAX_LISTED} more in the run.`);
+ }
+ return lines.join("\n");
+}
+
+function git(...args: string[]): string {
+ return execFileSync("git", args, { encoding: "utf8" }).trim();
+}
+
+function isAncestor(sha: string, of: string): boolean {
+ try {
+ git("merge-base", "--is-ancestor", sha, of);
+ return true;
+ } catch {
+ return false;
+ }
+}
+
+function blame(finding: Finding): string | undefined {
+ try {
+ const porcelain = git(
+ "blame",
+ "--porcelain",
+ "-L",
+ `${finding.line},${finding.line}`,
+ "HEAD",
+ "--",
+ finding.file,
+ );
+ return porcelain.split(" ")[0];
+ } catch {
+ return undefined;
+ }
+}
+
+const subjectOf = (sha: string) => git("log", "-1", "--format=%s", sha);
+
+/**
+ * The findings with each new one blamed on the last change to its line.
+ * With a base, only a change since the base counts.
+ */
+function attribute(findings: Finding[], baseSha: string): Finding[] {
+ return findings.map((finding) => {
+ if (finding.carried) {
+ return finding;
+ }
+ const sha = blame(finding);
+ const blamed = sha && (!baseSha || !isAncestor(sha, baseSha));
+ return blamed
+ ? { ...finding, cause: { sha, subject: subjectOf(sha) } }
+ : finding;
+ });
+}
+
+const readText = (file: string) =>
+ file && existsSync(file) ? readFileSync(file, "utf8") : "";
+
+const readFindings = (file: string): Finding[] => {
+ const text = readText(file);
+ return text ? JSON.parse(text) : [];
+};
+
+const writeFindings = (file: string, findings: Finding[]) =>
+ writeFileSync(file, JSON.stringify(findings, null, 2));
+
+async function main([command, ...args]: string[]) {
+ const env = process.env;
+ const today = new Date().toISOString().slice(0, 10);
+ switch (command) {
+ case "attribute": {
+ const [out, baseSha, previous, ...inputs] = args;
+ const current = inputs.flatMap((input) => {
+ const [target, file] = input.split("=");
+ return parseWarnings(target, readText(file));
+ });
+ const findings = carryOver(current, readFindings(previous), today);
+ writeFindings(out, attribute(findings, baseSha));
+ return;
+ }
+ case "bisect-targets":
+ for (const target of bisectTargets(readFindings(args[0]))) {
+ console.log(target);
+ }
+ return;
+ case "report": {
+ const [file, bisected, out] = args;
+ const findings = applyBisected(
+ readFindings(file),
+ readText(bisected),
+ subjectOf,
+ );
+ writeFindings(out, findings);
+ console.log(
+ findings.length === 0
+ ? ""
+ : formatReport(findings, {
+ date: today,
+ runUrl: env.RUN_URL ?? "",
+ repoUrl: `${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}`,
+ headSha: env.GITHUB_SHA ?? "",
+ baseSha: env.BASE_SHA ?? "",
+ }),
+ );
+ return;
+ }
+ case "sync": {
+ const [report, file] = args;
+ const findings = readFindings(file);
+ // Without a previous report, every finding looks new, so an update says nothing.
+ const fresh = env.BASE_SHA
+ ? findings.filter((finding) => !finding.carried).length
+ : 0;
+ return reportIssue({
+ title: "metabase/metabase Eastwood report",
+ report: readText(report).trim(),
+ opened: (link) =>
+ `:broom: The weekly Eastwood run found ${findings.length} findings in metabase/metabase: ${link}`,
+ updated: (link) =>
+ fresh > 0
+ ? `:broom: The weekly Eastwood run found ${fresh} new findings in metabase/metabase, ${findings.length} in all: ${link}`
+ : undefined,
+ closed: (link) =>
+ `:white_check_mark: Eastwood passes again on metabase/metabase, closed ${link}`,
+ closedComment: `Eastwood passes as of ${env.RUN_URL}`,
+ });
+ }
+ default:
+ throw new Error(`Unknown command: ${command}`);
+ }
+}
+
+// `import.meta.main` keeps the specs, which import the helpers above, from running the script.
+if ((import.meta as ImportMeta & { main?: boolean }).main) {
+ main(process.argv.slice(2)).catch((error) => {
+ console.error(error);
+ process.exitCode = 1;
+ });
+}
diff --git a/.github/scripts/eastwood-report.unit.spec.ts b/.github/scripts/eastwood-report.unit.spec.ts
new file mode 100644
index 00000000000..08180cd4be3
--- /dev/null
+++ b/.github/scripts/eastwood-report.unit.spec.ts
@@ -0,0 +1,253 @@
+import {
+ type Finding,
+ MAX_BISECTS,
+ MAX_LISTED,
+ MAX_MSG,
+ applyBisected,
+ bisectTargets,
+ carryOver,
+ formatReport,
+ namespaceOf,
+ parseWarnings,
+} from "./eastwood-report";
+
+const finding = (overrides: Partial<Finding> = {}): Finding => ({
+ target: "tests",
+ file: "test/metabase/foo_test.clj",
+ line: 12,
+ column: 3,
+ linter: "suspicious-test",
+ msg: "Found (is ...) form",
+ key: "test/metabase/foo_test.clj: suspicious-test: Found (is ...) form",
+ namespace: "metabase.foo-test",
+ firstSeen: "2026-11-02",
+ ...overrides,
+});
+
+const context = {
+ date: "2026-11-02",
+ runUrl: "https://github.com/metabase/metabase/actions/runs/1",
+ repoUrl: "https://github.com/metabase/metabase",
+ headSha: "h".repeat(40),
+ baseSha: "b".repeat(40),
+};
+
+const headings = (report: string) =>
+ report.split("\n").filter((line) => line.startsWith("#"));
+
+describe("namespaceOf", () => {
+ it.each([
+ ["src/metabase/util/match.clj", "metabase.util.match"],
+ ["test/metabase/api/macros_test.clj", "metabase.api.macros-test"],
+ [
+ "enterprise/backend/test/metabase_enterprise/foo_test.clj",
+ "metabase-enterprise.foo-test",
+ ],
+ [
+ "modules/drivers/snowflake/src/metabase/driver/snowflake.clj",
+ "metabase.driver.snowflake",
+ ],
+ ["dev/src/dev.clj", "dev"],
+ ["src/metabase/lib/core.cljc", "metabase.lib.core"],
+ ])("reads %s as %s", (file, namespace) => {
+ expect(namespaceOf(file)).toBe(namespace);
+ });
+
+ it("knows no namespace outside the source roots", () => {
+ expect(namespaceOf("jar:file:/x.jar!/clojure/core.clj")).toBeUndefined();
+ });
+});
+
+describe("parseWarnings", () => {
+ it("reads each warning, keyed without its position, and joins continuation lines to the message", () => {
+ const text = [
+ "Entering directory `/home/runner/work/metabase/metabase'",
+ "test/metabase/foo_test.clj:12:3: suspicious-test: Found (is ...) form",
+ "src/metabase/bar.clj:7:1: unused-ret-vals {:kind :pure}: Pure value discarded",
+ "src/metabase/bar.clj:9:5: deprecations: Instance method 'public x' is deprecated.",
+ " second line",
+ "",
+ ].join("\n");
+ expect(parseWarnings("source", text)).toEqual([
+ expect.objectContaining({
+ file: "test/metabase/foo_test.clj",
+ line: 12,
+ column: 3,
+ linter: "suspicious-test",
+ key: "test/metabase/foo_test.clj: suspicious-test: Found (is ...) form",
+ namespace: "metabase.foo-test",
+ }),
+ expect.objectContaining({
+ linter: "unused-ret-vals",
+ line: 7,
+ key: "src/metabase/bar.clj: unused-ret-vals {:kind :pure}: Pure value discarded",
+ }),
+ expect.objectContaining({
+ linter: "deprecations",
+ msg: "Instance method 'public x' is deprecated.\n second line",
+ }),
+ ]);
+ });
+});
+
+describe("carryOver", () => {
+ const cause = { sha: "a".repeat(40), subject: "Old change (#85000)" };
+ const earlier = finding({ cause, firstSeen: "2026-10-19", line: 10 });
+
+ it("keeps a finding's cause and first-seen date from the previous run, even when its line moved", () => {
+ expect(carryOver([finding({ line: 14 })], [earlier], "2026-11-02")).toEqual(
+ [finding({ line: 14, cause, firstSeen: "2026-10-19", carried: true })],
+ );
+ });
+
+ it("dates a finding the previous run didn't report today, and leaves its cause to blame", () => {
+ const fresh = finding({ key: "other", firstSeen: undefined });
+ expect(carryOver([fresh], [earlier], "2026-11-02")).toEqual([
+ { ...fresh, firstSeen: "2026-11-02" },
+ ]);
+ });
+
+ it("matches each previous finding once, so a second copy of a warning is new", () => {
+ const findings = carryOver(
+ [finding(), finding({ line: 30 })],
+ [earlier],
+ "2026-11-02",
+ );
+ expect(findings.map((f) => f.carried)).toEqual([true, undefined]);
+ });
+
+ it("doesn't match the same warning from the other target", () => {
+ expect(
+ carryOver([finding({ target: "source" })], [earlier], "2026-11-02")[0]
+ .carried,
+ ).toBeUndefined();
+ });
+});
+
+describe("bisectTargets", () => {
+ it("lists each new namespace and linter blame left without a cause, once", () => {
+ expect(
+ bisectTargets([
+ finding(),
+ finding({ line: 20 }),
+ finding({ linter: "constant-test" }),
+ finding({
+ namespace: "metabase.bar-test",
+ cause: { sha: "a", subject: "x" },
+ }),
+ finding({ namespace: "metabase.baz-test", carried: true }),
+ finding({ namespace: undefined }),
+ ]),
+ ).toEqual([
+ "tests metabase.foo-test suspicious-test",
+ "tests metabase.foo-test constant-test",
+ ]);
+ });
+
+ it(`stops at ${MAX_BISECTS}`, () => {
+ const many = Array.from({ length: MAX_BISECTS + 2 }, (_, i) =>
+ finding({ namespace: `metabase.ns-${i}` }),
+ );
+ expect(bisectTargets(many)).toHaveLength(MAX_BISECTS);
+ });
+});
+
+describe("applyBisected", () => {
+ it("fills in the bisected commit only for new findings without a cause", () => {
+ const blamed = finding({ cause: { sha: "b", subject: "Blamed" } });
+ const carried = finding({ carried: true });
+ const result = applyBisected(
+ [finding(), blamed, carried, finding({ linter: "constant-test" })],
+ "tests metabase.foo-test suspicious-test c0ffee\n",
+ (sha) => `Subject of ${sha}`,
+ );
+ expect(result.map((f) => f.cause)).toEqual([
+ { sha: "c0ffee", subject: "Subject of c0ffee" },
+ { sha: "b", subject: "Blamed" },
+ undefined,
+ undefined,
+ ]);
+ });
+});
+
+describe("formatReport", () => {
+ const one = { sha: "1".repeat(40), subject: "Fix things (#85001)" };
+ const two = { sha: "2".repeat(40), subject: "Direct commit" };
+
+ it("puts new findings before those still open, each grouped under its cause", () => {
+ const report = formatReport(
+ [
+ finding({ cause: one }),
+ finding({ line: 30 }),
+ finding({ cause: two, line: 40 }),
+ finding({ cause: two, line: 50 }),
+ finding({
+ cause: one,
+ line: 60,
+ carried: true,
+ firstSeen: "2026-10-26",
+ }),
+ finding({
+ cause: one,
+ line: 70,
+ carried: true,
+ firstSeen: "2026-10-19",
+ }),
+ ],
+ context,
+ );
+ expect(headings(report)).toEqual([
+ "## New since the previous run",
+ "### [`22222222222`](https://github.com/metabase/metabase/commit/2222222222222222222222222222222222222222) Direct commit",
+ "### [#85001](https://github.com/metabase/metabase/pull/85001) Fix things",
+ "### Cause not found",
+ "## Still open",
+ "### [#85001](https://github.com/metabase/metabase/pull/85001) Fix things, first seen 2026-10-19",
+ ]);
+ expect(report).toContain(
+ "found **6 findings** on 2026-11-02 ([run](https://github.com/metabase/metabase/actions/runs/1)): 4 new since the previous run at [`bbbbbbbbbbb`]",
+ );
+ expect(report).toContain(
+ "- [`test/metabase/foo_test.clj:12`](https://github.com/metabase/metabase/blob/hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh/test/metabase/foo_test.clj#L12) `suspicious-test`: Found (is ...) form",
+ );
+ });
+
+ it(`lists at most ${MAX_LISTED} findings and counts the rest`, () => {
+ const many = Array.from({ length: MAX_LISTED + 5 }, (_, i) =>
+ finding({ line: i + 1 }),
+ );
+ const report = formatReport(many, context);
+ expect(
+ report.split("\n").filter((line) => line.startsWith("- ")),
+ ).toHaveLength(MAX_LISTED);
+ expect(report).toContain("…and 5 more in the run.");
+ });
+
+ it(`cuts a message at ${MAX_MSG} characters, and puts it on one line`, () => {
+ const report = formatReport(
+ [finding({ msg: `first\nsecond ${"x".repeat(MAX_MSG)}` })],
+ context,
+ );
+ const item = report.split("\n").find((line) => line.startsWith("- "));
+ expect(item).toMatch(/`suspicious-test`: first second x+…$/);
+ expect(item?.split("`: ")[1]).toHaveLength(MAX_MSG + 1);
+ });
+
+ it("leaves out a section with nothing in it", () => {
+ expect(
+ headings(formatReport([finding({ carried: true })], context)),
+ ).toEqual(["## Still open", "### Cause not found, first seen 2026-11-02"]);
+ });
+
+ it("lists everything together, under the last change to each line, when there is no previous run", () => {
+ const report = formatReport([finding({ cause: one })], {
+ ...context,
+ baseSha: "",
+ });
+ expect(headings(report)).toEqual([
+ "## Findings",
+ "### [#85001](https://github.com/metabase/metabase/pull/85001) Fix things",
+ ]);
+ expect(report).toContain("No earlier run left a report to compare with");
+ });
+});
diff --git a/.github/scripts/report-issue.ts b/.github/scripts/report-issue.ts
new file mode 100644
index 00000000000..10a964a39a3
--- /dev/null
+++ b/.github/scripts/report-issue.ts
@@ -0,0 +1,127 @@
+// Keeps one open Linear issue per scheduled check, found by its title.
+// A non-empty report opens the issue or replaces its description; an empty one closes it with a comment.
+// Slack hears when it opens or closes, and on an update when the caller has something to say.
+//
+// Needs LINEAR_API_KEY, LINEAR_TEAM_ID, SLACK_BOT_TOKEN and SLACK_CHANNEL in the environment.
+
+type Issue = { id: string; identifier: string; url: string };
+
+export type ReportIssueOptions = {
+ title: string;
+ /** Markdown description, or an empty string when the check passed. */
+ report: string;
+ /** Slack message when the issue opens. */
+ opened: (link: string) => string;
+ /** Slack message when a report replaces the open issue's description, if any. */
+ updated?: (link: string) => string | undefined;
+ /** Slack message when the issue closes. */
+ closed: (link: string) => string;
+ /** Comment left on the issue when it closes. */
+ closedComment: string;
+};
+
+async function linear<T>(
+ query: string,
+ variables: Record<string, unknown> = {},
+): Promise<T> {
+ const response = await fetch("https://api.linear.app/graphql", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: process.env.LINEAR_API_KEY ?? "",
+ },
+ body: JSON.stringify({ query, variables }),
+ });
+ // The GraphQL API answers with `data` or `errors`, checked below.
+ const body = (await response.json()) as { data?: T; errors?: unknown };
+ if (!response.ok || body.errors || !body.data) {
+ throw new Error(
+ `Linear API error: ${JSON.stringify(body.errors ?? response.status)}`,
+ );
+ }
+ return body.data;
+}
+
+async function slack(text: string) {
+ const response = await fetch("https://slack.com/api/chat.postMessage", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json; charset=utf-8",
+ Authorization: `Bearer ${process.env.SLACK_BOT_TOKEN}`,
+ },
+ body: JSON.stringify({ channel: process.env.SLACK_CHANNEL, text }),
+ });
+ // Slack answers every call with `ok`, and `error` when it is false.
+ const body = (await response.json()) as { ok: boolean; error?: string };
+ if (!body.ok) {
+ throw new Error(`Slack API error: ${body.error}`);
+ }
+}
+
+const link = (issue: Issue) => `<${issue.url}|${issue.identifier}>`;
+
+export async function reportIssue({
+ title,
+ report,
+ opened,
+ updated,
+ closed,
+ closedComment,
+}: ReportIssueOptions) {
+ const teamId = process.env.LINEAR_TEAM_ID;
+
+ const { issues } = await linear<{ issues: { nodes: Issue[] } }>(
+ `query($teamId: ID!, $title: String!) {
+ issues(first: 1, filter: {
+ team: { id: { eq: $teamId } },
+ title: { eq: $title },
+ state: { type: { nin: ["completed", "canceled"] } }
+ }) { nodes { id identifier url } }
+ }`,
+ { teamId, title },
+ );
+ const open = issues.nodes[0];
+
+ if (report && open) {
+ await linear(
+ `mutation($id: String!, $description: String!) {
+ issueUpdate(id: $id, input: { description: $description }) { success }
+ }`,
+ { id: open.id, description: report },
+ );
+ const text = updated?.(link(open));
+ if (text) {
+ await slack(text);
+ }
+ console.log(`Updated ${open.identifier}`);
+ } else if (report) {
+ const { issueCreate } = await linear<{ issueCreate: { issue: Issue } }>(
+ `mutation($teamId: String!, $title: String!, $description: String!) {
+ issueCreate(input: { teamId: $teamId, title: $title, description: $description }) {
+ issue { id identifier url }
+ }
+ }`,
+ { teamId, title, description: report },
+ );
+ await slack(opened(link(issueCreate.issue)));
+ console.log(`Opened ${issueCreate.issue.identifier}`);
+ } else if (open) {
+ const { team } = await linear<{
+ team: { states: { nodes: { id: string }[] } };
+ }>(
+ `query($teamId: String!) {
+ team(id: $teamId) { states(filter: { type: { eq: "completed" } }) { nodes { id } } }
+ }`,
+ { teamId },
+ );
+ await linear(
+ `mutation($id: String!, $stateId: String!, $body: String!) {
+ issueUpdate(id: $id, input: { stateId: $stateId }) { success }
+ commentCreate(input: { issueId: $id, body: $body }) { success }
+ }`,
+ { id: open.id, stateId: team.states.nodes[0].id, body: closedComment },
+ );
+ await slack(closed(link(open)));
+ console.log(`Closed ${open.identifier}`);
+ }
+}
diff --git a/.github/scripts/report-links.ts b/.github/scripts/report-links.ts
index a858dfbae23..c0fbabc5cf4 100644
--- a/.github/scripts/report-links.ts
+++ b/.github/scripts/report-links.ts
@@ -2,108 +2,16 @@
// A non-empty report opens the Linear issue or replaces its description; an empty or missing one closes it.
import { existsSync, readFileSync } from "node:fs";
-const TITLE = "metabase/metabase broken links report";
-
-type Issue = { id: string; identifier: string; url: string };
-
-async function linear<T>(
- query: string,
- variables: Record<string, unknown> = {},
-): Promise<T> {
- const response = await fetch("https://api.linear.app/graphql", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- Authorization: process.env.LINEAR_API_KEY ?? "",
- },
- body: JSON.stringify({ query, variables }),
- });
- const body = (await response.json()) as { data?: T; errors?: unknown };
- if (!response.ok || body.errors || !body.data) {
- throw new Error(
- `Linear API error: ${JSON.stringify(body.errors ?? response.status)}`,
- );
- }
- return body.data;
-}
-
-async function slack(text: string) {
- const response = await fetch("https://slack.com/api/chat.postMessage", {
- method: "POST",
- headers: {
- "Content-Type": "application/json; charset=utf-8",
- Authorization: `Bearer ${process.env.SLACK_BOT_TOKEN}`,
- },
- body: JSON.stringify({ channel: process.env.SLACK_CHANNEL, text }),
- });
- const body = (await response.json()) as { ok: boolean; error?: string };
- if (!body.ok) {
- throw new Error(`Slack API error: ${body.error}`);
- }
-}
+import { reportIssue } from "./report-issue";
const file = process.argv[2];
-const report =
- file && existsSync(file) ? readFileSync(file, "utf8").trim() : "";
-const teamId = process.env.LINEAR_TEAM_ID;
-const runUrl = process.env.RUN_URL;
-const link = (issue: Issue) => `<${issue.url}|${issue.identifier}>`;
-
-const { issues } = await linear<{ issues: { nodes: Issue[] } }>(
- `query($teamId: ID!, $title: String!) {
- issues(first: 1, filter: {
- team: { id: { eq: $teamId } },
- title: { eq: $title },
- state: { type: { nin: ["completed", "canceled"] } }
- }) { nodes { id identifier url } }
- }`,
- { teamId, title: TITLE },
-);
-const open = issues.nodes[0];
-if (report && open) {
- await linear(
- `mutation($id: String!, $description: String!) {
- issueUpdate(id: $id, input: { description: $description }) { success }
- }`,
- { id: open.id, description: report },
- );
- console.log(`Updated ${open.identifier}`);
-} else if (report) {
- const { issueCreate } = await linear<{ issueCreate: { issue: Issue } }>(
- `mutation($teamId: String!, $title: String!, $description: String!) {
- issueCreate(input: { teamId: $teamId, title: $title, description: $description }) {
- issue { id identifier url }
- }
- }`,
- { teamId, title: TITLE, description: report },
- );
- await slack(
- `:link: The weekly link check found broken links in metabase/metabase: ${link(issueCreate.issue)}`,
- );
- console.log(`Opened ${issueCreate.issue.identifier}`);
-} else if (open) {
- const { team } = await linear<{
- team: { states: { nodes: { id: string }[] } };
- }>(
- `query($teamId: String!) {
- team(id: $teamId) { states(filter: { type: { eq: "completed" } }) { nodes { id } } }
- }`,
- { teamId },
- );
- await linear(
- `mutation($id: String!, $stateId: String!, $body: String!) {
- issueUpdate(id: $id, input: { stateId: $stateId }) { success }
- commentCreate(input: { issueId: $id, body: $body }) { success }
- }`,
- {
- id: open.id,
- stateId: team.states.nodes[0].id,
- body: `All links pass as of ${runUrl}`,
- },
- );
- await slack(
- `:white_check_mark: All links in metabase/metabase pass again, closed ${link(open)}`,
- );
- console.log(`Closed ${open.identifier}`);
-}
+await reportIssue({
+ title: "metabase/metabase broken links report",
+ report: file && existsSync(file) ? readFileSync(file, "utf8").trim() : "",
+ opened: (link) =>
+ `:link: The weekly link check found broken links in metabase/metabase: ${link}`,
+ closed: (link) =>
+ `:white_check_mark: All links in metabase/metabase pass again, closed ${link}`,
+ closedComment: `All links pass as of ${process.env.RUN_URL}`,
+});
diff --git a/.github/workflows/cache-warm.yml b/.github/workflows/cache-warm.yml
index 7e22320473f..79c46598ec5 100644
--- a/.github/workflows/cache-warm.yml
+++ b/.github/workflows/cache-warm.yml
@@ -118,6 +118,8 @@ jobs:
combos=(
":build:dev:ee:ee-dev:drivers:drivers-dev:cljs" # build + uberjar (combined classpath)
":cljs" # shadow-cljs (build:cljs); resolves :cljs alone -> covers asm:9.2
+ ":dev:ee:ee-dev:drivers:drivers-dev:test:eastwood" # eastwood.yml (source)
+ ":dev:dev/test:ee:ee-dev:drivers:drivers-dev:test:eastwood/test" # eastwood.yml (tests)
":dev:dev/test:ee:ee-dev:drivers:drivers-dev:test:ci" # run-tests.yml (project tests)
":dev:ci:ee:ee-dev:drivers:drivers-dev:test" # test-driver.yml (ee) -> covers data.json:2.4.0
":dev:ci:oss:oss-dev:drivers:drivers-dev:test" # test-driver.yml (oss)
diff --git a/.github/workflows/eastwood.yml b/.github/workflows/eastwood.yml
new file mode 100644
index 00000000000..87530661088
--- /dev/null
+++ b/.github/workflows/eastwood.yml
@@ -0,0 +1,194 @@
+name: Eastwood
+
+# Eastwood is too slow for PR CI: linting every test namespace takes about an hour. So it runs weekly, and on
+# master one open Linear issue lists the findings under the commit that most likely caused each one. Each run
+# compares with the previous one, so a finding still open from an earlier week keeps its cause and first-seen
+# date, and only the new ones are traced.
+# A manual run on another branch lints that branch and reports nothing.
+
+on:
+ schedule:
+ # Mondays at 03:00 UTC
+ - cron: "0 3 * * 1"
+ workflow_dispatch:
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+
+jobs:
+ lint:
+ name: Eastwood (${{ matrix.target }})
+ if: ${{ github.event_name != 'schedule' || github.repository == 'metabase/metabase' }}
+ runs-on: ${{ vars.DEFAULT_RUNNER_KEY }}
+ timeout-minutes: 120
+ permissions:
+ contents: read
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - target: source
+ command: clojure -X:dev:ee:ee-dev:drivers:drivers-dev:test:eastwood
+ - target: tests
+ command: clojure -X:dev:dev/test:ee:ee-dev:drivers:drivers-dev:test:eastwood/test
+ steps:
+ - uses: actions/checkout@v7
+ - name: Prepare back-end environment
+ uses: ./.github/actions/prepare-backend
+ - name: Run Eastwood
+ id: lint
+ continue-on-error: true
+ run: ${{ matrix.command }} :out '"warnings.txt"' 2>&1 | tee lint.log
+ # Eastwood stops at the first exception, so only its closing summary shows it linted every namespace.
+ - name: Save the outcome and show the warnings
+ run: |
+ if grep -qE '^== Warnings: [0-9]+\. Exceptions thrown: 0$' lint.log; then
+ echo complete > outcome.txt
+ else
+ echo incomplete > outcome.txt
+ fi
+ touch warnings.txt
+ cat warnings.txt
+ - uses: actions/upload-artifact@v7
+ with:
+ name: eastwood-${{ matrix.target }}
+ path: |
+ outcome.txt
+ warnings.txt
+
+ report:
+ name: Report Eastwood findings
+ needs: lint
+ if: ${{ !cancelled() && (github.event_name != 'schedule' || github.repository == 'metabase/metabase') }}
+ runs-on: ${{ vars.DEFAULT_RUNNER_KEY }}
+ timeout-minutes: 120
+ permissions:
+ actions: read
+ contents: read
+ env:
+ RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
+ SLACK_CHANNEL: C5XHN8GLW # #engineering-ci
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ # Blame and bisect need the history back to the previous run.
+ fetch-depth: 0
+ - uses: actions/download-artifact@v8
+ with:
+ pattern: eastwood-*
+ path: eastwood
+ - name: Install bun
+ uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
+ with:
+ bun-version-file: "package.json"
+ token: ${{ secrets.GITHUB_TOKEN }}
+
+ # A partial run would make the findings it didn't reach look fixed.
+ - name: Check that both targets linted everything
+ run: |
+ ran=true
+ for target in source tests; do
+ if [ "$(cat "eastwood/eastwood-$target/outcome.txt" 2>/dev/null)" != complete ]; then
+ echo "::error::Eastwood didn't finish linting $target. See its job log."
+ ran=false
+ fi
+ done
+ $ran
+
+ # The latest earlier run on this branch that saved a report, passing or not.
+ # A run that couldn't lint saves none, so the comparison skips it.
+ - name: Fetch the previous run's report
+ id: previous
+ env:
+ GH_TOKEN: ${{ github.token }}
+ BRANCH: ${{ github.ref_name }}
+ run: |
+ runs=$(gh run list --workflow eastwood.yml --branch "$BRANCH" --status completed --limit 10 \
+ --json databaseId,headSha --jq '.[] | "\(.databaseId) \(.headSha)"')
+ while read -r id sha; do
+ if [ -n "$id" ] && gh run download "$id" --name eastwood-report --dir previous 2>/dev/null; then
+ echo "Comparing with run $id at $sha"
+ echo "base=$sha" >> "$GITHUB_OUTPUT"
+ break
+ fi
+ done <<< "$runs"
+
+ - name: Blame the new findings
+ id: blame
+ env:
+ BASE_SHA: ${{ steps.previous.outputs.base }}
+ run: |
+ bun .github/scripts/eastwood-report.ts attribute findings.json "$BASE_SHA" previous/findings.json \
+ source=eastwood/eastwood-source/warnings.txt tests=eastwood/eastwood-tests/warnings.txt
+ bun .github/scripts/eastwood-report.ts bisect-targets findings.json > bisect-targets.txt
+ echo "Left for bisecting:"
+ cat bisect-targets.txt
+ if [ -n "$BASE_SHA" ] && [ -s bisect-targets.txt ]; then
+ echo "bisect=true" >> "$GITHUB_OUTPUT"
+ fi
+
+ - name: Prepare back-end environment
+ if: steps.blame.outputs.bisect == 'true'
+ uses: ./.github/actions/prepare-backend
+
+ - name: Bisect the new findings blame left without a cause
+ if: steps.blame.outputs.bisect == 'true'
+ env:
+ BASE_SHA: ${{ steps.previous.outputs.base }}
+ run: |
+ # Older commits may not have the check, so it runs from outside the checkout.
+ check=$RUNNER_TEMP/eastwood-bisect-check.sh
+ log=$RUNNER_TEMP/bisect.log
+ cp .github/scripts/eastwood-bisect-check.sh "$check"
+ while read -r target namespace linter <&3; do
+ echo "::group::Bisect $linter in $namespace"
+ git bisect start HEAD "$BASE_SHA"
+ git bisect run "$check" "$target" "$namespace" "$linter" "$PWD/previous/warnings-$target.txt" 2>&1 \
+ | tee "$log" || true
+ # When every candidate was skipped, bisect names no commit.
+ if grep -qE "is the first '?bad'? commit" "$log"; then
+ echo "$target $namespace $linter $(git rev-parse refs/bisect/bad)" >> bisected.txt
+ fi
+ git bisect reset
+ echo "::endgroup::"
+ done 3< bisect-targets.txt
+
+ - name: Build the report
+ env:
+ BASE_SHA: ${{ steps.previous.outputs.base }}
+ run: |
+ mkdir report
+ bun .github/scripts/eastwood-report.ts report findings.json bisected.txt report/findings.json > report.md
+ cp eastwood/eastwood-source/warnings.txt report/warnings-source.txt
+ cp eastwood/eastwood-tests/warnings.txt report/warnings-tests.txt
+ cat report.md >> "$GITHUB_STEP_SUMMARY"
+
+ # The next run compares with this one.
+ - uses: actions/upload-artifact@v7
+ with:
+ name: eastwood-report
+ path: report
+ retention-days: 90
+
+ - name: Open, update, or close the Eastwood issue
+ if: github.ref == 'refs/heads/master'
+ env:
+ LINEAR_API_KEY: ${{ secrets.LINEAR_API_KEY }}
+ LINEAR_TEAM_ID: 2e3af6a2-9b19-4abd-b72c-4b5665054861 # DEV
+ SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
+ BASE_SHA: ${{ steps.previous.outputs.base }}
+ run: bun .github/scripts/eastwood-report.ts sync report.md report/findings.json
+
+ - name: Alert when Eastwood can't run
+ if: failure() && github.ref == 'refs/heads/master'
+ env:
+ SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
+ run: |
+ jq -n --arg channel "$SLACK_CHANNEL" --arg text ":x: The weekly Eastwood run on metabase/metabase failed to run: $RUN_URL" \
+ '{channel: $channel, text: $text}' |
+ curl -sSf https://slack.com/api/chat.postMessage \
+ -H "Authorization: Bearer $SLACK_BOT_TOKEN" \
+ -H "Content-Type: application/json; charset=utf-8" --data @-
+
+ - name: Fail the run on findings
+ run: test "$(jq length report/findings.json)" = 0