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
|
|
|
|
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-08-09 13:33:10 +00:00
|
|
|
// fail hard on deprecated branch filter
|
2023-06-04 22:15:07 +00:00
|
|
|
if out.BranchesDontUseIt != nil {
|
2023-08-09 13:33:10 +00:00
|
|
|
return nil, fmt.Errorf("\"branches:\" filter got removed, use \"branch\" in global when filter")
|
2023-06-04 22:15:07 +00:00
|
|
|
}
|
|
|
|
|
2023-08-09 13:33:10 +00:00
|
|
|
// fail hard on deprecated pipeline keyword
|
|
|
|
if len(out.PipelineDontUseIt.ContainerList) != 0 {
|
|
|
|
return nil, fmt.Errorf("\"pipeline:\" got removed, user \"steps:\"")
|
2023-06-07 10:04:37 +00:00
|
|
|
}
|
|
|
|
|
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),
|
|
|
|
)
|
|
|
|
}
|