2017-03-05 07:56:08 +00:00
|
|
|
package yaml
|
|
|
|
|
|
|
|
import (
|
2023-06-04 22:15:07 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-04-29 12:49:41 +00:00
|
|
|
"codeberg.org/6543/xyaml"
|
2023-06-04 22:15:07 +00:00
|
|
|
|
2022-01-17 13:43:30 +00:00
|
|
|
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/constraint"
|
2021-10-30 15:52:02 +00:00
|
|
|
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types"
|
2017-03-05 07:56:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ParseBytes parses the configuration from bytes b.
|
2023-06-06 07:14:21 +00:00
|
|
|
func ParseBytes(b []byte) (*types.Workflow, error) {
|
|
|
|
out := new(types.Workflow)
|
2023-04-29 12:49:41 +00:00
|
|
|
err := xyaml.Unmarshal(b, out)
|
2017-03-05 07:56:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-06-04 22:15:07 +00:00
|
|
|
// support deprecated branch filter
|
|
|
|
if out.BranchesDontUseIt != nil {
|
|
|
|
if out.When.Constraints == nil {
|
|
|
|
out.When.Constraints = []constraint.Constraint{{Branch: *out.BranchesDontUseIt}}
|
|
|
|
} else if len(out.When.Constraints) == 1 && out.When.Constraints[0].Branch.IsEmpty() {
|
|
|
|
out.When.Constraints[0].Branch = *out.BranchesDontUseIt
|
|
|
|
} else {
|
|
|
|
return nil, fmt.Errorf("could not apply deprecated branches filter into global when filter")
|
|
|
|
}
|
|
|
|
out.BranchesDontUseIt = nil
|
|
|
|
}
|
|
|
|
|
2023-06-07 10:04:37 +00:00
|
|
|
// support deprecated pipeline keyword
|
|
|
|
if len(out.PipelineDontUseIt.ContainerList) != 0 && len(out.Steps.ContainerList) == 0 {
|
|
|
|
out.Steps.ContainerList = out.PipelineDontUseIt.ContainerList
|
|
|
|
}
|
|
|
|
out.PipelineDontUseIt.ContainerList = nil
|
|
|
|
|
2017-03-05 07:56:08 +00:00
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseString parses the configuration from string s.
|
2023-06-06 07:14:21 +00:00
|
|
|
func ParseString(s string) (*types.Workflow, error) {
|
2017-03-05 07:56:08 +00:00
|
|
|
return ParseBytes(
|
|
|
|
[]byte(s),
|
|
|
|
)
|
|
|
|
}
|