Skip to content

Commit 834245b

Browse files
authored
Fixed sync include/exclude not working correctly on Windows (#2609)
## Changes Fixed sync include/exclude not working correctly on Windows Fixes #1572 ## Why We need to convert `include` and `exclude` in the `sync` block to use Unix-style slashes because this is required for the ignore.GitIgnore we use in libs/fileset to work correctly. ## Tests Added acceptance test
1 parent ad0cc3a commit 834245b

File tree

16 files changed

+116
-36
lines changed

16 files changed

+116
-36
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Previously ".internal" folder under artifact_path was not cleaned up as expected
1515

1616
### Bundles
1717
* Fixed cleaning up artifact path .internal folder ([#2572](https://github.com/databricks/cli/pull/2572))
18+
* Fixed sync include/exclude not working correctly on Windows ([#2609](https://github.com/databricks/cli/pull/2609))
1819
* Added support for quality monitors in deployment bind/unbind commands ([#2583](https://github.com/databricks/cli/pull/2583))
1920
* Comment out email\_notifications section in builtin templates ([#2565](https://github.com/databricks/cli/pull/2565))
2021
* New DATABRICKS_BUNDLE_RESTRICTED_CODE_EXECUTION environment variable that rejects running scripts and Python code when it is set ([#2598](https://github.com/databricks/cli/pull/2598))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.yml

acceptance/bundle/validate/sync_patterns/conf/dir/test.txt

Whitespace-only changes.

acceptance/bundle/validate/sync_patterns/conf/dir/test.yml

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
bundle:
2+
name: sync_patterns
3+
4+
sync:
5+
include:
6+
- conf/dir/*.yml
7+
exclude:
8+
- conf/dir/*.txt
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"method": "POST",
3+
"path": "/api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/sync_patterns/default/files/conf/dir/test.yml"
4+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
>>> [CLI] bundle validate
3+
Name: sync_patterns
4+
Target: default
5+
Workspace:
6+
User: [USERNAME]
7+
Path: /Workspace/Users/[USERNAME]/.bundle/sync_patterns/default
8+
9+
Validation OK!
10+
11+
>>> [CLI] bundle validate -o json
12+
{
13+
"exclude": [
14+
"conf/dir/*.txt"
15+
],
16+
"include": [
17+
"conf/dir/*.yml"
18+
],
19+
"paths": [
20+
"."
21+
]
22+
}
23+
24+
>>> [CLI] bundle deploy
25+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/sync_patterns/default/files...
26+
Deploying resources...
27+
Deployment complete!
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
trace $CLI bundle validate
2+
trace $CLI bundle validate -o json | jq '.sync'
3+
trace $CLI bundle deploy
4+
jq 'select(.path | test("/api/2.0/workspace-files/import-file/Workspace/Users/.*/.bundle/sync_patterns/default/files/conf/dir/test.yml"))' out.requests.txt > out.sync.txt
5+
rm out.requests.txt
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cloud = false
2+
RecordRequests = true

bundle/config/mutator/rewrite_sync_paths.go

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

33
import (
44
"context"
5+
"fmt"
56
"path/filepath"
67

78
"github.com/databricks/cli/bundle"
@@ -49,11 +50,38 @@ func (m *rewriteSyncPaths) Apply(ctx context.Context, b *bundle.Bundle) diag.Dia
4950
if err != nil {
5051
return dyn.InvalidValue, err
5152
}
52-
v, err = dyn.Map(v, "include", dyn.Foreach(m.makeRelativeTo(b.BundleRootPath)))
53+
54+
makeRelativeFn := m.makeRelativeTo(b.BundleRootPath)
55+
56+
// Makes include and exclude paths relative to the bundle root first.
57+
// Then converts them to use Unix-style slashes.
58+
// This is required for the ignore.GitIgnore we use in libs/fileset to work correctly.
59+
v, err = dyn.Map(v, "include", dyn.Foreach(func(p dyn.Path, val dyn.Value) (dyn.Value, error) {
60+
relPath, err := makeRelativeFn(p, val)
61+
if err != nil {
62+
return dyn.InvalidValue, err
63+
}
64+
str, ok := relPath.AsString()
65+
if !ok {
66+
return dyn.InvalidValue, fmt.Errorf("expected string value but got %s", relPath.Kind())
67+
}
68+
return dyn.NewValue(filepath.ToSlash(str), relPath.Locations()), nil
69+
}))
5370
if err != nil {
5471
return dyn.InvalidValue, err
5572
}
56-
v, err = dyn.Map(v, "exclude", dyn.Foreach(m.makeRelativeTo(b.BundleRootPath)))
73+
74+
v, err = dyn.Map(v, "exclude", dyn.Foreach(func(p dyn.Path, val dyn.Value) (dyn.Value, error) {
75+
relPath, err := makeRelativeFn(p, val)
76+
if err != nil {
77+
return dyn.InvalidValue, err
78+
}
79+
str, ok := relPath.AsString()
80+
if !ok {
81+
return dyn.InvalidValue, fmt.Errorf("expected string value but got %s", relPath.Kind())
82+
}
83+
return dyn.NewValue(filepath.ToSlash(str), relPath.Locations()), nil
84+
}))
5785
if err != nil {
5886
return dyn.InvalidValue, err
5987
}

0 commit comments

Comments
 (0)