mirror of
https://github.com/thegeeklab/drone-yaml.git
synced 2024-11-21 17:40:39 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
72b626e584
@ -1,11 +1,11 @@
|
||||
// Copyright 2019 Drone IO, Inc.
|
||||
//
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
19
yaml/cond.go
19
yaml/cond.go
@ -18,15 +18,16 @@ import filepath "github.com/bmatcuk/doublestar"
|
||||
|
||||
// Conditions defines a group of conditions.
|
||||
type Conditions struct {
|
||||
Cron Condition `json:"cron,omitempty"`
|
||||
Ref Condition `json:"ref,omitempty"`
|
||||
Repo Condition `json:"repo,omitempty"`
|
||||
Instance Condition `json:"instance,omitempty"`
|
||||
Target Condition `json:"target,omitempty"`
|
||||
Event Condition `json:"event,omitempty"`
|
||||
Branch Condition `json:"branch,omitempty"`
|
||||
Status Condition `json:"status,omitempty"`
|
||||
Paths Condition `json:"paths,omitempty"`
|
||||
Cron Condition `json:"cron,omitempty"`
|
||||
Ref Condition `json:"ref,omitempty"`
|
||||
Repo Condition `json:"repo,omitempty"`
|
||||
Instance Condition `json:"instance,omitempty"`
|
||||
Target Condition `json:"target,omitempty"`
|
||||
Event Condition `json:"event,omitempty"`
|
||||
Branch Condition `json:"branch,omitempty"`
|
||||
Status Condition `json:"status,omitempty"`
|
||||
Paths Condition `json:"paths,omitempty"`
|
||||
Matrix map[string]string `json:"matrix,omitempty"`
|
||||
}
|
||||
|
||||
// Condition defines a runtime condition.
|
||||
|
@ -91,6 +91,40 @@ 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 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)
|
||||
|
||||
if err != nil {
|
||||
@ -180,6 +214,7 @@ func toConditions(from Constraints) droneyaml.Conditions {
|
||||
Include: from.Status.Include,
|
||||
Exclude: from.Status.Exclude,
|
||||
},
|
||||
Matrix: from.Matrix,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ type (
|
||||
Event Constraint
|
||||
Branch Constraint
|
||||
Status Constraint
|
||||
Matrix map[string]string
|
||||
}
|
||||
|
||||
// Constraint defines a runtime constraint.
|
||||
|
@ -1,11 +1,11 @@
|
||||
// Copyright 2019 Drone IO, Inc.
|
||||
//
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
13
yaml/env.go
13
yaml/env.go
@ -42,3 +42,16 @@ func (v *Variable) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
v.Secret = d.Secret
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalYAML implements yaml marshalling.
|
||||
func (v *Variable) MarshalYAML() (interface{}, error) {
|
||||
if v.Secret != "" {
|
||||
m := map[string]interface{}{}
|
||||
m["from_secret"] = v.Secret
|
||||
return m, nil
|
||||
}
|
||||
if v.Value != "" {
|
||||
return v.Value, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
// Copyright 2019 Drone IO, Inc.
|
||||
//
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@ -34,7 +34,7 @@ type (
|
||||
func (p *Parameter) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
d := new(parameter)
|
||||
err := unmarshal(d)
|
||||
if err == nil && d.Secret != ""{
|
||||
if err == nil && d.Secret != "" {
|
||||
p.Secret = d.Secret
|
||||
return nil
|
||||
}
|
||||
@ -43,3 +43,16 @@ func (p *Parameter) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
p.Value = i
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalYAML implements yaml marshalling.
|
||||
func (p *Parameter) MarshalYAML() (interface{}, error) {
|
||||
if p.Secret != "" {
|
||||
m := map[string]interface{}{}
|
||||
m["from_secret"] = p.Secret
|
||||
return m, nil
|
||||
}
|
||||
if p.Value != "" {
|
||||
return p.Value, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
// Copyright 2019 Drone IO, Inc.
|
||||
//
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -1,11 +1,11 @@
|
||||
// Copyright 2019 Drone IO, Inc.
|
||||
//
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -1,11 +1,11 @@
|
||||
// Copyright 2019 Drone IO, Inc.
|
||||
//
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -1,11 +1,11 @@
|
||||
// Copyright 2019 Drone IO, Inc.
|
||||
//
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -1,11 +1,11 @@
|
||||
// Copyright 2019 Drone IO, Inc.
|
||||
//
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
Loading…
Reference in New Issue
Block a user