mirror of https://github.com/databricks/cli.git
Move loadGitDetails mutator to Initialize phase
This will require API call and we want to keep Load phase fast.
This commit is contained in:
parent
7b9726dd64
commit
8922dba1ca
|
@ -26,7 +26,6 @@ func DefaultMutators() []bundle.Mutator {
|
|||
ComputeIdToClusterId(),
|
||||
InitializeVariables(),
|
||||
DefineDefaultTarget(),
|
||||
LoadGitDetails(),
|
||||
pythonmutator.PythonMutator(pythonmutator.PythonMutatorPhaseLoad),
|
||||
|
||||
// Note: This mutator must run before the target overrides are merged.
|
||||
|
|
|
@ -39,6 +39,7 @@ func Initialize() bundle.Mutator {
|
|||
mutator.MergePipelineClusters(),
|
||||
mutator.InitializeWorkspaceClient(),
|
||||
mutator.PopulateCurrentUser(),
|
||||
mutator.LoadGitDetails(),
|
||||
|
||||
mutator.DefineDefaultWorkspaceRoot(),
|
||||
mutator.ExpandWorkspaceRoot(),
|
||||
|
|
|
@ -5,18 +5,19 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/databricks/cli/bundle/config/mutator"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGitAutoLoadWithEnvironment(t *testing.T) {
|
||||
b := load(t, "./environments_autoload_git")
|
||||
b := load(t, "./environments_autoload_git", mutator.LoadGitDetails())
|
||||
assert.True(t, b.Config.Bundle.Git.Inferred)
|
||||
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
|
||||
assert.True(t, validUrl, fmt.Sprintf("Expected URL to contain '/cli' or '/bricks', got %s", b.Config.Bundle.Git.OriginURL))
|
||||
}
|
||||
|
||||
func TestGitManuallySetBranchWithEnvironment(t *testing.T) {
|
||||
b := loadTarget(t, "./environments_autoload_git", "production")
|
||||
b := loadTarget(t, "./environments_autoload_git", "production", mutator.LoadGitDetails())
|
||||
assert.False(t, b.Config.Bundle.Git.Inferred)
|
||||
assert.Equal(t, "main", b.Config.Bundle.Git.Branch)
|
||||
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
|
||||
|
|
|
@ -12,15 +12,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGitAutoLoad(t *testing.T) {
|
||||
b := load(t, "./autoload_git")
|
||||
assert.True(t, b.Config.Bundle.Git.Inferred)
|
||||
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
|
||||
assert.True(t, validUrl, fmt.Sprintf("Expected URL to contain '/cli' or '/bricks', got %s", b.Config.Bundle.Git.OriginURL))
|
||||
}
|
||||
|
||||
func TestGitManuallySetBranch(t *testing.T) {
|
||||
b := loadTarget(t, "./autoload_git", "production")
|
||||
b := loadTarget(t, "./autoload_git", "production", mutator.LoadGitDetails())
|
||||
assert.False(t, b.Config.Bundle.Git.Inferred)
|
||||
assert.Equal(t, "main", b.Config.Bundle.Git.Branch)
|
||||
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
|
||||
|
@ -33,7 +26,7 @@ func TestGitBundleBranchValidation(t *testing.T) {
|
|||
git.GitDirectoryName = ".git"
|
||||
})
|
||||
|
||||
b := load(t, "./git_branch_validation")
|
||||
b := load(t, "./git_branch_validation", mutator.LoadGitDetails())
|
||||
assert.False(t, b.Config.Bundle.Git.Inferred)
|
||||
assert.Equal(t, "feature-a", b.Config.Bundle.Git.Branch)
|
||||
assert.Equal(t, "feature-b", b.Config.Bundle.Git.ActualBranch)
|
||||
|
|
|
@ -15,29 +15,33 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func load(t *testing.T, path string) *bundle.Bundle {
|
||||
func load(t *testing.T, path string, mutators ...bundle.Mutator) *bundle.Bundle {
|
||||
ctx := context.Background()
|
||||
b, err := bundle.Load(ctx, path)
|
||||
require.NoError(t, err)
|
||||
diags := bundle.Apply(ctx, b, phases.Load())
|
||||
require.NoError(t, diags.Error())
|
||||
for _, m := range mutators {
|
||||
diags := bundle.Apply(ctx, b, m)
|
||||
require.NoError(t, diags.Error())
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func loadTarget(t *testing.T, path, env string) *bundle.Bundle {
|
||||
b, diags := loadTargetWithDiags(path, env)
|
||||
func loadTarget(t *testing.T, path, env string, mutators ...bundle.Mutator) *bundle.Bundle {
|
||||
b, diags := loadTargetWithDiags(path, env, mutators...)
|
||||
require.NoError(t, diags.Error())
|
||||
return b
|
||||
}
|
||||
|
||||
func loadTargetWithDiags(path, env string) (*bundle.Bundle, diag.Diagnostics) {
|
||||
func loadTargetWithDiags(path, env string, mutators ...bundle.Mutator) (*bundle.Bundle, diag.Diagnostics) {
|
||||
ctx := context.Background()
|
||||
b, err := bundle.Load(ctx, path)
|
||||
if err != nil {
|
||||
return nil, diag.FromErr(err)
|
||||
}
|
||||
|
||||
diags := bundle.Apply(ctx, b, bundle.Seq(
|
||||
seq := []bundle.Mutator{
|
||||
phases.LoadNamedTarget(env),
|
||||
mutator.RewriteSyncPaths(),
|
||||
mutator.SyncDefaultPath(),
|
||||
|
@ -46,7 +50,10 @@ func loadTargetWithDiags(path, env string) (*bundle.Bundle, diag.Diagnostics) {
|
|||
mutator.MergeJobParameters(),
|
||||
mutator.MergeJobTasks(),
|
||||
mutator.MergePipelineClusters(),
|
||||
))
|
||||
}
|
||||
seq = append(seq, mutators...)
|
||||
diags := bundle.Apply(ctx, b, bundle.Seq(seq...))
|
||||
|
||||
return b, diags
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue