Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bundle/artifacts/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (m *all) Name() string {
return fmt.Sprintf("artifacts.%sAll", m.name)
}

func (m *all) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
func (m *all) Apply(ctx context.Context, b *bundle.Bundle) error {
var out []bundle.Mutator

// Iterate with stable ordering.
Expand All @@ -30,12 +30,12 @@ func (m *all) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, er
for _, name := range keys {
m, err := m.fn(name)
if err != nil {
return nil, err
return err
}
if m != nil {
out = append(out, m)
}
}

return out, nil
return bundle.Apply(ctx, b, bundle.Seq(out...))
}
8 changes: 4 additions & 4 deletions bundle/artifacts/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ func (m *build) Name() string {
return fmt.Sprintf("artifacts.Build(%s)", m.name)
}

func (m *build) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
func (m *build) Apply(ctx context.Context, b *bundle.Bundle) error {
artifact, ok := b.Config.Artifacts[m.name]
if !ok {
return nil, fmt.Errorf("artifact doesn't exist: %s", m.name)
return fmt.Errorf("artifact doesn't exist: %s", m.name)
}

if artifact.Notebook != nil {
return []bundle.Mutator{notebook.Build(m.name)}, nil
return bundle.Apply(ctx, b, notebook.Build(m.name))
}

return nil, nil
return nil
}
16 changes: 8 additions & 8 deletions bundle/artifacts/notebook/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ func (m *build) Name() string {
return fmt.Sprintf("notebook.Build(%s)", m.name)
}

func (m *build) Apply(_ context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
func (m *build) Apply(_ context.Context, b *bundle.Bundle) error {
a, ok := b.Config.Artifacts[m.name]
if !ok {
return nil, fmt.Errorf("artifact doesn't exist: %s", m.name)
return fmt.Errorf("artifact doesn't exist: %s", m.name)
}

artifact := a.Notebook
Expand All @@ -44,35 +44,35 @@ func (m *build) Apply(_ context.Context, b *bundle.Bundle) ([]bundle.Mutator, er
case ".sql":
artifact.Language = workspace.LanguageSql
default:
return nil, fmt.Errorf("invalid notebook extension: %s", ext)
return fmt.Errorf("invalid notebook extension: %s", ext)
}

// Open underlying file.
f, err := os.Open(filepath.Join(b.Config.Path, artifact.Path))
if err != nil {
return nil, fmt.Errorf("unable to open artifact file %s: %w", artifact.Path, errors.Unwrap(err))
return fmt.Errorf("unable to open artifact file %s: %w", artifact.Path, errors.Unwrap(err))
}
defer f.Close()

// Check that the file contains the notebook marker on its first line.
ok, err = hasMarker(artifact.Language, f)
if err != nil {
return nil, fmt.Errorf("unable to read artifact file %s: %s", artifact.Path, errors.Unwrap(err))
return fmt.Errorf("unable to read artifact file %s: %s", artifact.Path, errors.Unwrap(err))
}
if !ok {
return nil, fmt.Errorf("notebook marker not found in %s", artifact.Path)
return fmt.Errorf("notebook marker not found in %s", artifact.Path)
}

// Check that an artifact path is defined.
remotePath := b.Config.Workspace.ArtifactsPath
if remotePath == "" {
return nil, fmt.Errorf("remote artifact path not configured")
return fmt.Errorf("remote artifact path not configured")
}

// Store absolute paths.
artifact.LocalPath = filepath.Join(b.Config.Path, artifact.Path)
artifact.RemotePath = path.Join(remotePath, stripExtension(artifact.Path))
return nil, nil
return nil
}

func stripExtension(path string) string {
Expand Down
12 changes: 6 additions & 6 deletions bundle/artifacts/notebook/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ func (m *upload) Name() string {
return fmt.Sprintf("notebook.Upload(%s)", m.name)
}

func (m *upload) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
func (m *upload) Apply(ctx context.Context, b *bundle.Bundle) error {
a, ok := b.Config.Artifacts[m.name]
if !ok {
return nil, fmt.Errorf("artifact doesn't exist: %s", m.name)
return fmt.Errorf("artifact doesn't exist: %s", m.name)
}

artifact := a.Notebook
raw, err := os.ReadFile(artifact.LocalPath)
if err != nil {
return nil, fmt.Errorf("unable to read %s: %w", m.name, errors.Unwrap(err))
return fmt.Errorf("unable to read %s: %w", m.name, errors.Unwrap(err))
}

// Make sure target directory exists.
err = b.WorkspaceClient().Workspace.MkdirsByPath(ctx, path.Dir(artifact.RemotePath))
if err != nil {
return nil, fmt.Errorf("unable to create directory for %s: %w", m.name, err)
return fmt.Errorf("unable to create directory for %s: %w", m.name, err)
}

// Import to workspace.
Expand All @@ -53,8 +53,8 @@ func (m *upload) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator,
Content: base64.StdEncoding.EncodeToString(raw),
})
if err != nil {
return nil, fmt.Errorf("unable to import %s: %w", m.name, err)
return fmt.Errorf("unable to import %s: %w", m.name, err)
}

return nil, nil
return nil
}
8 changes: 4 additions & 4 deletions bundle/artifacts/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ func (m *upload) Name() string {
return fmt.Sprintf("artifacts.Upload(%s)", m.name)
}

func (m *upload) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
func (m *upload) Apply(ctx context.Context, b *bundle.Bundle) error {
artifact, ok := b.Config.Artifacts[m.name]
if !ok {
return nil, fmt.Errorf("artifact doesn't exist: %s", m.name)
return fmt.Errorf("artifact doesn't exist: %s", m.name)
}

if artifact.Notebook != nil {
return []bundle.Mutator{notebook.Upload(m.name)}, nil
return bundle.Apply(ctx, b, notebook.Upload(m.name))
}

return nil, nil
return nil
}
4 changes: 2 additions & 2 deletions bundle/config/interpolation/interpolation.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,6 @@ func (m *interpolate) Name() string {
return "Interpolate"
}

func (m *interpolate) Apply(_ context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
return nil, m.expand(&b.Config)
func (m *interpolate) Apply(_ context.Context, b *bundle.Bundle) error {
return m.expand(&b.Config)
}
6 changes: 3 additions & 3 deletions bundle/config/mutator/default_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ func (m *defineDefaultEnvironment) Name() string {
return fmt.Sprintf("DefineDefaultEnvironment(%s)", m.name)
}

func (m *defineDefaultEnvironment) Apply(_ context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
func (m *defineDefaultEnvironment) Apply(_ context.Context, b *bundle.Bundle) error {
// Nothing to do if the configuration has at least 1 environment.
if len(b.Config.Environments) > 0 {
return nil, nil
return nil
}

// Define default environment.
b.Config.Environments = make(map[string]*config.Environment)
b.Config.Environments[m.name] = &config.Environment{}
return nil, nil
return nil
}
4 changes: 2 additions & 2 deletions bundle/config/mutator/default_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func TestDefaultEnvironment(t *testing.T) {
bundle := &bundle.Bundle{}
_, err := mutator.DefineDefaultEnvironment().Apply(context.Background(), bundle)
err := mutator.DefineDefaultEnvironment().Apply(context.Background(), bundle)
require.NoError(t, err)
env, ok := bundle.Config.Environments["default"]
assert.True(t, ok)
Expand All @@ -28,7 +28,7 @@ func TestDefaultEnvironmentAlreadySpecified(t *testing.T) {
},
},
}
_, err := mutator.DefineDefaultEnvironment().Apply(context.Background(), bundle)
err := mutator.DefineDefaultEnvironment().Apply(context.Background(), bundle)
require.NoError(t, err)
_, ok := bundle.Config.Environments["default"]
assert.False(t, ok)
Expand Down
4 changes: 2 additions & 2 deletions bundle/config/mutator/default_include.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func (m *defineDefaultInclude) Name() string {
return "DefineDefaultInclude"
}

func (m *defineDefaultInclude) Apply(_ context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
func (m *defineDefaultInclude) Apply(_ context.Context, b *bundle.Bundle) error {
if len(b.Config.Include) == 0 {
b.Config.Include = slices.Clone(m.include)
}
return nil, nil
return nil
}
2 changes: 1 addition & 1 deletion bundle/config/mutator/default_include_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestDefaultInclude(t *testing.T) {
bundle := &bundle.Bundle{}
_, err := mutator.DefineDefaultInclude().Apply(context.Background(), bundle)
err := mutator.DefineDefaultInclude().Apply(context.Background(), bundle)
require.NoError(t, err)
assert.Equal(t, []string{"*.yml", "*/*.yml"}, bundle.Config.Include)
}
6 changes: 3 additions & 3 deletions bundle/config/mutator/default_workspace_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ func (m *defineDefaultWorkspacePaths) Name() string {
return "DefaultWorkspacePaths"
}

func (m *defineDefaultWorkspacePaths) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
func (m *defineDefaultWorkspacePaths) Apply(ctx context.Context, b *bundle.Bundle) error {
root := b.Config.Workspace.RootPath
if root == "" {
return nil, fmt.Errorf("unable to define default workspace paths: workspace root not defined")
return fmt.Errorf("unable to define default workspace paths: workspace root not defined")
}

if b.Config.Workspace.FilesPath == "" {
Expand All @@ -37,5 +37,5 @@ func (m *defineDefaultWorkspacePaths) Apply(ctx context.Context, b *bundle.Bundl
b.Config.Workspace.StatePath = path.Join(root, "state")
}

return nil, nil
return nil
}
4 changes: 2 additions & 2 deletions bundle/config/mutator/default_workspace_paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestDefineDefaultWorkspacePaths(t *testing.T) {
},
},
}
_, err := mutator.DefineDefaultWorkspacePaths().Apply(context.Background(), bundle)
err := mutator.DefineDefaultWorkspacePaths().Apply(context.Background(), bundle)
require.NoError(t, err)
assert.Equal(t, "/files", bundle.Config.Workspace.FilesPath)
assert.Equal(t, "/artifacts", bundle.Config.Workspace.ArtifactsPath)
Expand All @@ -37,7 +37,7 @@ func TestDefineDefaultWorkspacePathsAlreadySet(t *testing.T) {
},
},
}
_, err := mutator.DefineDefaultWorkspacePaths().Apply(context.Background(), bundle)
err := mutator.DefineDefaultWorkspacePaths().Apply(context.Background(), bundle)
require.NoError(t, err)
assert.Equal(t, "/foo/bar", bundle.Config.Workspace.FilesPath)
assert.Equal(t, "/foo/bar", bundle.Config.Workspace.ArtifactsPath)
Expand Down
10 changes: 5 additions & 5 deletions bundle/config/mutator/default_workspace_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ func (m *defineDefaultWorkspaceRoot) Name() string {
return "DefineDefaultWorkspaceRoot"
}

func (m *defineDefaultWorkspaceRoot) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
func (m *defineDefaultWorkspaceRoot) Apply(ctx context.Context, b *bundle.Bundle) error {
if b.Config.Workspace.RootPath != "" {
return nil, nil
return nil
}

if b.Config.Bundle.Name == "" {
return nil, fmt.Errorf("unable to define default workspace root: bundle name not defined")
return fmt.Errorf("unable to define default workspace root: bundle name not defined")
}

if b.Config.Bundle.Environment == "" {
return nil, fmt.Errorf("unable to define default workspace root: bundle environment not selected")
return fmt.Errorf("unable to define default workspace root: bundle environment not selected")
}

b.Config.Workspace.RootPath = fmt.Sprintf(
"~/.bundle/%s/%s",
b.Config.Bundle.Name,
b.Config.Bundle.Environment,
)
return nil, nil
return nil
}
2 changes: 1 addition & 1 deletion bundle/config/mutator/default_workspace_root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestDefaultWorkspaceRoot(t *testing.T) {
},
},
}
_, err := mutator.DefineDefaultWorkspaceRoot().Apply(context.Background(), bundle)
err := mutator.DefineDefaultWorkspaceRoot().Apply(context.Background(), bundle)
require.NoError(t, err)
assert.Equal(t, "~/.bundle/name/environment", bundle.Config.Workspace.RootPath)
}
8 changes: 4 additions & 4 deletions bundle/config/mutator/expand_workspace_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ func (m *expandWorkspaceRoot) Name() string {
return "ExpandWorkspaceRoot"
}

func (m *expandWorkspaceRoot) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
func (m *expandWorkspaceRoot) Apply(ctx context.Context, b *bundle.Bundle) error {
root := b.Config.Workspace.RootPath
if root == "" {
return nil, fmt.Errorf("unable to expand workspace root: workspace root not defined")
return fmt.Errorf("unable to expand workspace root: workspace root not defined")
}

currentUser := b.Config.Workspace.CurrentUser
if currentUser == nil || currentUser.UserName == "" {
return nil, fmt.Errorf("unable to expand workspace root: current user not set")
return fmt.Errorf("unable to expand workspace root: current user not set")
}

if strings.HasPrefix(root, "~/") {
home := fmt.Sprintf("/Users/%s", currentUser.UserName)
b.Config.Workspace.RootPath = path.Join(home, root[2:])
}

return nil, nil
return nil
}
8 changes: 4 additions & 4 deletions bundle/config/mutator/expand_workspace_root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestExpandWorkspaceRoot(t *testing.T) {
},
},
}
_, err := mutator.ExpandWorkspaceRoot().Apply(context.Background(), bundle)
err := mutator.ExpandWorkspaceRoot().Apply(context.Background(), bundle)
require.NoError(t, err)
assert.Equal(t, "/Users/jane@doe.com/foo", bundle.Config.Workspace.RootPath)
}
Expand All @@ -39,7 +39,7 @@ func TestExpandWorkspaceRootDoesNothing(t *testing.T) {
},
},
}
_, err := mutator.ExpandWorkspaceRoot().Apply(context.Background(), bundle)
err := mutator.ExpandWorkspaceRoot().Apply(context.Background(), bundle)
require.NoError(t, err)
assert.Equal(t, "/Users/charly@doe.com/foo", bundle.Config.Workspace.RootPath)
}
Expand All @@ -54,7 +54,7 @@ func TestExpandWorkspaceRootWithoutRoot(t *testing.T) {
},
},
}
_, err := mutator.ExpandWorkspaceRoot().Apply(context.Background(), bundle)
err := mutator.ExpandWorkspaceRoot().Apply(context.Background(), bundle)
require.Error(t, err)
}

Expand All @@ -66,6 +66,6 @@ func TestExpandWorkspaceRootWithoutCurrentUser(t *testing.T) {
},
},
}
_, err := mutator.ExpandWorkspaceRoot().Apply(context.Background(), bundle)
err := mutator.ExpandWorkspaceRoot().Apply(context.Background(), bundle)
require.Error(t, err)
}
6 changes: 3 additions & 3 deletions bundle/config/mutator/load_git_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ func (m *loadGitDetails) Name() string {
return "LoadGitDetails"
}

func (m *loadGitDetails) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
func (m *loadGitDetails) Apply(ctx context.Context, b *bundle.Bundle) error {
// Load relevant git repository
repo, err := git.NewRepository(b.Config.Path)
if err != nil {
return nil, err
return err
}
// load branch name if undefined
if b.Config.Bundle.Git.Branch == "" {
Expand All @@ -47,5 +47,5 @@ func (m *loadGitDetails) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.
remoteUrl := repo.OriginUrl()
b.Config.Bundle.Git.OriginURL = remoteUrl
}
return nil, nil
return nil
}
6 changes: 3 additions & 3 deletions bundle/config/mutator/populate_current_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ func (m *populateCurrentUser) Name() string {
return "PopulateCurrentUser"
}

func (m *populateCurrentUser) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
func (m *populateCurrentUser) Apply(ctx context.Context, b *bundle.Bundle) error {
w := b.WorkspaceClient()
me, err := w.CurrentUser.Me(ctx)
if err != nil {
return nil, err
return err
}

b.Config.Workspace.CurrentUser = me
return nil, nil
return nil
}
Loading