mirror of
https://github.com/thegeeklab/drone-yaml.git
synced 2024-11-22 01:50:40 +00:00
Check matrix conditions correctly
We are using matrix conditions heavily, and without that fix they are ignored and could lead to undefined variables. With this fix only matching matrix conditions are getting converted from the legacy format.
This commit is contained in:
parent
34c94916ef
commit
6c40ddf74e
@ -27,6 +27,7 @@ type Conditions struct {
|
|||||||
Branch Condition `json:"branch,omitempty"`
|
Branch Condition `json:"branch,omitempty"`
|
||||||
Status Condition `json:"status,omitempty"`
|
Status Condition `json:"status,omitempty"`
|
||||||
Paths Condition `json:"paths,omitempty"`
|
Paths Condition `json:"paths,omitempty"`
|
||||||
|
Matrix map[string]string `json:"matrix,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Condition defines a runtime condition.
|
// Condition defines a runtime condition.
|
||||||
|
@ -91,6 +91,40 @@ func Convert(d []byte) ([]byte, error) {
|
|||||||
current := pipeline
|
current := pipeline
|
||||||
current.Name = fmt.Sprintf("matrix-%d", index+1)
|
current.Name = fmt.Sprintf("matrix-%d", index+1)
|
||||||
|
|
||||||
|
services := make([]*droneyaml.Container, 0)
|
||||||
|
for _, service := range current.Services {
|
||||||
|
if len(service.When.Matrix) == 0 {
|
||||||
|
services = append(services, service)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for whenKey, whenValue := range service.When.Matrix {
|
||||||
|
for envKey, envValue := range environ {
|
||||||
|
if whenKey == envKey && whenValue == envValue {
|
||||||
|
services = append(services, service)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
current.Services = services
|
||||||
|
|
||||||
|
steps := make([]*droneyaml.Container, 0)
|
||||||
|
for _, step := range current.Steps {
|
||||||
|
if len(step.When.Matrix) == 0 {
|
||||||
|
steps = append(steps, step)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for whenKey, whenValue := range step.When.Matrix {
|
||||||
|
for envKey, envValue := range environ {
|
||||||
|
if whenKey == envKey && whenValue == envValue {
|
||||||
|
steps = append(steps, step)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
current.Steps = steps
|
||||||
|
|
||||||
marshaled, err := yaml.Marshal(¤t)
|
marshaled, err := yaml.Marshal(¤t)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -180,6 +214,7 @@ func toConditions(from Constraints) droneyaml.Conditions {
|
|||||||
Include: from.Status.Include,
|
Include: from.Status.Include,
|
||||||
Exclude: from.Status.Exclude,
|
Exclude: from.Status.Exclude,
|
||||||
},
|
},
|
||||||
|
Matrix: from.Matrix,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ type (
|
|||||||
Event Constraint
|
Event Constraint
|
||||||
Branch Constraint
|
Branch Constraint
|
||||||
Status Constraint
|
Status Constraint
|
||||||
|
Matrix map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constraint defines a runtime constraint.
|
// Constraint defines a runtime constraint.
|
||||||
|
Loading…
Reference in New Issue
Block a user