Skip to content
Open
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
33 changes: 19 additions & 14 deletions bundle/phases/dms.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,31 @@ func logDeploymentVersion(ctx context.Context, b *bundle.Bundle) {
cmdio.LogString(ctx, "Current Deployment Version: "+workspaceurls.DeploymentURL(*baseURL, deploymentID, version))
}

// deploymentMetadata describes the bundle this deploy came from and where it
// landed, mirroring what bundle/deploy/metadata computes for the metadata file.
func deploymentMetadata(b *bundle.Bundle) (dms.Metadata, error) {
// bundleMetadata describes the bundle and workspace without deployed file metadata.
func bundleMetadata(b *bundle.Bundle) dms.Metadata {
p := dms.Metadata{
DisplayName: b.Config.Bundle.Name,
TargetName: b.Config.Bundle.Target,
Mode: deploymentModeToSDK(b.Config.Bundle.Mode),
Workspace: &bundledeployments.WorkspaceInfo{
RootPath: b.Config.Workspace.RootPath,
},
}

ws := &bundledeployments.WorkspaceInfo{
RootPath: b.Config.Workspace.RootPath,
FilePath: b.Config.Workspace.FilePath,
// Only a deploy from a Databricks Git folder has one; a local worktree does not.
// bundle_root_path is relative to it, so the service requires both or neither.
if b.WorktreeRoot != nil && strings.HasPrefix(b.WorktreeRoot.Native(), "/Workspace/") {
p.Workspace.GitFolderPath = b.WorktreeRoot.Native()
p.Workspace.BundleRootPath = b.Config.Bundle.Git.BundleRootPath
}
return p
}

// deploymentMetadata describes the bundle this deploy came from and where it
// landed, mirroring what bundle/deploy/metadata computes for the metadata file.
func deploymentMetadata(b *bundle.Bundle) (dms.Metadata, error) {
p := bundleMetadata(b)
ws := p.Workspace
ws.FilePath = b.Config.Workspace.FilePath
// With an immutable folder, file_path is a reference to the snapshot, which only
// resolves once the snapshot is uploaded. Its path is already known from the staged zip.
if b.IsImmutableFolder() {
Expand All @@ -294,13 +306,6 @@ func deploymentMetadata(b *bundle.Bundle) (dms.Metadata, error) {
ws.FilePath = b.SyncRootPath
ws.SourceLinked = true
}
// Only a deploy from a Databricks Git folder has one; a local worktree does not.
// bundle_root_path is relative to it, so the service requires both or neither.
if b.WorktreeRoot != nil && strings.HasPrefix(b.WorktreeRoot.Native(), "/Workspace/") {
ws.GitFolderPath = b.WorktreeRoot.Native()
ws.BundleRootPath = b.Config.Bundle.Git.BundleRootPath
}
p.Workspace = ws
return p, nil
}

Expand Down
27 changes: 27 additions & 0 deletions bundle/phases/dms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,39 @@ package phases
import (
"testing"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/deployplan"
"github.com/databricks/databricks-sdk-go/service/bundledeployments"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestBundleMetadataWithoutDeployedFiles(t *testing.T) {
for _, mode := range []config.SyncMode{config.SyncModeImmutable, config.SyncModeInPlace} {
t.Run(string(mode), func(t *testing.T) {
b := &bundle.Bundle{
Config: config.Root{
Bundle: config.Bundle{Name: "test", Target: "prod", Mode: config.Production},
Workspace: config.Workspace{
RootPath: "/Workspace/bundle",
FilePath: "${resources.snapshots.files.full_path}/files",
SyncMode: mode,
},
},
SyncRootPath: "/Workspace/source",
}

assert.Equal(t, bundledeployments.Deployment{
DisplayName: "test",
TargetName: "prod",
DeploymentMode: bundledeployments.DeploymentModeDeploymentModeProduction,
WorkspaceInfo: &bundledeployments.WorkspaceInfo{RootPath: "/Workspace/bundle"},
}, bundleMetadata(b).Deployment())
})
}
}

func TestStagedOperationsCoversEveryTouchedResource(t *testing.T) {
// The version fixes its operation set, so anything the apply will write has to appear
// here. Keys go out in the service's form, without the CLI's "resources." prefix.
Expand Down
Loading