diff --git a/bundle/phases/dms.go b/bundle/phases/dms.go index bd5d846420d..f6f29b833a0 100644 --- a/bundle/phases/dms.go +++ b/bundle/phases/dms.go @@ -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() { @@ -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 } diff --git a/bundle/phases/dms_test.go b/bundle/phases/dms_test.go index 6b045f863ae..cbb98f9fe63 100644 --- a/bundle/phases/dms_test.go +++ b/bundle/phases/dms_test.go @@ -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.