Skip to content
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

Remove support for DATABRICKS_BUNDLE_INCLUDES #1317

Merged
merged 5 commits into from
Mar 27, 2024
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
15 changes: 0 additions & 15 deletions bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 0 additions & 23 deletions bundle/config/mutator/process_root_includes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
40 changes: 0 additions & 40 deletions bundle/config/mutator/process_root_includes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
14 changes: 0 additions & 14 deletions bundle/env/includes.go

This file was deleted.

28 changes: 0 additions & 28 deletions bundle/env/includes_test.go

This file was deleted.

47 changes: 0 additions & 47 deletions bundle/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
Loading