Skip to content

Commit

Permalink
Update skip_path to new logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
lswith committed Nov 12, 2024
1 parent ee4e3de commit 19d5e09
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 16 deletions.
66 changes: 52 additions & 14 deletions pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,33 +109,71 @@ func stepsToTrigger(files []string, watch []WatchConfig) ([]Step, error) {
defaultStep = &w.Step
continue
}
for _, p := range w.Paths {
for _, f := range files {
match, err := matchPath(p, f)

skip := false
for _, sp := range w.SkipPaths {
skipMatch, errSkip := matchPath(sp, f)
match := false
skip := false
for _, f := range files {
for _, p := range w.Paths {

if errSkip != nil {
return nil, errSkip
}
m, err := matchPath(p, f)
if err != nil {
return nil, err
}

if skipMatch {
skip = true
}
if m {
log.Printf("matched: %s\n", f)
match = true
break
}
}

for _, sp := range w.SkipPaths {

sm, err := matchPath(sp, f)
if err != nil {
return nil, err
}

if match && !skip {
steps = append(steps, w.Step)
if sm {
log.Printf("skipped: %s\n", f)
skip = true
break
}
}
}

if match && !skip {
log.Printf("adding step: %s\n", w.Step.Trigger)
steps = append(steps, w.Step)
}

// for _, p := range w.Paths {
// for _, f := range files {
// match, err := matchPath(p, f)
//
// skip := false
// for _, sp := range w.SkipPaths {
// skipMatch, errSkip := matchPath(sp, f)
//
// if errSkip != nil {
// return nil, errSkip
// }
//
// if skipMatch {
// skip = true
// }
// }
//
// if err != nil {
// return nil, err
// }
//
// if match && !skip {
// steps = append(steps, w.Step)
// break
// }
// }
// }
}

if len(steps) == 0 && defaultStep != nil {
Expand Down
23 changes: 21 additions & 2 deletions pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func TestPipelinesStepsToTrigger(t *testing.T) {
{Trigger: "service-1"},
},
},
"step is included even when one of the files is skipped": {
"step is not included if one of the files is skipped": {
ChangedFiles: []string{
"docs/text.secret.txt",
"docs/text.txt",
Expand All @@ -356,7 +356,6 @@ func TestPipelinesStepsToTrigger(t *testing.T) {
}},
Expected: []Step{
{Trigger: "service-1"},
{Trigger: "service-2"},
},
},
"fails if not path is included": {
Expand All @@ -370,6 +369,26 @@ func TestPipelinesStepsToTrigger(t *testing.T) {
}},
Expected: []Step{},
},
"skips if one file matches": {
ChangedFiles: []string{
"docs/secret/secret.txt",
"docs/test/test.txt",
"docs/README.md",
},
WatchConfigs: []WatchConfig{
{
Paths: []string{"**/*"},
Step: Step{Trigger: "service-1"},
},
{
Paths: []string{"**/*"},
SkipPaths: []string{"docs/test/**/*"},
Step: Step{Trigger: "service-2"},
}},
Expected: []Step{
{Trigger: "service-1"},
},
},
}

for name, tc := range testCases {
Expand Down

0 comments on commit 19d5e09

Please sign in to comment.