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 4b9cc32
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 37 deletions.
60 changes: 25 additions & 35 deletions pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"reflect"
"strings"

"github.com/bmatcuk/doublestar/v2"
Expand Down Expand Up @@ -109,40 +108,50 @@ 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)
}
}

if len(steps) == 0 && defaultStep != nil {
steps = append(steps, *defaultStep)
}

return dedupSteps(steps), nil
return steps, nil
}

// matchPath checks if the file f matches the path p.
Expand All @@ -165,25 +174,6 @@ func matchPath(p string, f string) (bool, error) {
return false, nil
}

func dedupSteps(steps []Step) []Step {
unique := []Step{}
for _, p := range steps {
duplicate := false
for _, t := range unique {
if reflect.DeepEqual(p, t) {
duplicate = true
break
}
}

if !duplicate {
unique = append(unique, p)
}
}

return unique
}

func generatePipeline(steps []Step, plugin Plugin) (*os.File, bool, error) {
tmp, err := os.CreateTemp(os.TempDir(), "bmrd-")
if err != nil {
Expand Down
3 changes: 1 addition & 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 Down

0 comments on commit 4b9cc32

Please sign in to comment.