Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(container): skip "label" rule evaluation in container execution #380

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions pipeline/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
86 changes: 86 additions & 0 deletions pipeline/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading