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:
Pieter Noordhuis 2024-03-27 11:13:54 +01:00 committed by GitHub
parent 00d76d5afa
commit f195b84475
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 0 additions and 167 deletions

View File

@ -70,23 +70,8 @@ func Load(ctx context.Context, path string) (*Bundle, error) {
b := &Bundle{
RootPath: filepath.Clean(path),
}
stat, err := os.Stat(path)
if err != nil {
return nil, err
}
configFile, err := config.FileNames.FindInPath(path)
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
}
log.Debugf(ctx, "Loading bundle configuration from: %s", configFile)

View File

@ -2,26 +2,15 @@ package mutator
import (
"context"
"os"
"path/filepath"
"slices"
"strings"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/env"
"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{}
// 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.
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.
// Ordering of the list of globs is maintained in the output.
// For matches that appear in multiple globs, only the first is kept.

View File

@ -2,16 +2,12 @@ package mutator_test
import (
"context"
"os"
"path"
"runtime"
"strings"
"testing"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/config/mutator"
"github.com/databricks/cli/bundle/env"
"github.com/databricks/cli/internal/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -115,39 +111,3 @@ func TestProcessRootIncludesNotExists(t *testing.T) {
require.True(t, diags.HasError())
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)
}

View File

@ -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,
})
}

View File

@ -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)
})
}

View File

@ -9,7 +9,6 @@ import (
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/env"
"github.com/databricks/cli/internal/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -94,49 +93,3 @@ func TestRootLookupError(t *testing.T) {
_, err := mustGetRoot(ctx)
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)
}