From c18246855cd2011cea14eaa1073a88b654df4849 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Thu, 29 Aug 2024 17:09:46 +0200 Subject: [PATCH] fixes --- bundle/config/mutator/prepend_workspace_prefix.go | 4 ++-- bundle/config/validate/no_workspace_prefix_used.go | 10 ++++++---- bundle/phases/initialize.go | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bundle/config/mutator/prepend_workspace_prefix.go b/bundle/config/mutator/prepend_workspace_prefix.go index 8e01dfe71f..dd467344b8 100644 --- a/bundle/config/mutator/prepend_workspace_prefix.go +++ b/bundle/config/mutator/prepend_workspace_prefix.go @@ -22,8 +22,8 @@ func (m *prependWorkspacePrefix) Name() string { } var skipPrefixes = []string{ - "/Workspace", - "/Volumes", + "/Workspace/", + "/Volumes/", } func (m *prependWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { diff --git a/bundle/config/validate/no_workspace_prefix_used.go b/bundle/config/validate/no_workspace_prefix_used.go index dd774dd1d1..0f93c7b0d7 100644 --- a/bundle/config/validate/no_workspace_prefix_used.go +++ b/bundle/config/validate/no_workspace_prefix_used.go @@ -23,24 +23,26 @@ func (m *noWorkspacePrefixUsed) Name() string { func (m *noWorkspacePrefixUsed) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { diags := diag.Diagnostics{} - prefixes := []string{ + paths := []string{ "/Workspace/${workspace.root_path}", "/Workspace/${workspace.file_path}", "/Workspace/${workspace.artifact_path}", "/Workspace/${workspace.state_path}", } + // Walk through the bundle configuration, check all the string leaves and + // see if any of the prefixes are used in the remote path. _, err := dyn.Walk(b.Config.Value(), func(p dyn.Path, v dyn.Value) (dyn.Value, error) { vv, ok := v.AsString() if !ok { return v, nil } - for _, prefix := range prefixes { - if strings.HasPrefix(vv, prefix) { + for _, path := range paths { + if strings.Contains(vv, path) { diags = append(diags, diag.Diagnostic{ Severity: diag.Error, - Summary: fmt.Sprintf("%s used in the remote path %s. Please change to use %s instead", prefix, vv, strings.ReplaceAll(vv, "/Workspace/", "")), + Summary: fmt.Sprintf("%s used in the remote path %s. Please change to use %s instead", path, vv, strings.ReplaceAll(vv, "/Workspace/", "")), Locations: v.Locations(), Paths: []dyn.Path{p}, }) diff --git a/bundle/phases/initialize.go b/bundle/phases/initialize.go index 2d3f311e4d..4bc2d1a046 100644 --- a/bundle/phases/initialize.go +++ b/bundle/phases/initialize.go @@ -45,6 +45,8 @@ func Initialize() bundle.Mutator { mutator.DefineDefaultWorkspacePaths(), mutator.PrependWorkspacePrefix(), + // This mutator needs to be run before variable interpolation because it + // searches for strings with variable references in them. validate.NoWorkspacePrefixUsed(), mutator.SetVariables(),