Skip to content

Commit

Permalink
fix: Allow partial match for manual sync
Browse files Browse the repository at this point in the history
  • Loading branch information
simonstratmann committed Mar 14, 2024
1 parent eeaf001 commit eeafea6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/skaffold/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,17 @@ func autoSyncItem(ctx context.Context, a *latest.Artifact, tag string, e filemon
}

func latestTag(image string, builds []graph.Artifact) string {
for _, build := range builds {
if build.ImageName == image {
return build.Tag
for _, _build := range builds {
if _build.ImageName == image {
return _build.Tag
}
}
return ""
}

func intersect(ctx context.Context, contextWd, containerWd string, syncRules []*latest.SyncRule, files []string) (syncMap, error) {
ret := make(syncMap)
hadMismatch := false
for _, f := range files {
relPath, err := filepath.Rel(contextWd, f)
if err != nil {
Expand All @@ -240,11 +241,15 @@ func intersect(ctx context.Context, contextWd, containerWd string, syncRules []*

if len(dsts) == 0 {
log.Entry(ctx).Infof("Changed file %s does not match any sync pattern. Skipping sync", relPath)
return nil, nil
hadMismatch = true
continue
}

ret[f] = dsts
}
if len(ret) == 0 && hadMismatch {
return nil, nil
}
return ret, nil
}

Expand Down
52 changes: 52 additions & 0 deletions pkg/skaffold/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,58 @@ func TestNewSyncItem(t *testing.T) {
Delete: map[string][]string{},
},
},
{
description: "manual: match copy partial match first",
artifact: &latest.Artifact{
ImageName: "test",
Sync: &latest.Sync{
Manual: []*latest.SyncRule{{Src: "*.html", Dest: "."}},
},
Workspace: ".",
},
builds: []graph.Artifact{
{
ImageName: "test",
Tag: "test:123",
},
},
evt: filemon.Events{
Added: []string{"someOtherFile.txt", "index.html"},
},
expected: &Item{
Image: "test:123",
Copy: map[string][]string{
"index.html": {"index.html"},
},
Delete: map[string][]string{},
},
},
{
description: "manual: match copy partial match last",
artifact: &latest.Artifact{
ImageName: "test",
Sync: &latest.Sync{
Manual: []*latest.SyncRule{{Src: "*.html", Dest: "."}},
},
Workspace: ".",
},
builds: []graph.Artifact{
{
ImageName: "test",
Tag: "test:123",
},
},
evt: filemon.Events{
Added: []string{"index.html", "someOtherFile.txt"},
},
expected: &Item{
Image: "test:123",
Copy: map[string][]string{
"index.html": {"index.html"},
},
Delete: map[string][]string{},
},
},
{
description: "manual: no tag for image",
artifact: &latest.Artifact{
Expand Down

0 comments on commit eeafea6

Please sign in to comment.