Skip to content

Instantly share code, notes, and snippets.

@tboerger
Last active April 24, 2019 14:04
Show Gist options
  • Select an option

  • Save tboerger/007ebd70c8c677a61fae609a35875e5b to your computer and use it in GitHub Desktop.

Select an option

Save tboerger/007ebd70c8c677a61fae609a35875e5b to your computer and use it in GitHub Desktop.
diff --git a/vendor/github.com/drone/drone-yaml/yaml/converter/legacy/internal/config.go b/vendor/github.com/drone/drone-yaml/yaml/converter/legacy/internal/config.go
index 14a9070..84e1f0a 100644
--- a/vendor/github.com/drone/drone-yaml/yaml/converter/legacy/internal/config.go
+++ b/vendor/github.com/drone/drone-yaml/yaml/converter/legacy/internal/config.go
@@ -91,6 +91,60 @@ func Convert(d []byte) ([]byte, error) {
current := pipeline
current.Name = fmt.Sprintf("matrix-%d", index+1)
+ services := make([]*droneyaml.Container, 0)
+ for _, service := range current.Services {
+ if service == nil {
+ continue
+ }
+
+ if len(service.When.Matrix) == 0 {
+ services = append(services, service)
+ continue
+ }
+
+ keep := false
+
+ for whenKey, whenValue := range service.When.Matrix {
+ for envKey, envValue := range environ {
+ if whenKey == envKey && whenValue == envValue {
+ keep = true
+ }
+ }
+ }
+
+ if keep {
+ services = append(services, service)
+ }
+ }
+ current.Services = services
+
+ steps := make([]*droneyaml.Container, 0)
+ for _, step := range current.Steps {
+ if step == nil {
+ continue
+ }
+
+ if len(step.When.Matrix) == 0 {
+ steps = append(steps, step)
+ continue
+ }
+
+ keep := false
+
+ for whenKey, whenValue := range step.When.Matrix {
+ for envKey, envValue := range environ {
+ if whenKey == envKey && whenValue == envValue {
+ keep = true
+ }
+ }
+ }
+
+ if keep {
+ steps = append(steps, step)
+ }
+ }
+ current.Steps = steps
+
marshaled, err := yaml.Marshal(&current)
if err != nil {
@@ -180,6 +234,7 @@ func toConditions(from Constraints) droneyaml.Conditions {
Include: from.Status.Include,
Exclude: from.Status.Exclude,
},
+ Matrix: from.Matrix,
}
}
diff --git a/vendor/github.com/drone/drone-yaml/yaml/converter/legacy/internal/constraint.go b/vendor/github.com/drone/drone-yaml/yaml/converter/legacy/internal/constraint.go
index 8131a17..518db2a 100644
--- a/vendor/github.com/drone/drone-yaml/yaml/converter/legacy/internal/constraint.go
+++ b/vendor/github.com/drone/drone-yaml/yaml/converter/legacy/internal/constraint.go
@@ -14,6 +14,7 @@ type (
Event Constraint
Branch Constraint
Status Constraint
+ Matrix map[string]string
}
// Constraint defines a runtime constraint.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment