From 3bb0f64025b574e1f7ea23256996360b522abd5c Mon Sep 17 00:00:00 2001 From: Laszlo Fogas Date: Mon, 22 Jul 2019 14:29:15 +0200 Subject: [PATCH] Handling zero-steps as transitive dependencies --- server/procBuilder.go | 3 ++- server/procBuilder_test.go | 52 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/server/procBuilder.go b/server/procBuilder.go index d96343c95a6..a31a2f711b9 100644 --- a/server/procBuilder.go +++ b/server/procBuilder.go @@ -156,7 +156,8 @@ func filterItemsWithMissingDependencies(items []*buildItem) []*buildItem { filtered = append(filtered, item) } } - return filtered + // Recursive to handle transitive deps + return filterItemsWithMissingDependencies(filtered) } return items diff --git a/server/procBuilder_test.go b/server/procBuilder_test.go index d5368bb1a0a..904a7204b78 100644 --- a/server/procBuilder_test.go +++ b/server/procBuilder_test.go @@ -288,6 +288,58 @@ depends_on: [ zerostep ] } } +func TestZeroStepsAsMultiPipelineTransitiveDeps(t *testing.T) { + build := &model.Build{Branch: "dev"} + + b := procBuilder{ + Repo: &model.Repo{}, + Curr: build, + Last: &model.Build{}, + Netrc: &model.Netrc{}, + Secs: []*model.Secret{}, + Regs: []*model.Registry{}, + Link: "", + Yamls: []*remote.FileMeta{ + &remote.FileMeta{Name: "zerostep", Data: []byte(` +skip_clone: true +pipeline: + build: + when: + branch: notdev + image: scratch +`)}, + &remote.FileMeta{Name: "justastep", Data: []byte(` +pipeline: + build: + image: scratch +`)}, + &remote.FileMeta{Name: "shouldbefiltered", Data: []byte(` +pipeline: + build: + image: scratch +depends_on: [ zerostep ] +`)}, + &remote.FileMeta{Name: "shouldbefilteredtoo", Data: []byte(` +pipeline: + build: + image: scratch +depends_on: [ shouldbefiltered ] +`)}, + }, + } + + buildItems, err := b.Build() + if err != nil { + t.Fatal(err) + } + if len(buildItems) != 1 { + t.Fatal("Zerostep and the step that depends on it, and the one depending on it should not generate a build item") + } + if "justastep" != buildItems[0].Proc.Name { + t.Fatal("justastep should have been generated") + } +} + func TestTree(t *testing.T) { build := &model.Build{}