Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion acceptance/bundle/help/bundle-validate/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Validate bundle configuration for errors, warnings and recommendations.
Run validate before deploy to catch configuration issues early:
databricks bundle validate # Validate default target
databricks bundle validate --target prod # Validate specific target
databricks bundle validate --strict # Fail on warnings

Validation checks the configuration syntax and schema, permissions etc.

Expand All @@ -14,7 +15,8 @@ Usage:
databricks bundle validate [flags]

Flags:
-h, --help help for validate
-h, --help help for validate
--strict Treat warnings as errors

Global Flags:
--debug enable debug logging
Expand Down
17 changes: 17 additions & 0 deletions acceptance/bundle/validate/strict/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
bundle:
name: test-bundle

variables:
my_variable:
type: INVALID_TYPE
default: "value"

targets:
foo:
default: true

bar:
artifacts:
my_artifact:
type: INVALID_TYPE
build: "echo 'hello'"
5 changes: 5 additions & 0 deletions acceptance/bundle/validate/strict/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions acceptance/bundle/validate/strict/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

>>> [CLI] bundle validate
Warning: invalid value "INVALID_TYPE" for enum field. Valid values are [complex]
at variables.my_variable.type
in databricks.yml:6:11

Name: test-bundle
Target: foo
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/foo

Found 1 warning

>>> [CLI] bundle validate --strict
Warning: invalid value "INVALID_TYPE" for enum field. Valid values are [complex]
at variables.my_variable.type
in databricks.yml:6:11

Name: test-bundle
Target: foo
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/foo

Found 1 warning
Error: 1 warning was found. Warnings are not allowed in strict mode

Exit code: 1

>>> [CLI] bundle validate --strict -t bar
Warning: invalid value "INVALID_TYPE" for enum field. Valid values are [complex]
at variables.my_variable.type
in databricks.yml:6:11

Warning: invalid value "INVALID_TYPE" for enum field. Valid values are [whl jar]
at artifacts.my_artifact.type
in databricks.yml:16:15

Name: test-bundle
Target: bar
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/bar

Found 2 warnings
Error: 2 warnings were found. Warnings are not allowed in strict mode

Exit code: 1
7 changes: 7 additions & 0 deletions acceptance/bundle/validate/strict/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Without --strict, warnings don't cause exit code 1
trace $CLI bundle validate

# With --strict, warnings cause exit code 1
errcode trace $CLI bundle validate --strict

errcode trace $CLI bundle validate --strict -t bar
16 changes: 16 additions & 0 deletions cmd/bundle/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"encoding/json"
"fmt"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/render"
Expand Down Expand Up @@ -35,6 +36,7 @@
Run validate before deploy to catch configuration issues early:
databricks bundle validate # Validate default target
databricks bundle validate --target prod # Validate specific target
databricks bundle validate --strict # Fail on warnings

Validation checks the configuration syntax and schema, permissions etc.

Expand All @@ -43,8 +45,10 @@
}

var includeLocations bool
var strict bool
cmd.Flags().BoolVar(&includeLocations, "include-locations", false, "Include location information in the output")
cmd.Flags().MarkHidden("include-locations")
cmd.Flags().BoolVar(&strict, "strict", false, "Treat warnings as errors")

cmd.RunE = func(cmd *cobra.Command, args []string) error {
b, err := utils.ProcessBundle(cmd, utils.ProcessOptions{
Expand Down Expand Up @@ -74,6 +78,18 @@
}
}

// In strict mode, treat warnings as errors.
numWarnings := logdiag.NumWarnings(ctx)
if err == nil && strict && numWarnings > 0 {
prefix := ""
if numWarnings == 1 {
prefix = fmt.Sprintf("1 warning was found")

Check failure on line 86 in cmd/bundle/validate.go

View workflow job for this annotation

GitHub Actions / lint

string-format: fmt.Sprintf can be replaced with just using the string (perfsprint)
} else {
prefix = fmt.Sprintf("%d warnings were found", numWarnings)
}
return fmt.Errorf("%s. Warnings are not allowed in strict mode", prefix)
}

return err
}

Expand Down
8 changes: 8 additions & 0 deletions libs/logdiag/logdiag.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ func HasError(ctx context.Context) bool {
return val.Errors > 0
}

func NumWarnings(ctx context.Context) int {
val := read(ctx)
val.mu.Lock()
defer val.mu.Unlock()

return val.Warnings
}

func SetSeverity(ctx context.Context, target diag.Severity) {
val := read(ctx)
val.mu.Lock()
Expand Down
Loading