mirror of https://github.com/databricks/cli.git
Add versioning for bundle templates (#972)
## Changes This PR adds versioning for bundle templates. Right now there's only logic for the maximum version of templates supported. At some point in the future if we make a breaking template change we can also include a minimum version of template supported by the CLI. ## Tests Unit tests.
This commit is contained in:
parent
677926b78b
commit
1f1ed6db53
|
@ -26,4 +26,8 @@ type Extension struct {
|
|||
// If the CLI version is less than this value, then validation for this
|
||||
// schema will fail.
|
||||
MinDatabricksCliVersion string `json:"min_databricks_cli_version,omitempty"`
|
||||
|
||||
// Version of the schema. This is used to determine if the schema is
|
||||
// compatible with the current CLI version.
|
||||
Version *int `json:"version,omitempty"`
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@ import (
|
|||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
// The latest template schema version supported by the CLI
|
||||
const latestSchemaVersion = 1
|
||||
|
||||
type config struct {
|
||||
ctx context.Context
|
||||
values map[string]any
|
||||
|
@ -49,6 +52,9 @@ func validateSchema(schema *jsonschema.Schema) error {
|
|||
return fmt.Errorf("property type %s is not supported by bundle templates", v.Type)
|
||||
}
|
||||
}
|
||||
if schema.Version != nil && *schema.Version > latestSchemaVersion {
|
||||
return fmt.Errorf("template schema version %d is not supported by this version of the CLI. Please upgrade your CLI to the latest version", *schema.Version)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package template
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/databricks/cli/cmd/root"
|
||||
|
@ -150,6 +151,40 @@ func TestTemplateValidateSchema(t *testing.T) {
|
|||
assert.EqualError(t, err, "property type array is not supported by bundle templates")
|
||||
}
|
||||
|
||||
func TestTemplateValidateSchemaVersion(t *testing.T) {
|
||||
version := latestSchemaVersion
|
||||
schema := jsonschema.Schema{
|
||||
Extension: jsonschema.Extension{
|
||||
Version: &version,
|
||||
},
|
||||
}
|
||||
assert.NoError(t, validateSchema(&schema))
|
||||
|
||||
version = latestSchemaVersion + 1
|
||||
schema = jsonschema.Schema{
|
||||
Extension: jsonschema.Extension{
|
||||
Version: &version,
|
||||
},
|
||||
}
|
||||
assert.EqualError(t, validateSchema(&schema), fmt.Sprintf("template schema version %d is not supported by this version of the CLI. Please upgrade your CLI to the latest version", version))
|
||||
|
||||
version = 5000
|
||||
schema = jsonschema.Schema{
|
||||
Extension: jsonschema.Extension{
|
||||
Version: &version,
|
||||
},
|
||||
}
|
||||
assert.EqualError(t, validateSchema(&schema), "template schema version 5000 is not supported by this version of the CLI. Please upgrade your CLI to the latest version")
|
||||
|
||||
version = 0
|
||||
schema = jsonschema.Schema{
|
||||
Extension: jsonschema.Extension{
|
||||
Version: &version,
|
||||
},
|
||||
}
|
||||
assert.NoError(t, validateSchema(&schema))
|
||||
}
|
||||
|
||||
func TestTemplateEnumValidation(t *testing.T) {
|
||||
schema := jsonschema.Schema{
|
||||
Properties: map[string]*jsonschema.Schema{
|
||||
|
|
Loading…
Reference in New Issue