mirror of https://github.com/databricks/cli.git
Remove support for DATABRICKS_BUNDLE_INCLUDES (#1317)
## Changes PR #604 added functionality to load a bundle without a `databricks.yml` if both the `DATABRICKS_BUNDLE_ROOT` and `DATABRICKS_BUNDLE_INCLUDES` environment variables were set. We never ended up using this in downstream tools so this can be removed. ## Tests Unit tests pass.
This commit is contained in:
parent
00d76d5afa
commit
f195b84475
|
@ -70,23 +70,8 @@ func Load(ctx context.Context, path string) (*Bundle, error) {
|
||||||
b := &Bundle{
|
b := &Bundle{
|
||||||
RootPath: filepath.Clean(path),
|
RootPath: filepath.Clean(path),
|
||||||
}
|
}
|
||||||
stat, err := os.Stat(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
configFile, err := config.FileNames.FindInPath(path)
|
configFile, err := config.FileNames.FindInPath(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_, hasRootEnv := env.Root(ctx)
|
|
||||||
_, hasIncludesEnv := env.Includes(ctx)
|
|
||||||
if hasRootEnv && hasIncludesEnv && stat.IsDir() {
|
|
||||||
log.Debugf(ctx, "No bundle configuration; using bundle root: %s", path)
|
|
||||||
b.Config = config.Root{
|
|
||||||
Bundle: config.Bundle{
|
|
||||||
Name: filepath.Base(path),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return b, nil
|
|
||||||
}
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Debugf(ctx, "Loading bundle configuration from: %s", configFile)
|
log.Debugf(ctx, "Loading bundle configuration from: %s", configFile)
|
||||||
|
|
|
@ -2,26 +2,15 @@ package mutator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/databricks/cli/bundle"
|
"github.com/databricks/cli/bundle"
|
||||||
"github.com/databricks/cli/bundle/config"
|
"github.com/databricks/cli/bundle/config"
|
||||||
"github.com/databricks/cli/bundle/env"
|
|
||||||
"github.com/databricks/cli/libs/diag"
|
"github.com/databricks/cli/libs/diag"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get extra include paths from environment variable
|
|
||||||
func getExtraIncludePaths(ctx context.Context) []string {
|
|
||||||
value, exists := env.Includes(ctx)
|
|
||||||
if !exists {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return strings.Split(value, string(os.PathListSeparator))
|
|
||||||
}
|
|
||||||
|
|
||||||
type processRootIncludes struct{}
|
type processRootIncludes struct{}
|
||||||
|
|
||||||
// ProcessRootIncludes expands the patterns in the configuration's include list
|
// ProcessRootIncludes expands the patterns in the configuration's include list
|
||||||
|
@ -48,18 +37,6 @@ func (m *processRootIncludes) Apply(ctx context.Context, b *bundle.Bundle) diag.
|
||||||
// This is stored in the bundle configuration for observability.
|
// This is stored in the bundle configuration for observability.
|
||||||
var files []string
|
var files []string
|
||||||
|
|
||||||
// Converts extra include paths from environment variable to relative paths
|
|
||||||
for _, extraIncludePath := range getExtraIncludePaths(ctx) {
|
|
||||||
if filepath.IsAbs(extraIncludePath) {
|
|
||||||
rel, err := filepath.Rel(b.RootPath, extraIncludePath)
|
|
||||||
if err != nil {
|
|
||||||
return diag.Errorf("unable to include file '%s': %v", extraIncludePath, err)
|
|
||||||
}
|
|
||||||
extraIncludePath = rel
|
|
||||||
}
|
|
||||||
b.Config.Include = append(b.Config.Include, extraIncludePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
// For each glob, find all files to load.
|
// For each glob, find all files to load.
|
||||||
// Ordering of the list of globs is maintained in the output.
|
// Ordering of the list of globs is maintained in the output.
|
||||||
// For matches that appear in multiple globs, only the first is kept.
|
// For matches that appear in multiple globs, only the first is kept.
|
||||||
|
|
|
@ -2,16 +2,12 @@ package mutator_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/databricks/cli/bundle"
|
"github.com/databricks/cli/bundle"
|
||||||
"github.com/databricks/cli/bundle/config"
|
"github.com/databricks/cli/bundle/config"
|
||||||
"github.com/databricks/cli/bundle/config/mutator"
|
"github.com/databricks/cli/bundle/config/mutator"
|
||||||
"github.com/databricks/cli/bundle/env"
|
|
||||||
"github.com/databricks/cli/internal/testutil"
|
"github.com/databricks/cli/internal/testutil"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -115,39 +111,3 @@ func TestProcessRootIncludesNotExists(t *testing.T) {
|
||||||
require.True(t, diags.HasError())
|
require.True(t, diags.HasError())
|
||||||
assert.ErrorContains(t, diags.Error(), "notexist.yml defined in 'include' section does not match any files")
|
assert.ErrorContains(t, diags.Error(), "notexist.yml defined in 'include' section does not match any files")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProcessRootIncludesExtrasFromEnvVar(t *testing.T) {
|
|
||||||
rootPath := t.TempDir()
|
|
||||||
testYamlName := "extra_include_path.yml"
|
|
||||||
testutil.Touch(t, rootPath, testYamlName)
|
|
||||||
t.Setenv(env.IncludesVariable, path.Join(rootPath, testYamlName))
|
|
||||||
|
|
||||||
b := &bundle.Bundle{
|
|
||||||
RootPath: rootPath,
|
|
||||||
}
|
|
||||||
|
|
||||||
diags := bundle.Apply(context.Background(), b, mutator.ProcessRootIncludes())
|
|
||||||
require.NoError(t, diags.Error())
|
|
||||||
assert.Contains(t, b.Config.Include, testYamlName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestProcessRootIncludesDedupExtrasFromEnvVar(t *testing.T) {
|
|
||||||
rootPath := t.TempDir()
|
|
||||||
testYamlName := "extra_include_path.yml"
|
|
||||||
testutil.Touch(t, rootPath, testYamlName)
|
|
||||||
t.Setenv(env.IncludesVariable, strings.Join(
|
|
||||||
[]string{
|
|
||||||
path.Join(rootPath, testYamlName),
|
|
||||||
path.Join(rootPath, testYamlName),
|
|
||||||
},
|
|
||||||
string(os.PathListSeparator),
|
|
||||||
))
|
|
||||||
|
|
||||||
b := &bundle.Bundle{
|
|
||||||
RootPath: rootPath,
|
|
||||||
}
|
|
||||||
|
|
||||||
diags := bundle.Apply(context.Background(), b, mutator.ProcessRootIncludes())
|
|
||||||
require.NoError(t, diags.Error())
|
|
||||||
assert.Equal(t, []string{testYamlName}, b.Config.Include)
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
package env
|
|
||||||
|
|
||||||
import "context"
|
|
||||||
|
|
||||||
// IncludesVariable names the environment variable that holds additional configuration paths to include
|
|
||||||
// during bundle configuration loading. Also see `bundle/config/mutator/process_root_includes.go`.
|
|
||||||
const IncludesVariable = "DATABRICKS_BUNDLE_INCLUDES"
|
|
||||||
|
|
||||||
// Includes returns the bundle Includes environment variable.
|
|
||||||
func Includes(ctx context.Context) (string, bool) {
|
|
||||||
return get(ctx, []string{
|
|
||||||
IncludesVariable,
|
|
||||||
})
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
package env
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/databricks/cli/internal/testutil"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestIncludes(t *testing.T) {
|
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
testutil.CleanupEnvironment(t)
|
|
||||||
|
|
||||||
t.Run("set", func(t *testing.T) {
|
|
||||||
t.Setenv("DATABRICKS_BUNDLE_INCLUDES", "foo")
|
|
||||||
includes, ok := Includes(ctx)
|
|
||||||
assert.True(t, ok)
|
|
||||||
assert.Equal(t, "foo", includes)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("not set", func(t *testing.T) {
|
|
||||||
includes, ok := Includes(ctx)
|
|
||||||
assert.False(t, ok)
|
|
||||||
assert.Equal(t, "", includes)
|
|
||||||
})
|
|
||||||
}
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/databricks/cli/bundle/config"
|
"github.com/databricks/cli/bundle/config"
|
||||||
"github.com/databricks/cli/bundle/env"
|
"github.com/databricks/cli/bundle/env"
|
||||||
"github.com/databricks/cli/internal/testutil"
|
"github.com/databricks/cli/internal/testutil"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -94,49 +93,3 @@ func TestRootLookupError(t *testing.T) {
|
||||||
_, err := mustGetRoot(ctx)
|
_, err := mustGetRoot(ctx)
|
||||||
require.ErrorContains(t, err, "unable to locate bundle root")
|
require.ErrorContains(t, err, "unable to locate bundle root")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadYamlWhenIncludesEnvPresent(t *testing.T) {
|
|
||||||
ctx := context.Background()
|
|
||||||
testutil.Chdir(t, filepath.Join(".", "tests", "basic"))
|
|
||||||
t.Setenv(env.IncludesVariable, "test")
|
|
||||||
|
|
||||||
bundle, err := MustLoad(ctx)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, "basic", bundle.Config.Bundle.Name)
|
|
||||||
|
|
||||||
cwd, err := os.Getwd()
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, cwd, bundle.RootPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLoadDefautlBundleWhenNoYamlAndRootAndIncludesEnvPresent(t *testing.T) {
|
|
||||||
ctx := context.Background()
|
|
||||||
dir := t.TempDir()
|
|
||||||
testutil.Chdir(t, dir)
|
|
||||||
t.Setenv(env.RootVariable, dir)
|
|
||||||
t.Setenv(env.IncludesVariable, "test")
|
|
||||||
|
|
||||||
bundle, err := MustLoad(ctx)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, dir, bundle.RootPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestErrorIfNoYamlNoRootEnvAndIncludesEnvPresent(t *testing.T) {
|
|
||||||
ctx := context.Background()
|
|
||||||
dir := t.TempDir()
|
|
||||||
testutil.Chdir(t, dir)
|
|
||||||
t.Setenv(env.IncludesVariable, "test")
|
|
||||||
|
|
||||||
_, err := MustLoad(ctx)
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestErrorIfNoYamlNoIncludesEnvAndRootEnvPresent(t *testing.T) {
|
|
||||||
ctx := context.Background()
|
|
||||||
dir := t.TempDir()
|
|
||||||
testutil.Chdir(t, dir)
|
|
||||||
t.Setenv(env.RootVariable, dir)
|
|
||||||
|
|
||||||
_, err := MustLoad(ctx)
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue