Skip to content

Commit dfa9454

Browse files
authored
Add source_linked_deployment & git_folder_path to metadata.json (#3719)
## Changes Add two new fields to `metadata.json`: - `config.presets.source_linked_deployment` - `extra.git_folder_path` ## Why To support Lakeflow integration with DABs ## Tests Added unit tests <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 449a250 commit dfa9454

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

acceptance/bundle/deploy/jobs/check-metadata/output.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ Deployment complete!
5757
"relative_path": "databricks.yml"
5858
}
5959
}
60+
},
61+
"presets": {
62+
"source_linked_deployment": false
6063
}
61-
}
64+
},
65+
"extra": {}
6266
}
6367
=== Check that metadata contains created job ids
6468
>>> cat metadata.json

bundle/deploy/metadata/compute.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package metadata
33
import (
44
"context"
55
"path/filepath"
6+
"strings"
67

78
"github.com/databricks/cli/bundle"
89
"github.com/databricks/cli/bundle/config"
@@ -83,6 +84,13 @@ func (m *compute) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics
8384
// In source-linked deployment files are not copied and resources use source files, therefore we use sync path as file path in metadata
8485
if config.IsExplicitlyEnabled(b.Config.Presets.SourceLinkedDeployment) {
8586
b.Metadata.Config.Workspace.FilePath = b.SyncRootPath
87+
b.Metadata.Config.Presets.SourceLinkedDeployment = true
8688
}
89+
90+
// Set the git folder path for deployments from the workspace
91+
if b.WorktreeRoot != nil && strings.HasPrefix(b.WorktreeRoot.Native(), "/Workspace/") {
92+
b.Metadata.Extra.GitFolderPath = b.WorktreeRoot.Native()
93+
}
94+
8795
return nil
8896
}

bundle/deploy/metadata/compute_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package metadata
22

33
import (
44
"context"
5+
"runtime"
56
"testing"
67

78
"github.com/databricks/cli/bundle"
@@ -10,6 +11,7 @@ import (
1011
"github.com/databricks/cli/bundle/internal/bundletest"
1112
"github.com/databricks/cli/bundle/metadata"
1213
"github.com/databricks/cli/libs/dyn"
14+
"github.com/databricks/cli/libs/vfs"
1315
"github.com/databricks/databricks-sdk-go/service/jobs"
1416
"github.com/databricks/databricks-sdk-go/service/pipelines"
1517
"github.com/stretchr/testify/assert"
@@ -136,4 +138,24 @@ func TestComputeMetadataMutatorSourceLinked(t *testing.T) {
136138
require.NoError(t, diags.Error())
137139

138140
assert.Equal(t, syncRootPath, b.Metadata.Config.Workspace.FilePath)
141+
assert.True(t, b.Metadata.Config.Presets.SourceLinkedDeployment)
142+
}
143+
144+
func TestComputeMetadataMutatorGitFolderPath(t *testing.T) {
145+
// The native path of the worktree root on Windows will never match the /Workspace prefix,
146+
// so `GitFolderPath` will never be set and this test will never pass
147+
if runtime.GOOS == "windows" {
148+
t.Skip("this test is not applicable on Windows")
149+
}
150+
gitFolderPath := "/Workspace/Users/[email protected]/git_folder"
151+
path := vfs.MustNew(gitFolderPath)
152+
b := &bundle.Bundle{
153+
Config: config.Root{},
154+
WorktreeRoot: path,
155+
}
156+
157+
diags := bundle.Apply(context.Background(), b, Compute())
158+
require.NoError(t, diags.Error())
159+
160+
assert.Equal(t, gitFolderPath, b.Metadata.Extra.GitFolderPath)
139161
}

bundle/metadata/metadata.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,19 @@ type Resources struct {
2727
Pipelines map[string]*Resource `json:"pipelines,omitempty"`
2828
}
2929

30+
type Presets struct {
31+
SourceLinkedDeployment bool `json:"source_linked_deployment"`
32+
}
33+
3034
type Config struct {
3135
Bundle Bundle `json:"bundle,omitempty"`
3236
Workspace Workspace `json:"workspace,omitempty"`
3337
Resources Resources `json:"resources,omitempty"`
38+
Presets Presets `json:"presets,omitempty"`
39+
}
40+
41+
type Extra struct {
42+
GitFolderPath string `json:"git_folder_path,omitempty"`
3443
}
3544

3645
// Metadata about the bundle deployment. This is the interface Databricks services
@@ -43,4 +52,6 @@ type Metadata struct {
4352
Version int `json:"version"`
4453

4554
Config Config `json:"config"`
55+
// Fields that don't map 1-to-1 with the bundle configuration schema
56+
Extra Extra `json:"extra"`
4657
}

0 commit comments

Comments
 (0)