From aef0237fc5c495bf20fb2a038e0fd9c10100ded0 Mon Sep 17 00:00:00 2001 From: wsan3 Date: Thu, 13 Jun 2024 16:35:27 -0500 Subject: [PATCH 1/2] Skip label rule evaluation in container exectution --- pipeline/container.go | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/pipeline/container.go b/pipeline/container.go index 3d427cb0..8e2e55f1 100644 --- a/pipeline/container.go +++ b/pipeline/container.go @@ -152,32 +152,21 @@ func (c *Container) Execute(r *RuleData) (bool, error) { if c == nil { return false, nil } - // skip evaluating path in ruleset - // - // the compiler is the component responsible for - // choosing whether a container will run based - // off the files changed for a build + + // Skip evaluating path, comment, and label in ruleset, + // as the worker lacks necessary rule data. // - // the worker doesn't have any record of - // what files changed for a build so we - // should "skip" evaluating what the - // user provided for the path element + // The compiler determines whether a container will run based on + // these rules. c.Ruleset.If.Path = []string{} c.Ruleset.Unless.Path = []string{} - // skip evaluating comment in ruleset - // - // the compiler is the component responsible for - // choosing whether a container will run based - // off the PR comment matching the pipeline comment - // - // the worker doesn't have any record of - // the PR comment so we - // should "skip" evaluating what the - // user provided for the PR comment c.Ruleset.If.Comment = []string{} c.Ruleset.Unless.Comment = []string{} + c.Ruleset.If.Label = []string{} + c.Ruleset.Unless.Label = []string{} + // check if the build is in a running state if strings.EqualFold(r.Status, constants.StatusRunning) { // treat the ruleset status as success From 0811f1fba47f0e7a953b3771f3c86929dbf011e8 Mon Sep 17 00:00:00 2001 From: wsan3 Date: Fri, 14 Jun 2024 09:51:33 -0500 Subject: [PATCH 2/2] Add skip label evaluation tests --- pipeline/container_test.go | 86 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/pipeline/container_test.go b/pipeline/container_test.go index 3f5e3a45..a7ae573c 100644 --- a/pipeline/container_test.go +++ b/pipeline/container_test.go @@ -749,6 +749,92 @@ func TestPipeline_Container_Execute(t *testing.T) { }, want: true, }, + { // pull request labeled success container with build success + container: &Container{ + Name: "pull-request-labeled", + Image: "alpine:latest", + Commands: []string{"echo \"Hey Vela\""}, + Ruleset: Ruleset{ + If: Rules{ + Branch: []string{"fix/1234"}, + Event: []string{constants.EventPull + constants.ActionLabeled}, + Label: []string{"enhancement", "documentation"}, + }, + Operator: "and", + }, + }, + ruleData: &RuleData{ + Branch: "fix/1234", + Event: "pull_request:labeled", + Repo: "foo/bar", + Status: "success", + }, + want: true, + }, + { // pull request unlabeled success container with build success + container: &Container{ + Name: "pull-request-unlabeled", + Image: "alpine:latest", + Commands: []string{"echo \"Hey Vela\""}, + Ruleset: Ruleset{ + If: Rules{ + Event: []string{constants.EventPull + constants.ActionUnlabeled}, + Label: []string{"enhancement"}, + }, + Operator: "and", + }, + }, + ruleData: &RuleData{ + Branch: "fix/1234", + Event: "pull_request:unlabeled", + Repo: "foo/bar", + Status: "success", + }, + want: true, + }, + { // pull request labeled unless ruleset, success container with build success + container: &Container{ + Name: "pull-request-labeled", + Image: "alpine:latest", + Commands: []string{"echo \"Hey Vela\""}, + Ruleset: Ruleset{ + Unless: Rules{ + Branch: []string{"fix/1234"}, + Event: []string{constants.EventPull + constants.ActionLabeled}, + Label: []string{"enhancement", "documentation"}, + }, + Operator: "and", + }, + }, + ruleData: &RuleData{ + Branch: "fix/1234", + Event: "pull_request:labeled", + Repo: "foo/bar", + Status: "success", + }, + want: true, + }, + { // pull request unlabeled unless ruleset, success container with build success + container: &Container{ + Name: "pull-request-unlabeled", + Image: "alpine:latest", + Commands: []string{"echo \"Hey Vela\""}, + Ruleset: Ruleset{ + Unless: Rules{ + Event: []string{constants.EventPull + constants.ActionUnlabeled}, + Label: []string{"enhancement"}, + }, + Operator: "and", + }, + }, + ruleData: &RuleData{ + Branch: "fix/1234", + Event: "pull_request:unlabeled", + Repo: "foo/bar", + Status: "success", + }, + want: true, + }, } // run tests