Skip to content

Commit 240d442

Browse files
committed
make expandGlobs a mutator
1 parent d68a1c7 commit 240d442

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

bundle/artifacts/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (m *build) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
7777
// We need to expand glob reference after build mutator is applied because
7878
// if we do it before, any files that are generated by build command will
7979
// not be included into artifact.Files and thus will not be uploaded.
80-
diags = diags.Extend(expandGlobs(ctx, b, artifactName))
80+
diags = diags.Extend(bundle.Apply(ctx, b, expandGlobs{name: artifactName}))
8181
if diags.HasError() {
8282
break
8383
}

bundle/artifacts/expand_globs.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/databricks/cli/bundle"
99
"github.com/databricks/cli/libs/diag"
1010
"github.com/databricks/cli/libs/dyn"
11-
"github.com/databricks/cli/libs/log"
1211
)
1312

1413
func createGlobError(v dyn.Value, p dyn.Path, message string) diag.Diagnostic {
@@ -30,25 +29,20 @@ func createGlobError(v dyn.Value, p dyn.Path, message string) diag.Diagnostic {
3029
}
3130
}
3231

33-
func expandGlobs(ctx context.Context, b *bundle.Bundle, name string) diag.Diagnostics {
34-
err := b.Config.MarkMutatorEntry(ctx)
35-
if err != nil {
36-
log.Errorf(ctx, "entry error: %s", err)
37-
return diag.Errorf("entry error: %s", err)
38-
}
32+
type expandGlobs struct {
33+
name string
34+
}
3935

40-
defer func() {
41-
err := b.Config.MarkMutatorExit(ctx)
42-
if err != nil {
43-
log.Errorf(ctx, "exit error: %s", err)
44-
}
45-
}()
36+
func (e expandGlobs) Name() string {
37+
return "expandGlobs"
38+
}
4639

40+
func (e expandGlobs) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
4741
// Base path for this mutator.
4842
// This path is set with the list of expanded globs when done.
4943
base := dyn.NewPath(
5044
dyn.Key("artifacts"),
51-
dyn.Key(name),
45+
dyn.Key(e.name),
5246
dyn.Key("files"),
5347
)
5448

@@ -59,7 +53,7 @@ func expandGlobs(ctx context.Context, b *bundle.Bundle, name string) diag.Diagno
5953
)
6054

6155
var diags diag.Diagnostics
62-
err = b.Config.Mutate(func(v dyn.Value) (dyn.Value, error) {
56+
err := b.Config.Mutate(func(v dyn.Value) (dyn.Value, error) {
6357
var output []dyn.Value
6458
_, err := dyn.MapByPattern(v, pattern, func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
6559
if v.Kind() != dyn.KindString {

bundle/artifacts/prepare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (m *prepare) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics
7474
}
7575

7676
if len(artifact.Files) > 0 && artifact.BuildCommand == "" {
77-
diags = diags.Extend(expandGlobs(ctx, b, artifactName))
77+
diags = diags.Extend(bundle.Apply(ctx, b, expandGlobs{name: artifactName}))
7878
}
7979

8080
if diags.HasError() {

0 commit comments

Comments
 (0)