mirror of https://github.com/databricks/cli.git
Show an error when non-yaml files used in include section (#2201)
## Changes `include` section is used only to include other bundle configuration YAML files. If any other file type is used, raise an error and guide users to use `sync.include` instead ## Tests Added acceptance test --------- Co-authored-by: Julia Crawford (Databricks) <julia.crawford@databricks.com>
This commit is contained in:
parent
6153423c56
commit
8af9efaa62
|
@ -0,0 +1,6 @@
|
||||||
|
bundle:
|
||||||
|
name: non_yaml_in_includes
|
||||||
|
|
||||||
|
include:
|
||||||
|
- test.py
|
||||||
|
- resources/*.yml
|
|
@ -0,0 +1,10 @@
|
||||||
|
Error: Files in the 'include' configuration section must be YAML files.
|
||||||
|
in databricks.yml:5:4
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
Found 1 error
|
||||||
|
|
||||||
|
Exit code: 1
|
|
@ -0,0 +1 @@
|
||||||
|
$CLI bundle validate
|
|
@ -0,0 +1 @@
|
||||||
|
print("Hello world")
|
|
@ -2,6 +2,7 @@ package loader
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"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.
|
// Maintain list of files in order of files being loaded.
|
||||||
// This is stored in the bundle configuration for observability.
|
// This is stored in the bundle configuration for observability.
|
||||||
var files []string
|
var files []string
|
||||||
|
var diags diag.Diagnostics
|
||||||
|
|
||||||
// For each glob, find all files to load.
|
// For each glob, find all files to load.
|
||||||
// Ordering of the list of globs is maintained in the output.
|
// Ordering of the list of globs is maintained in the output.
|
||||||
|
@ -60,7 +62,7 @@ func (m *processRootIncludes) Apply(ctx context.Context, b *bundle.Bundle) diag.
|
||||||
|
|
||||||
// Filter matches to ones we haven't seen yet.
|
// Filter matches to ones we haven't seen yet.
|
||||||
var includes []string
|
var includes []string
|
||||||
for _, match := range matches {
|
for i, match := range matches {
|
||||||
rel, err := filepath.Rel(b.BundleRootPath, match)
|
rel, err := filepath.Rel(b.BundleRootPath, match)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
|
@ -69,9 +71,22 @@ func (m *processRootIncludes) Apply(ctx context.Context, b *bundle.Bundle) diag.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
seen[rel] = true
|
seen[rel] = true
|
||||||
|
if filepath.Ext(rel) != ".yaml" && filepath.Ext(rel) != ".yml" {
|
||||||
|
diags = diags.Append(diag.Diagnostic{
|
||||||
|
Severity: diag.Error,
|
||||||
|
Summary: "Files in the 'include' configuration section must be YAML files.",
|
||||||
|
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
|
||||||
|
}
|
||||||
includes = append(includes, rel)
|
includes = append(includes, rel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(diags) > 0 {
|
||||||
|
return diags
|
||||||
|
}
|
||||||
|
|
||||||
// Add matches to list of mutators to return.
|
// Add matches to list of mutators to return.
|
||||||
slices.Sort(includes)
|
slices.Sort(includes)
|
||||||
files = append(files, includes...)
|
files = append(files, includes...)
|
||||||
|
|
Loading…
Reference in New Issue