From d1848263e2c0506703e33385ee33612ede0e9c13 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Tue, 21 Jan 2025 14:30:24 +0000 Subject: [PATCH 1/6] Show an error when non-yaml files used in include section --- .../bundle/includes/non_yaml_in_include/databricks.yml | 6 ++++++ acceptance/bundle/includes/non_yaml_in_include/output.txt | 7 +++++++ acceptance/bundle/includes/non_yaml_in_include/script | 1 + acceptance/bundle/includes/non_yaml_in_include/test.py | 1 + bundle/config/loader/process_root_includes.go | 3 +++ 5 files changed, 18 insertions(+) create mode 100644 acceptance/bundle/includes/non_yaml_in_include/databricks.yml create mode 100644 acceptance/bundle/includes/non_yaml_in_include/output.txt create mode 100644 acceptance/bundle/includes/non_yaml_in_include/script create mode 100644 acceptance/bundle/includes/non_yaml_in_include/test.py diff --git a/acceptance/bundle/includes/non_yaml_in_include/databricks.yml b/acceptance/bundle/includes/non_yaml_in_include/databricks.yml new file mode 100644 index 0000000000..3fd3558ea4 --- /dev/null +++ b/acceptance/bundle/includes/non_yaml_in_include/databricks.yml @@ -0,0 +1,6 @@ +bundle: + name: non_yaml_in_includes + +include: + - resources/*.yml + - test.py diff --git a/acceptance/bundle/includes/non_yaml_in_include/output.txt b/acceptance/bundle/includes/non_yaml_in_include/output.txt new file mode 100644 index 0000000000..974e21d1e4 --- /dev/null +++ b/acceptance/bundle/includes/non_yaml_in_include/output.txt @@ -0,0 +1,7 @@ +Error: file test.py included in 'include' section but only YAML files are supported. If you want to explicitly include files to sync, use 'sync.include' configuration section + +Name: non_yaml_in_includes + +Found 1 error + +Exit code: 1 diff --git a/acceptance/bundle/includes/non_yaml_in_include/script b/acceptance/bundle/includes/non_yaml_in_include/script new file mode 100644 index 0000000000..72555b332a --- /dev/null +++ b/acceptance/bundle/includes/non_yaml_in_include/script @@ -0,0 +1 @@ +$CLI bundle validate diff --git a/acceptance/bundle/includes/non_yaml_in_include/test.py b/acceptance/bundle/includes/non_yaml_in_include/test.py new file mode 100644 index 0000000000..44159b3954 --- /dev/null +++ b/acceptance/bundle/includes/non_yaml_in_include/test.py @@ -0,0 +1 @@ +print("Hello world") diff --git a/bundle/config/loader/process_root_includes.go b/bundle/config/loader/process_root_includes.go index c608a3de61..ccf4f514a4 100644 --- a/bundle/config/loader/process_root_includes.go +++ b/bundle/config/loader/process_root_includes.go @@ -69,6 +69,9 @@ func (m *processRootIncludes) Apply(ctx context.Context, b *bundle.Bundle) diag. continue } seen[rel] = true + if filepath.Ext(rel) != ".yaml" && filepath.Ext(rel) != ".yml" { + return diag.Errorf("file %s included in 'include' section but only YAML files are supported. If you want to explicitly include files to sync, use 'sync.include' configuration section", rel) + } includes = append(includes, rel) } From f4a2efe9c6e79fdf41b5d38a2592cf368e3c2f1c Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Tue, 21 Jan 2025 14:42:38 +0000 Subject: [PATCH 2/6] added summary and location --- .../bundle/includes/non_yaml_in_include/output.txt | 5 ++++- bundle/config/loader/process_root_includes.go | 14 +++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/acceptance/bundle/includes/non_yaml_in_include/output.txt b/acceptance/bundle/includes/non_yaml_in_include/output.txt index 974e21d1e4..25f337ef57 100644 --- a/acceptance/bundle/includes/non_yaml_in_include/output.txt +++ b/acceptance/bundle/includes/non_yaml_in_include/output.txt @@ -1,4 +1,7 @@ -Error: file test.py included in 'include' section but only YAML files are supported. If you want to explicitly include files to sync, use 'sync.include' configuration section +Error: non-yaml file in 'include' section + in databricks.yml:5:2 + +file test.py included in 'include' section but only YAML files are supported. If you want to explicitly include files to sync, use 'sync.include' configuration section Name: non_yaml_in_includes diff --git a/bundle/config/loader/process_root_includes.go b/bundle/config/loader/process_root_includes.go index ccf4f514a4..2cd16b5cc9 100644 --- a/bundle/config/loader/process_root_includes.go +++ b/bundle/config/loader/process_root_includes.go @@ -2,6 +2,7 @@ package loader import ( "context" + "fmt" "path/filepath" "slices" "strings" @@ -36,6 +37,7 @@ func (m *processRootIncludes) Apply(ctx context.Context, b *bundle.Bundle) diag. // Maintain list of files in order of files being loaded. // This is stored in the bundle configuration for observability. var files []string + var diags diag.Diagnostics // For each glob, find all files to load. // Ordering of the list of globs is maintained in the output. @@ -70,11 +72,21 @@ func (m *processRootIncludes) Apply(ctx context.Context, b *bundle.Bundle) diag. } seen[rel] = true if filepath.Ext(rel) != ".yaml" && filepath.Ext(rel) != ".yml" { - return diag.Errorf("file %s included in 'include' section but only YAML files are supported. If you want to explicitly include files to sync, use 'sync.include' configuration section", rel) + diags = diags.Append(diag.Diagnostic{ + Severity: diag.Error, + Summary: "non-yaml file in 'include' section", + Detail: fmt.Sprintf("file %s included in 'include' section but only YAML files are supported. If you want to explicitly include files to sync, use 'sync.include' configuration section", rel), + Locations: b.Config.GetLocations("include"), + }) + continue } includes = append(includes, rel) } + if len(diags) > 0 { + return diags + } + // Add matches to list of mutators to return. slices.Sort(includes) files = append(files, includes...) From 403249d664e54ce701aeb6177f9b80bd2b7da3a7 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Tue, 21 Jan 2025 15:13:11 +0000 Subject: [PATCH 3/6] fixed location --- acceptance/bundle/includes/non_yaml_in_include/databricks.yml | 2 +- acceptance/bundle/includes/non_yaml_in_include/output.txt | 2 +- bundle/config/loader/process_root_includes.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/acceptance/bundle/includes/non_yaml_in_include/databricks.yml b/acceptance/bundle/includes/non_yaml_in_include/databricks.yml index 3fd3558ea4..162bd60133 100644 --- a/acceptance/bundle/includes/non_yaml_in_include/databricks.yml +++ b/acceptance/bundle/includes/non_yaml_in_include/databricks.yml @@ -2,5 +2,5 @@ bundle: name: non_yaml_in_includes include: - - resources/*.yml - test.py + - resources/*.yml diff --git a/acceptance/bundle/includes/non_yaml_in_include/output.txt b/acceptance/bundle/includes/non_yaml_in_include/output.txt index 25f337ef57..e636dcf2e2 100644 --- a/acceptance/bundle/includes/non_yaml_in_include/output.txt +++ b/acceptance/bundle/includes/non_yaml_in_include/output.txt @@ -1,5 +1,5 @@ Error: non-yaml file in 'include' section - in databricks.yml:5:2 + in databricks.yml:5:4 file test.py included in 'include' section but only YAML files are supported. If you want to explicitly include files to sync, use 'sync.include' configuration section diff --git a/bundle/config/loader/process_root_includes.go b/bundle/config/loader/process_root_includes.go index 2cd16b5cc9..ced861810f 100644 --- a/bundle/config/loader/process_root_includes.go +++ b/bundle/config/loader/process_root_includes.go @@ -62,7 +62,7 @@ func (m *processRootIncludes) Apply(ctx context.Context, b *bundle.Bundle) diag. // Filter matches to ones we haven't seen yet. var includes []string - for _, match := range matches { + for i, match := range matches { rel, err := filepath.Rel(b.BundleRootPath, match) if err != nil { return diag.FromErr(err) @@ -76,7 +76,7 @@ func (m *processRootIncludes) Apply(ctx context.Context, b *bundle.Bundle) diag. Severity: diag.Error, Summary: "non-yaml file in 'include' section", Detail: fmt.Sprintf("file %s included in 'include' section but only YAML files are supported. If you want to explicitly include files to sync, use 'sync.include' configuration section", rel), - Locations: b.Config.GetLocations("include"), + Locations: b.Config.GetLocations(fmt.Sprintf("include[%d]", i)), }) continue } From abe8168ed1cdde5766d82bdcc11cee97657be7f3 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Thu, 23 Jan 2025 13:58:41 +0100 Subject: [PATCH 4/6] Update bundle/config/loader/process_root_includes.go Co-authored-by: Julia Crawford (Databricks) --- bundle/config/loader/process_root_includes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/config/loader/process_root_includes.go b/bundle/config/loader/process_root_includes.go index ced861810f..94005391f7 100644 --- a/bundle/config/loader/process_root_includes.go +++ b/bundle/config/loader/process_root_includes.go @@ -74,7 +74,7 @@ func (m *processRootIncludes) Apply(ctx context.Context, b *bundle.Bundle) diag. if filepath.Ext(rel) != ".yaml" && filepath.Ext(rel) != ".yml" { diags = diags.Append(diag.Diagnostic{ Severity: diag.Error, - Summary: "non-yaml file in 'include' section", + Summary: "Files in the 'include' configuration section must be YAML files.", Detail: fmt.Sprintf("file %s included in 'include' section but only YAML files are supported. If you want to explicitly include files to sync, use 'sync.include' configuration section", rel), Locations: b.Config.GetLocations(fmt.Sprintf("include[%d]", i)), }) From 4789d1fc833008f3c485c14d04fb7187e63dd86f Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Thu, 23 Jan 2025 13:58:48 +0100 Subject: [PATCH 5/6] Update bundle/config/loader/process_root_includes.go Co-authored-by: Julia Crawford (Databricks) --- bundle/config/loader/process_root_includes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/config/loader/process_root_includes.go b/bundle/config/loader/process_root_includes.go index 94005391f7..1980957420 100644 --- a/bundle/config/loader/process_root_includes.go +++ b/bundle/config/loader/process_root_includes.go @@ -75,7 +75,7 @@ func (m *processRootIncludes) Apply(ctx context.Context, b *bundle.Bundle) diag. diags = diags.Append(diag.Diagnostic{ Severity: diag.Error, Summary: "Files in the 'include' configuration section must be YAML files.", - Detail: fmt.Sprintf("file %s included in 'include' section but only YAML files are supported. If you want to explicitly include files to sync, use 'sync.include' configuration section", rel), + Detail: fmt.Sprintf("The file %s in the 'include' configuration section is not a YAML file, and only YAML files are supported. To include files to sync, specify them in the 'sync.include' configuration section instead.", rel), Locations: b.Config.GetLocations(fmt.Sprintf("include[%d]", i)), }) continue From 851e5bb8f71ccaf03b580d90eeb8f2722336ea2f Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Thu, 23 Jan 2025 13:05:57 +0000 Subject: [PATCH 6/6] update golden file --- acceptance/bundle/includes/non_yaml_in_include/output.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/acceptance/bundle/includes/non_yaml_in_include/output.txt b/acceptance/bundle/includes/non_yaml_in_include/output.txt index e636dcf2e2..6006ca14e2 100644 --- a/acceptance/bundle/includes/non_yaml_in_include/output.txt +++ b/acceptance/bundle/includes/non_yaml_in_include/output.txt @@ -1,7 +1,7 @@ -Error: non-yaml file in 'include' section +Error: Files in the 'include' configuration section must be YAML files. in databricks.yml:5:4 -file test.py included in 'include' section but only YAML files are supported. If you want to explicitly include files to sync, use 'sync.include' configuration section +The file test.py in the 'include' configuration section is not a YAML file, and only YAML files are supported. To include files to sync, specify them in the 'sync.include' configuration section instead. Name: non_yaml_in_includes