diff --git a/.nextchanges/bundles/bundle-file-origin.md b/.nextchanges/bundles/bundle-file-origin.md new file mode 100644 index 00000000000..fe5a7f4259b --- /dev/null +++ b/.nextchanges/bundles/bundle-file-origin.md @@ -0,0 +1 @@ +* Tag the files and libraries that bundle commands upload to the workspace as deployment copies, so the workspace can tell them apart from a bundle's source files. ([#7893](https://github.com/databricks/cli/pull/7893)) diff --git a/acceptance/bundle/apps/app_yaml/out.app.yml.txt b/acceptance/bundle/apps/app_yaml/out.app.yml.txt index 29cb7da70fa..ebe0928b2c9 100644 --- a/acceptance/bundle/apps/app_yaml/out.app.yml.txt +++ b/acceptance/bundle/apps/app_yaml/out.app.yml.txt @@ -2,6 +2,7 @@ "method": "POST", "path": "/api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/app/app.yml", "q": { + "bundleFileOrigin": "DEPLOYMENT_COPY", "overwrite": "true" }, "raw_body": "command:\n - python\n - app.py\n" diff --git a/acceptance/bundle/deploy/readplan/whl-upload/output.txt b/acceptance/bundle/deploy/readplan/whl-upload/output.txt index fef495b6973..7ea15a3dc8d 100644 --- a/acceptance/bundle/deploy/readplan/whl-upload/output.txt +++ b/acceptance/bundle/deploy/readplan/whl-upload/output.txt @@ -13,6 +13,7 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged "method": "POST", "path": "/api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/whl-upload/default/artifacts/.internal/my_test_code-0.0.1+[UNIX_TIME_NANOS]-py3-none-any.whl", "q": { + "bundleFileOrigin": "DEPLOYMENT_COPY", "overwrite": "true" } } @@ -39,6 +40,7 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged "method": "POST", "path": "/api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/whl-upload/default/artifacts/.internal/my_test_code-0.0.1+[UNIX_TIME_NANOS]-py3-none-any.whl", "q": { + "bundleFileOrigin": "DEPLOYMENT_COPY", "overwrite": "true" } } diff --git a/acceptance/bundle/libraries/outside_of_bundle_root/output.txt b/acceptance/bundle/libraries/outside_of_bundle_root/output.txt index e7f1bc13643..a7e632d59bd 100644 --- a/acceptance/bundle/libraries/outside_of_bundle_root/output.txt +++ b/acceptance/bundle/libraries/outside_of_bundle_root/output.txt @@ -57,6 +57,7 @@ Resources: 2 created, 0 changed, 0 deleted, 0 unchanged "method": "POST", "path": "/api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/outside_of_bundle_root/default/artifacts/.internal/test.whl", "q": { + "bundleFileOrigin": "DEPLOYMENT_COPY", "overwrite": "true" } } diff --git a/acceptance/bundle/resources/jobs/request-summary/output.txt b/acceptance/bundle/resources/jobs/request-summary/output.txt index a05f10b342f..993864c8554 100644 --- a/acceptance/bundle/resources/jobs/request-summary/output.txt +++ b/acceptance/bundle/resources/jobs/request-summary/output.txt @@ -28,7 +28,7 @@ GET /api/2.0/workspace/get-status path=/Workspace/Users/[USERNAME]/.bundle/reque GET /api/2.0/workspace/get-status path=/Workspace/Users/[USERNAME]/.bundle/request-summary/default/state/deploy.lock return_export_info=true GET /api/2.0/workspace/get-status path=/Workspace/Users/[USERNAME]/.bundle/request-summary/default/state/deploy.lock return_export_info=true GET /api/2.0/workspace/get-status path=/Workspace/Users/[USERNAME]/.bundle/request-summary/default/state/deploy.lock return_export_info=true -POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/request-summary/default/files/databricks.yml overwrite=true +POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/request-summary/default/files/databricks.yml bundleFileOrigin=DEPLOYMENT_COPY overwrite=true POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/request-summary/default/state/deploy.lock overwrite=false POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/request-summary/default/state/deploy.lock overwrite=false POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/request-summary/default/state/deployment.json overwrite=true diff --git a/acceptance/bundle/sync/bundle_file_origin/databricks.yml b/acceptance/bundle/sync/bundle_file_origin/databricks.yml new file mode 100644 index 00000000000..576d7a9ef25 --- /dev/null +++ b/acceptance/bundle/sync/bundle_file_origin/databricks.yml @@ -0,0 +1,2 @@ +bundle: + name: test-bundle diff --git a/acceptance/bundle/sync/bundle_file_origin/hello.py b/acceptance/bundle/sync/bundle_file_origin/hello.py new file mode 100644 index 00000000000..11b15b1a458 --- /dev/null +++ b/acceptance/bundle/sync/bundle_file_origin/hello.py @@ -0,0 +1 @@ +print("hello") diff --git a/acceptance/bundle/sync/bundle_file_origin/out.test.toml b/acceptance/bundle/sync/bundle_file_origin/out.test.toml new file mode 100644 index 00000000000..a927a5fbc06 --- /dev/null +++ b/acceptance/bundle/sync/bundle_file_origin/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/sync/bundle_file_origin/output.txt b/acceptance/bundle/sync/bundle_file_origin/output.txt new file mode 100644 index 00000000000..294719392e4 --- /dev/null +++ b/acceptance/bundle/sync/bundle_file_origin/output.txt @@ -0,0 +1,36 @@ + +=== Deploy tags the bundle files it uploads, not its state files + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Files: 2 uploaded, 0 deleted +Resources: 0 created, 0 changed, 0 deleted, 0 unchanged + +>>> print_requests.py --summary --sort //default/files/ //state/metadata.json +POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/databricks.yml bundleFileOrigin=DEPLOYMENT_COPY overwrite=true +POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/hello.py bundleFileOrigin=DEPLOYMENT_COPY overwrite=true +POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json overwrite=true + +=== Bundle sync writes to the same file_path, so it tags them too + +>>> [CLI] bundle sync --full +Action: PUT: databricks.yml, hello.py +Initial Sync Complete +Uploaded databricks.yml +Uploaded hello.py + +>>> print_requests.py --summary --sort //api/2.0/workspace-files/import-file +POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/databricks.yml bundleFileOrigin=DEPLOYMENT_COPY overwrite=true +POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/hello.py bundleFileOrigin=DEPLOYMENT_COPY overwrite=true + +=== A plain sync does not tag its uploads + +>>> MSYS_NO_PATHCONV=1 [CLI] sync . /Users/[USERNAME]/plain-sync +Action: PUT: databricks.yml, hello.py +Initial Sync Complete +Uploaded databricks.yml +Uploaded hello.py + +>>> print_requests.py --summary --sort //api/2.0/workspace-files/import-file +POST /api/2.0/workspace-files/import-file/Users/[USERNAME]/plain-sync/databricks.yml overwrite=true +POST /api/2.0/workspace-files/import-file/Users/[USERNAME]/plain-sync/hello.py overwrite=true diff --git a/acceptance/bundle/sync/bundle_file_origin/script b/acceptance/bundle/sync/bundle_file_origin/script new file mode 100644 index 00000000000..8a5db36787c --- /dev/null +++ b/acceptance/bundle/sync/bundle_file_origin/script @@ -0,0 +1,13 @@ +title "Deploy tags the bundle files it uploads, not its state files" +trace $CLI bundle deploy +# Deployment history (DMS=true) also uploads resources.json, so only metadata.json stands for the state files. +trace print_requests.py --summary --sort //default/files/ //state/metadata.json + +title "Bundle sync writes to the same file_path, so it tags them too" +trace $CLI bundle sync --full | sort +trace print_requests.py --summary --sort //api/2.0/workspace-files/import-file + +title "A plain sync does not tag its uploads" +# Prevent Git Bash on Windows from converting the /Users/... sync target into a Windows path. +trace MSYS_NO_PATHCONV=1 $CLI sync . /Users/$CURRENT_USER_NAME/plain-sync | sort +trace print_requests.py --summary --sort //api/2.0/workspace-files/import-file diff --git a/acceptance/bundle/sync/bundle_file_origin/test.toml b/acceptance/bundle/sync/bundle_file_origin/test.toml new file mode 100644 index 00000000000..159efe02696 --- /dev/null +++ b/acceptance/bundle/sync/bundle_file_origin/test.toml @@ -0,0 +1 @@ +RecordRequests = true diff --git a/acceptance/bundle/sync/output.txt b/acceptance/bundle/sync/output.txt index 276972e0d5d..2b6cd8e61f4 100644 --- a/acceptance/bundle/sync/output.txt +++ b/acceptance/bundle/sync/output.txt @@ -1,8 +1,12 @@ >>> [CLI] bundle sync --output text -Action: PUT: .gitignore, databricks.yml, dryrun/databricks.yml, dryrun/out.test.toml, ignored-folder/folder1/script.py, ignored-folder/script.py, replace-node-type/bom.sql, replace-node-type/databricks.yml.tmpl, replace-node-type/out.test.toml, replace-node-type/plain.sql, upload-504/databricks.yml, upload-504/out.test.toml, zip-extract/archive.zip, zip-extract/archive_v2.zip, zip-extract/databricks.yml.tmpl, zip-extract/out.test.toml +Action: PUT: .gitignore, bundle_file_origin/databricks.yml, bundle_file_origin/hello.py, bundle_file_origin/out.test.toml, databricks.yml, dryrun/databricks.yml, dryrun/out.test.toml, ignored-folder/folder1/script.py, ignored-folder/script.py, replace-node-type/bom.sql, replace-node-type/databricks.yml.tmpl, replace-node-type/out.test.toml, replace-node-type/plain.sql, upload-504/databricks.yml, upload-504/out.test.toml, zip-extract/archive.zip, zip-extract/archive_v2.zip, zip-extract/databricks.yml.tmpl, zip-extract/out.test.toml Initial Sync Complete Uploaded .gitignore +Uploaded bundle_file_origin +Uploaded bundle_file_origin/databricks.yml +Uploaded bundle_file_origin/hello.py +Uploaded bundle_file_origin/out.test.toml Uploaded databricks.yml Uploaded dryrun Uploaded dryrun/databricks.yml diff --git a/acceptance/bundle/upload/internal_server_error/output.txt b/acceptance/bundle/upload/internal_server_error/output.txt index d75ee2a71b1..3a4f21ea673 100644 --- a/acceptance/bundle/upload/internal_server_error/output.txt +++ b/acceptance/bundle/upload/internal_server_error/output.txt @@ -3,7 +3,7 @@ Warn: retrying after 500 Internal Server Error from POST /api/2.0/workspace-file Warn: retrying after 500 Internal Server Error from POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/file_to_upload.txt Error: Fault injected by test. (500 INJECTED) -Endpoint: POST [DATABRICKS_URL]/api/2.0/workspace-files/import-file/Workspace%2FUsers%2F[USERNAME]%2F.bundle%2Ftest-bundle%2Fdefault%2Ffiles%2Ffile_to_upload.txt?overwrite=true +Endpoint: POST [DATABRICKS_URL]/api/2.0/workspace-files/import-file/Workspace%2FUsers%2F[USERNAME]%2F.bundle%2Ftest-bundle%2Fdefault%2Ffiles%2Ffile_to_upload.txt?overwrite=true&bundleFileOrigin=DEPLOYMENT_COPY HTTP Status: 500 Internal Server Error API error_code: INJECTED API message: Fault injected by test. diff --git a/acceptance/bundle/upload/timeout/output.txt b/acceptance/bundle/upload/timeout/output.txt index 26b3b8b8bae..3df896b23ca 100644 --- a/acceptance/bundle/upload/timeout/output.txt +++ b/acceptance/bundle/upload/timeout/output.txt @@ -1,7 +1,7 @@ Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Warn: retrying after Post "[DATABRICKS_URL]/api/2.0/workspace-files/import-file/Workspace%2FUsers%2F[USERNAME]%2F.bundle%2Ftest-bundle%2Fdefault%2Ffiles%2Ffile_to_upload.txt?overwrite=true": request timed out after 5s of inactivity -Warn: retrying after Post "[DATABRICKS_URL]/api/2.0/workspace-files/import-file/Workspace%2FUsers%2F[USERNAME]%2F.bundle%2Ftest-bundle%2Fdefault%2Ffiles%2Ffile_to_upload.txt?overwrite=true": request timed out after 5s of inactivity -Error: Post "[DATABRICKS_URL]/api/2.0/workspace-files/import-file/Workspace%2FUsers%2F[USERNAME]%2F.bundle%2Ftest-bundle%2Fdefault%2Ffiles%2Ffile_to_upload.txt?overwrite=true": request timed out after 5s of inactivity +Warn: retrying after Post "[DATABRICKS_URL]/api/2.0/workspace-files/import-file/Workspace%2FUsers%2F[USERNAME]%2F.bundle%2Ftest-bundle%2Fdefault%2Ffiles%2Ffile_to_upload.txt?overwrite=true&bundleFileOrigin=DEPLOYMENT_COPY": request timed out after 5s of inactivity +Warn: retrying after Post "[DATABRICKS_URL]/api/2.0/workspace-files/import-file/Workspace%2FUsers%2F[USERNAME]%2F.bundle%2Ftest-bundle%2Fdefault%2Ffiles%2Ffile_to_upload.txt?overwrite=true&bundleFileOrigin=DEPLOYMENT_COPY": request timed out after 5s of inactivity +Error: Post "[DATABRICKS_URL]/api/2.0/workspace-files/import-file/Workspace%2FUsers%2F[USERNAME]%2F.bundle%2Ftest-bundle%2Fdefault%2Ffiles%2Ffile_to_upload.txt?overwrite=true&bundleFileOrigin=DEPLOYMENT_COPY": request timed out after 5s of inactivity /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/file_to_upload.txt /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/file_to_upload.txt diff --git a/acceptance/bundle/user_agent/simple/out.requests.deploy.json b/acceptance/bundle/user_agent/simple/out.requests.deploy.json index aaca239572d..79fc8c8aa0e 100644 --- a/acceptance/bundle/user_agent/simple/out.requests.deploy.json +++ b/acceptance/bundle/user_agent/simple/out.requests.deploy.json @@ -132,6 +132,7 @@ "method": "POST", "path": "/api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/empty.py", "q": { + "bundleFileOrigin": "DEPLOYMENT_COPY", "overwrite": "true" } } diff --git a/acceptance/bundle/validate/sync_patterns/out.sync.txt b/acceptance/bundle/validate/sync_patterns/out.sync.txt index ac5aba9ab29..dff8e130c30 100644 --- a/acceptance/bundle/validate/sync_patterns/out.sync.txt +++ b/acceptance/bundle/validate/sync_patterns/out.sync.txt @@ -2,6 +2,7 @@ "method": "POST", "path": "/api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/conf/dir/test.yml", "q": { + "bundleFileOrigin": "DEPLOYMENT_COPY", "overwrite": "true" } } diff --git a/bundle/deploy/files/sync.go b/bundle/deploy/files/sync.go index 152df0f3692..0c55723bdb2 100644 --- a/bundle/deploy/files/sync.go +++ b/bundle/deploy/files/sync.go @@ -3,8 +3,11 @@ package files import ( "context" "fmt" + "path" + "strings" "github.com/databricks/cli/bundle" + "github.com/databricks/cli/libs/dbr" "github.com/databricks/cli/libs/sync" ) @@ -55,6 +58,8 @@ func GetSyncOptions(ctx context.Context, b *bundle.Bundle) (*sync.SyncOptions, e SnapshotBasePath: cacheDir, WorkspaceClient: b.WorkspaceClient(ctx), + + DeploymentCopy: !writesOntoSource(ctx, b), } if b.Config.Workspace.CurrentUser != nil { @@ -63,3 +68,19 @@ func GetSyncOptions(ctx context.Context, b *bundle.Bundle) (*sync.SyncOptions, e return opts, nil } + +// writesOntoSource reports whether file_path is the sync root itself, as in a +// deploy from a workspace folder that points file_path at that folder. Those +// files are the bundle's source, not a deployment copy. +func writesOntoSource(ctx context.Context, b *bundle.Bundle) bool { + if !dbr.HasDetection(ctx) || !dbr.RunsOnRuntime(ctx) { + return false + } + // A file_path set from a variable can still lack the /Workspace prefix, + // because PrependWorkspacePrefix runs before variables are resolved. + filePath := b.Config.Workspace.FilePath + if !strings.HasPrefix(filePath, "/Workspace/") { + filePath = path.Join("/Workspace", filePath) + } + return path.Clean(filePath) == path.Clean(b.SyncRootPath) +} diff --git a/bundle/deploy/files/sync_test.go b/bundle/deploy/files/sync_test.go new file mode 100644 index 00000000000..3bda77f1925 --- /dev/null +++ b/bundle/deploy/files/sync_test.go @@ -0,0 +1,64 @@ +package files + +import ( + "testing" + + "github.com/databricks/cli/bundle" + "github.com/databricks/cli/bundle/config" + "github.com/databricks/cli/libs/dbr" + "github.com/stretchr/testify/assert" +) + +func TestWritesOntoSource(t *testing.T) { + for _, tc := range []struct { + name string + isDbr bool + syncRootPath string + filePath string + expect bool + }{ + { + name: "file_path is the workspace sync root", + isDbr: true, + syncRootPath: "/Workspace/Users/me/my_bundle", + filePath: "/Workspace/Users/me/my_bundle/", + expect: true, + }, + { + name: "file_path from a variable without the /Workspace prefix", + isDbr: true, + syncRootPath: "/Workspace/Users/me/my_bundle", + filePath: "/Users/me/my_bundle", + expect: true, + }, + { + name: "default file_path from the workspace", + isDbr: true, + syncRootPath: "/Workspace/Users/me/my_bundle", + filePath: "/Workspace/Users/me/.bundle/my_bundle/default/files", + expect: false, + }, + { + name: "same path outside the runtime", + isDbr: false, + syncRootPath: "/Workspace/Users/me/my_bundle", + filePath: "/Workspace/Users/me/my_bundle", + expect: false, + }, + } { + t.Run(tc.name, func(t *testing.T) { + ctx := dbr.MockRuntime(t.Context(), dbr.Environment{IsDbr: tc.isDbr}) + b := &bundle.Bundle{ + SyncRootPath: tc.syncRootPath, + Config: config.Root{ + Workspace: config.Workspace{FilePath: tc.filePath}, + }, + } + assert.Equal(t, tc.expect, writesOntoSource(ctx, b)) + }) + } + + t.Run("no runtime detection", func(t *testing.T) { + assert.False(t, writesOntoSource(t.Context(), &bundle.Bundle{})) + }) +} diff --git a/bundle/libraries/filer_workspace.go b/bundle/libraries/filer_workspace.go index 3d223c342f8..35fe78693c5 100644 --- a/bundle/libraries/filer_workspace.go +++ b/bundle/libraries/filer_workspace.go @@ -9,6 +9,6 @@ import ( ) func filerForWorkspace(ctx context.Context, b *bundle.Bundle, uploadPath string) (filer.Filer, string, diag.Diagnostics) { - f, err := filer.NewWorkspaceFilesClient(b.WorkspaceClient(ctx), uploadPath) + f, err := filer.NewWorkspaceFilesClientForBundleDeploy(b.WorkspaceClient(ctx), uploadPath) return f, uploadPath, diag.FromErr(err) } diff --git a/libs/filer/workspace_files_client.go b/libs/filer/workspace_files_client.go index 30ca51f03d9..dd7534e7dc8 100644 --- a/libs/filer/workspace_files_client.go +++ b/libs/filer/workspace_files_client.go @@ -122,6 +122,10 @@ type WorkspaceFilesClient struct { // File operations will be relative to this path. root WorkspaceRootPath + + // Tag every upload as written by a bundle deployment, so the workspace + // does not treat a deployed databricks.yml as a bundle's source. + deploymentCopy bool } // workspaceIDHeaders returns the workspace routing header map for outbound @@ -137,6 +141,16 @@ func (w *WorkspaceFilesClient) workspaceIDHeaders() map[string]string { } func NewWorkspaceFilesClient(w *databricks.WorkspaceClient, root string) (Filer, error) { + return newWorkspaceFilesClient(w, root, false) +} + +// NewWorkspaceFilesClientForBundleDeploy returns a client that tags every +// upload as a bundle deployment copy. +func NewWorkspaceFilesClientForBundleDeploy(w *databricks.WorkspaceClient, root string) (Filer, error) { + return newWorkspaceFilesClient(w, root, true) +} + +func newWorkspaceFilesClient(w *databricks.WorkspaceClient, root string, deploymentCopy bool) (Filer, error) { apiClient, err := client.New(w.Config) if err != nil { return nil, err @@ -147,6 +161,8 @@ func NewWorkspaceFilesClient(w *databricks.WorkspaceClient, root string) (Filer, apiClient: apiClient, root: NewWorkspaceRootPath(root), + + deploymentCopy: deploymentCopy, }, nil } @@ -163,6 +179,10 @@ func (w *WorkspaceFilesClient) Write(ctx context.Context, name string, reader io url.PathEscape(strings.TrimLeft(absPath, "/")), overwrite, ) + // Workspaces that do not know the parameter ignore it. + if w.deploymentCopy { + urlPath += "&bundleFileOrigin=DEPLOYMENT_COPY" + } // Buffer the file contents because we may need to retry below and we cannot read twice. body, err := io.ReadAll(reader) diff --git a/libs/filer/workspace_files_client_test.go b/libs/filer/workspace_files_client_test.go index 2915af60436..c7de6592fd6 100644 --- a/libs/filer/workspace_files_client_test.go +++ b/libs/filer/workspace_files_client_test.go @@ -3,6 +3,8 @@ package filer import ( "encoding/json" "io/fs" + "net/url" + "strings" "testing" "time" @@ -181,3 +183,44 @@ func TestWorkspaceFilesClientStatNotFound(t *testing.T) { err := statWithError(t, 404, "RESOURCE_DOES_NOT_EXIST") assert.ErrorIs(t, err, fs.ErrNotExist) } + +func TestWorkspaceFilesClientWriteBundleFileOrigin(t *testing.T) { + for _, tc := range []struct { + name string + newFn func(*databricks.WorkspaceClient, string) (Filer, error) + expect url.Values + }{ + { + name: "default", + newFn: NewWorkspaceFilesClient, + expect: url.Values{"overwrite": {"true"}}, + }, + { + name: "bundle deploy", + newFn: NewWorkspaceFilesClientForBundleDeploy, + expect: url.Values{"overwrite": {"true"}, "bundleFileOrigin": {"DEPLOYMENT_COPY"}}, + }, + } { + t.Run(tc.name, func(t *testing.T) { + var query url.Values + server := testserver.New(t) + server.Handle("POST", "/api/2.0/workspace-files/import-file/{path...}", func(req testserver.Request) any { + query = req.URL.Query() + return "" + }) + + client, err := databricks.NewWorkspaceClient(&databricks.Config{ + Host: server.URL, + Token: "testtoken", + }) + require.NoError(t, err) + + f, err := tc.newFn(client, "/test") + require.NoError(t, err) + + err = f.Write(t.Context(), "databricks.yml", strings.NewReader("bundle: {}"), OverwriteIfExists) + require.NoError(t, err) + assert.Equal(t, tc.expect, query) + }) + } +} diff --git a/libs/sync/sync.go b/libs/sync/sync.go index 1e31b85481f..223dd8c302c 100644 --- a/libs/sync/sync.go +++ b/libs/sync/sync.go @@ -52,6 +52,9 @@ type SyncOptions struct { DryRun bool NoValidateRemotePath bool + + // Tag uploads as bundle deployment copies. + DeploymentCopy bool } type Sync struct { @@ -115,7 +118,11 @@ func New(ctx context.Context, opts SyncOptions) (*Sync, error) { } } - workspaceFiler, err := filer.NewWorkspaceFilesClient(opts.WorkspaceClient, opts.RemotePath) + newWorkspaceFiler := filer.NewWorkspaceFilesClient + if opts.DeploymentCopy { + newWorkspaceFiler = filer.NewWorkspaceFilesClientForBundleDeploy + } + workspaceFiler, err := newWorkspaceFiler(opts.WorkspaceClient, opts.RemotePath) if err != nil { return nil, err }