mirror of https://github.com/databricks/cli.git
added more patterns to replace
This commit is contained in:
parent
970c7ea355
commit
356a1c75c1
|
@ -24,11 +24,15 @@ func (m *rewriteWorkspacePrefix) Name() string {
|
||||||
|
|
||||||
func (m *rewriteWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
func (m *rewriteWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
||||||
diags := diag.Diagnostics{}
|
diags := diag.Diagnostics{}
|
||||||
paths := []string{
|
paths := map[string]string{
|
||||||
"/Workspace/${workspace.root_path}",
|
"/Workspace/${workspace.root_path}": "${workspace.root_path}",
|
||||||
"/Workspace/${workspace.file_path}",
|
"/Workspace${workspace.root_path}": "${workspace.root_path}",
|
||||||
"/Workspace/${workspace.artifact_path}",
|
"/Workspace/${workspace.file_path}": "${workspace.file_path}",
|
||||||
"/Workspace/${workspace.state_path}",
|
"/Workspace${workspace.file_path}": "${workspace.file_path}",
|
||||||
|
"/Workspace/${workspace.artifact_path}": "${workspace.artifact_path}",
|
||||||
|
"/Workspace${workspace.artifact_path}": "${workspace.artifact_path}",
|
||||||
|
"/Workspace/${workspace.state_path}": "${workspace.state_path}",
|
||||||
|
"/Workspace${workspace.state_path}": "${workspace.state_path}",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := b.Config.Mutate(func(root dyn.Value) (dyn.Value, error) {
|
err := b.Config.Mutate(func(root dyn.Value) (dyn.Value, error) {
|
||||||
|
@ -40,17 +44,18 @@ func (m *rewriteWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) di
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, path := range paths {
|
for path, replacePath := range paths {
|
||||||
if strings.Contains(vv, path) {
|
if strings.Contains(vv, path) {
|
||||||
|
newPath := strings.Replace(vv, path, replacePath, 1)
|
||||||
diags = append(diags, diag.Diagnostic{
|
diags = append(diags, diag.Diagnostic{
|
||||||
Severity: diag.Warning,
|
Severity: diag.Warning,
|
||||||
Summary: fmt.Sprintf("substring %q found in %q. Please update this to %q. For more information, please refer to: https://docs.databricks.com/en/release-notes/dev-tools/bundles.html#workspace-paths", path, vv, strings.Replace(vv, "/Workspace/", "", 1)),
|
Summary: fmt.Sprintf("substring %q found in %q. Please update this to %q. For more information, please refer to: https://docs.databricks.com/en/release-notes/dev-tools/bundles.html#workspace-paths", path, vv, newPath),
|
||||||
Locations: v.Locations(),
|
Locations: v.Locations(),
|
||||||
Paths: []dyn.Path{p},
|
Paths: []dyn.Path{p},
|
||||||
})
|
})
|
||||||
|
|
||||||
// Remove the workspace prefix from the string.
|
// Remove the workspace prefix from the string.
|
||||||
return dyn.NewValue(strings.Replace(vv, "/Workspace/", "", 1), v.Locations()), nil
|
return dyn.NewValue(newPath, v.Locations()), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ func TestNoWorkspacePrefixUsed(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
NotebookTask: &jobs.NotebookTask{
|
NotebookTask: &jobs.NotebookTask{
|
||||||
NotebookPath: "/Workspace/${workspace.file_path}/notebook1",
|
NotebookPath: "/Workspace${workspace.file_path}/notebook1",
|
||||||
},
|
},
|
||||||
Libraries: []compute.Library{
|
Libraries: []compute.Library{
|
||||||
{
|
{
|
||||||
|
@ -66,7 +66,7 @@ func TestNoWorkspacePrefixUsed(t *testing.T) {
|
||||||
|
|
||||||
expectedErrors := map[string]bool{
|
expectedErrors := map[string]bool{
|
||||||
`substring "/Workspace/${workspace.root_path}" found in "/Workspace/${workspace.root_path}/file1.py". Please update this to "${workspace.root_path}/file1.py". For more information, please refer to: https://docs.databricks.com/en/release-notes/dev-tools/bundles.html#workspace-paths`: true,
|
`substring "/Workspace/${workspace.root_path}" found in "/Workspace/${workspace.root_path}/file1.py". Please update this to "${workspace.root_path}/file1.py". For more information, please refer to: https://docs.databricks.com/en/release-notes/dev-tools/bundles.html#workspace-paths`: true,
|
||||||
`substring "/Workspace/${workspace.file_path}" found in "/Workspace/${workspace.file_path}/notebook1". Please update this to "${workspace.file_path}/notebook1". For more information, please refer to: https://docs.databricks.com/en/release-notes/dev-tools/bundles.html#workspace-paths`: true,
|
`substring "/Workspace${workspace.file_path}" found in "/Workspace${workspace.file_path}/notebook1". Please update this to "${workspace.file_path}/notebook1". For more information, please refer to: https://docs.databricks.com/en/release-notes/dev-tools/bundles.html#workspace-paths`: true,
|
||||||
`substring "/Workspace/${workspace.artifact_path}" found in "/Workspace/${workspace.artifact_path}/jar1.jar". Please update this to "${workspace.artifact_path}/jar1.jar". For more information, please refer to: https://docs.databricks.com/en/release-notes/dev-tools/bundles.html#workspace-paths`: true,
|
`substring "/Workspace/${workspace.artifact_path}" found in "/Workspace/${workspace.artifact_path}/jar1.jar". Please update this to "${workspace.artifact_path}/jar1.jar". For more information, please refer to: https://docs.databricks.com/en/release-notes/dev-tools/bundles.html#workspace-paths`: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue