From eb57dbd844c65224f99492cb0b48729df2e0bc55 Mon Sep 17 00:00:00 2001 From: shreyas-goenka <88374338+shreyas-goenka@users.noreply.github.com> Date: Thu, 27 Feb 2025 20:29:00 +0530 Subject: [PATCH] Add warning when include is used in config files other than databricks.yml (#2389) ## Changes Defining an include section in config files other than the main `databricks.yml` file fails silently. With this PR users will get a warning when they try this. ## Tests Acceptance test. --- .../bundle/includes/include_outside_root/a.yml | 4 ++++ .../includes/include_outside_root/databricks.yml | 5 +++++ .../includes/include_outside_root/output.txt | 16 ++++++++++++++++ .../bundle/includes/include_outside_root/script | 1 + bundle/config/loader/process_include.go | 13 +++++++++++++ 5 files changed, 39 insertions(+) create mode 100644 acceptance/bundle/includes/include_outside_root/a.yml create mode 100644 acceptance/bundle/includes/include_outside_root/databricks.yml create mode 100644 acceptance/bundle/includes/include_outside_root/output.txt create mode 100644 acceptance/bundle/includes/include_outside_root/script diff --git a/acceptance/bundle/includes/include_outside_root/a.yml b/acceptance/bundle/includes/include_outside_root/a.yml new file mode 100644 index 000000000..b4addb99b --- /dev/null +++ b/acceptance/bundle/includes/include_outside_root/a.yml @@ -0,0 +1,4 @@ +include: + - b.yml + - c.yml + diff --git a/acceptance/bundle/includes/include_outside_root/databricks.yml b/acceptance/bundle/includes/include_outside_root/databricks.yml new file mode 100644 index 000000000..6addb7d2f --- /dev/null +++ b/acceptance/bundle/includes/include_outside_root/databricks.yml @@ -0,0 +1,5 @@ +bundle: + name: include_outside_root + +include: + - a.yml diff --git a/acceptance/bundle/includes/include_outside_root/output.txt b/acceptance/bundle/includes/include_outside_root/output.txt new file mode 100644 index 000000000..720c3a826 --- /dev/null +++ b/acceptance/bundle/includes/include_outside_root/output.txt @@ -0,0 +1,16 @@ +Warning: Include section is defined outside root file + at include + in a.yml:2:3 + +The include section is defined in a file that is not the root file. +These values will be ignored because only the includes defined in +the bundle root file (that is databricks.yml or databricks.yaml) +are loaded. + +Name: include_outside_root +Target: default +Workspace: + User: [USERNAME] + Path: /Workspace/Users/[USERNAME]/.bundle/include_outside_root/default + +Found 1 warning diff --git a/acceptance/bundle/includes/include_outside_root/script b/acceptance/bundle/includes/include_outside_root/script new file mode 100644 index 000000000..72555b332 --- /dev/null +++ b/acceptance/bundle/includes/include_outside_root/script @@ -0,0 +1 @@ +$CLI bundle validate diff --git a/bundle/config/loader/process_include.go b/bundle/config/loader/process_include.go index f82f5db1e..4f7dd47ca 100644 --- a/bundle/config/loader/process_include.go +++ b/bundle/config/loader/process_include.go @@ -161,6 +161,19 @@ func (m *processInclude) Apply(_ context.Context, b *bundle.Bundle) diag.Diagnos return diags } + if len(this.Include) > 0 { + diags = diags.Append(diag.Diagnostic{ + Severity: diag.Warning, + Summary: "Include section is defined outside root file", + Detail: `The include section is defined in a file that is not the root file. +These values will be ignored because only the includes defined in +the bundle root file (that is databricks.yml or databricks.yaml) +are loaded.`, + Locations: this.GetLocations("include"), + Paths: []dyn.Path{dyn.MustPathFromString("include")}, + }) + } + err := b.Config.Merge(this) if err != nil { diags = diags.Extend(diag.FromErr(err))