-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load bundle configuration from mutator #1318
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2adc677
Move path field to bundle type
pietern f48cf03
Path -> RootPath
pietern bd14db0
Fix
pietern 99f027e
Remove support for DATABRICKS_BUNDLE_INCLUDES
pietern 503e3e4
Load bundle entry point from mutator
pietern 64a5bed
Load configuration entry point from mutator instead of bundle.Load
pietern b79ae8f
Fold target selection into seq
pietern d01334b
Merge remote-tracking branch 'origin/main' into bundle-load-from-mutator
pietern File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package loader | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/cli/bundle/config" | ||
"github.com/databricks/cli/libs/diag" | ||
) | ||
|
||
type entryPoint struct{} | ||
|
||
// EntryPoint loads the entry point configuration. | ||
func EntryPoint() bundle.Mutator { | ||
return &entryPoint{} | ||
} | ||
|
||
func (m *entryPoint) Name() string { | ||
return "EntryPoint" | ||
} | ||
|
||
func (m *entryPoint) Apply(_ context.Context, b *bundle.Bundle) diag.Diagnostics { | ||
path, err := config.FileNames.FindInPath(b.RootPath) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
this, err := config.Load(path) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
// TODO: Return actual warnings. | ||
err = b.Config.Merge(this) | ||
return diag.FromErr(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package loader_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/cli/bundle/config/loader" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestEntryPointNoRootPath(t *testing.T) { | ||
b := &bundle.Bundle{} | ||
diags := bundle.Apply(context.Background(), b, loader.EntryPoint()) | ||
require.Error(t, diags.Error()) | ||
} | ||
|
||
func TestEntryPoint(t *testing.T) { | ||
b := &bundle.Bundle{ | ||
RootPath: "testdata", | ||
} | ||
diags := bundle.Apply(context.Background(), b, loader.EntryPoint()) | ||
require.NoError(t, diags.Error()) | ||
assert.Equal(t, "loader_test", b.Config.Bundle.Name) | ||
} |
2 changes: 1 addition & 1 deletion
2
bundle/config/mutator/process_include.go → bundle/config/loader/process_include.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package mutator | ||
package loader | ||
|
||
import ( | ||
"context" | ||
|
21 changes: 9 additions & 12 deletions
21
...le/config/mutator/process_include_test.go → bundle/config/loader/process_include_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,35 @@ | ||
package mutator_test | ||
package loader_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/cli/bundle/config" | ||
"github.com/databricks/cli/bundle/config/mutator" | ||
"github.com/databricks/cli/bundle/config/loader" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestProcessInclude(t *testing.T) { | ||
b := &bundle.Bundle{ | ||
RootPath: t.TempDir(), | ||
RootPath: "testdata", | ||
Config: config.Root{ | ||
Workspace: config.Workspace{ | ||
Host: "foo", | ||
}, | ||
}, | ||
} | ||
|
||
relPath := "./file.yml" | ||
fullPath := filepath.Join(b.RootPath, relPath) | ||
f, err := os.Create(fullPath) | ||
require.NoError(t, err) | ||
fmt.Fprint(f, "workspace:\n host: bar\n") | ||
f.Close() | ||
m := loader.ProcessInclude(filepath.Join(b.RootPath, "host.yml"), "host.yml") | ||
assert.Equal(t, "ProcessInclude(host.yml)", m.Name()) | ||
|
||
// Assert the host value prior to applying the mutator | ||
assert.Equal(t, "foo", b.Config.Workspace.Host) | ||
diags := bundle.Apply(context.Background(), b, mutator.ProcessInclude(fullPath, relPath)) | ||
|
||
// Apply the mutator and assert that the host value has been updated | ||
diags := bundle.Apply(context.Background(), b, m) | ||
require.NoError(t, diags.Error()) | ||
assert.Equal(t, "bar", b.Config.Workspace.Host) | ||
} |
2 changes: 1 addition & 1 deletion
2
...e/config/mutator/process_root_includes.go → ...le/config/loader/process_root_includes.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package mutator | ||
package loader | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bundle: | ||
name: loader_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
workspace: | ||
host: bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package phases | ||
|
||
import ( | ||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/cli/bundle/config/mutator" | ||
) | ||
|
||
// The load phase loads configuration from disk and performs | ||
// lightweight preprocessing (anything that can be done without network I/O). | ||
func Load() bundle.Mutator { | ||
return newPhase( | ||
"load", | ||
mutator.DefaultMutators(), | ||
) | ||
} | ||
|
||
func LoadDefaultTarget() bundle.Mutator { | ||
return newPhase( | ||
"load", | ||
append(mutator.DefaultMutators(), mutator.SelectDefaultTarget()), | ||
) | ||
} | ||
|
||
func LoadNamedTarget(target string) bundle.Mutator { | ||
return newPhase( | ||
"load", | ||
append(mutator.DefaultMutators(), mutator.SelectTarget(target)), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we use it in
loadBundle
as well? https://github.com/databricks/cli/blob/main/cmd/root/bundle.go#L77There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch. I'm working on a change on top of this one that modifies
MustConfigureBundle
andTryConfigureBundle
to return diagnostics as well and this is addressed there.