Skip to content

Commit

Permalink
fix: skip path rule for container.Execute() (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockopp authored Aug 24, 2020
1 parent 5218860 commit 8988a28
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pipeline/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ func (c *Container) Execute(r *RuleData) bool {
// treat the ruleset status as success
r.Status = constants.StatusSuccess

// 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
//
// 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
c.Ruleset.If.Path = []string{}
c.Ruleset.Unless.Path = []string{}

// return if the container ruleset matches the conditions
return c.Ruleset.Match(r)
}
Expand Down
63 changes: 63 additions & 0 deletions pipeline/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,69 @@ func TestPipeline_Container_Execute(t *testing.T) {
},
want: false,
},
{ // branch/event/path container with build running
container: &Container{
Name: "branch/event/path-running",
Image: "alpine:latest",
Commands: []string{"echo \"Hey Vela\""},
Ruleset: Ruleset{
If: Rules{
Branch: []string{"master"},
Event: []string{constants.EventPush},
Path: []string{"README.md"},
},
},
},
ruleData: &RuleData{
Branch: "master",
Event: "push",
Repo: "foo/bar",
Status: "running",
},
want: true,
},
{ // branch/event/path container with build success
container: &Container{
Name: "branch/event/path-success",
Image: "alpine:latest",
Commands: []string{"echo \"Hey Vela\""},
Ruleset: Ruleset{
If: Rules{
Branch: []string{"master"},
Event: []string{constants.EventPush},
Path: []string{"README.md"},
},
},
},
ruleData: &RuleData{
Branch: "master",
Event: "push",
Repo: "foo/bar",
Status: "success",
},
want: true,
},
{ // branch/event/path container with build failure
container: &Container{
Name: "branch/event/path-failure",
Image: "alpine:latest",
Commands: []string{"echo \"Hey Vela\""},
Ruleset: Ruleset{
If: Rules{
Branch: []string{"master"},
Event: []string{constants.EventPush},
Path: []string{"README.md"},
},
},
},
ruleData: &RuleData{
Branch: "master",
Event: "push",
Repo: "foo/bar",
Status: "failure",
},
want: false,
},
{ // branch/event/status container with build running
container: &Container{
Name: "branch/event/status-running",
Expand Down

0 comments on commit 8988a28

Please sign in to comment.