From 4b9cc325ccfd1b55067aa37620b4e7991c5417f4 Mon Sep 17 00:00:00 2001 From: Luke Swithenbank Date: Tue, 12 Nov 2024 16:34:32 +1100 Subject: [PATCH] Update `skip_path` to new logic. --- pipeline.go | 60 ++++++++++++++++++++---------------------------- pipeline_test.go | 3 +-- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/pipeline.go b/pipeline.go index 70242ff..3ec2232 100644 --- a/pipeline.go +++ b/pipeline.go @@ -3,7 +3,6 @@ package main import ( "fmt" "os" - "reflect" "strings" "github.com/bmatcuk/doublestar/v2" @@ -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. @@ -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 { diff --git a/pipeline_test.go b/pipeline_test.go index cff0f6e..1cc2496 100644 --- a/pipeline_test.go +++ b/pipeline_test.go @@ -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", @@ -356,7 +356,6 @@ func TestPipelinesStepsToTrigger(t *testing.T) { }}, Expected: []Step{ {Trigger: "service-1"}, - {Trigger: "service-2"}, }, }, "fails if not path is included": {