Skip to content

Commit

Permalink
added more patterns to replace
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnester committed Oct 2, 2024
1 parent 970c7ea commit 356a1c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 13 additions & 8 deletions bundle/config/mutator/rewrite_workspace_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ func (m *rewriteWorkspacePrefix) Name() string {

func (m *rewriteWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
diags := diag.Diagnostics{}
paths := []string{
"/Workspace/${workspace.root_path}",
"/Workspace/${workspace.file_path}",
"/Workspace/${workspace.artifact_path}",
"/Workspace/${workspace.state_path}",
paths := map[string]string{
"/Workspace/${workspace.root_path}": "${workspace.root_path}",
"/Workspace${workspace.root_path}": "${workspace.root_path}",
"/Workspace/${workspace.file_path}": "${workspace.file_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) {
Expand All @@ -40,17 +44,18 @@ func (m *rewriteWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) di
return v, nil
}

for _, path := range paths {
for path, replacePath := range paths {
if strings.Contains(vv, path) {
newPath := strings.Replace(vv, path, replacePath, 1)
diags = append(diags, diag.Diagnostic{
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(),
Paths: []dyn.Path{p},
})

// 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
}
}

Expand Down
4 changes: 2 additions & 2 deletions bundle/config/mutator/rewrite_workspace_prefix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestNoWorkspacePrefixUsed(t *testing.T) {
},
{
NotebookTask: &jobs.NotebookTask{
NotebookPath: "/Workspace/${workspace.file_path}/notebook1",
NotebookPath: "/Workspace${workspace.file_path}/notebook1",
},
Libraries: []compute.Library{
{
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestNoWorkspacePrefixUsed(t *testing.T) {

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.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,
}

Expand Down

0 comments on commit 356a1c7

Please sign in to comment.