Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnester committed Aug 29, 2024
1 parent 5a85cd3 commit c182468
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions bundle/config/mutator/prepend_workspace_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions bundle/config/validate/no_workspace_prefix_used.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
})
Expand Down
2 changes: 2 additions & 0 deletions bundle/phases/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit c182468

Please sign in to comment.