2017-03-05 18:56:08 +11:00
|
|
|
package yaml
|
|
|
|
|
|
|
|
import (
|
2023-06-05 00:15:07 +02:00
|
|
|
"fmt"
|
|
|
|
|
2023-04-29 14:49:41 +02:00
|
|
|
"codeberg.org/6543/xyaml"
|
2023-06-05 00:15:07 +02:00
|
|
|
|
2022-01-17 14:43:30 +01:00
|
|
|
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/constraint"
|
2021-10-30 17:52:02 +02:00
|
|
|
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types"
|
2017-03-05 18:56:08 +11:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// Config defines a pipeline configuration.
|
|
|
|
Config struct {
|
2022-09-26 03:27:20 -04:00
|
|
|
When constraint.When `yaml:"when,omitempty"`
|
2023-02-02 00:08:02 +01:00
|
|
|
Cache types.StringOrSlice
|
2017-03-05 18:56:08 +11:00
|
|
|
Platform string
|
|
|
|
Workspace Workspace
|
|
|
|
Clone Containers
|
|
|
|
Pipeline Containers
|
|
|
|
Services Containers
|
|
|
|
Networks Networks
|
|
|
|
Volumes Volumes
|
2021-10-30 17:52:02 +02:00
|
|
|
Labels types.SliceorMap
|
2019-06-12 11:03:59 +02:00
|
|
|
DependsOn []string `yaml:"depends_on,omitempty"`
|
2019-06-17 09:06:36 +02:00
|
|
|
RunsOn []string `yaml:"runs_on,omitempty"`
|
2019-06-24 11:19:12 +02:00
|
|
|
SkipClone bool `yaml:"skip_clone"`
|
2022-09-26 03:27:20 -04:00
|
|
|
// Deprecated use When.Branch
|
2023-06-05 00:15:07 +02:00
|
|
|
BranchesDontUseIt *constraint.List `yaml:"branches,omitempty"`
|
2017-03-05 18:56:08 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
// Workspace defines a pipeline workspace.
|
|
|
|
Workspace struct {
|
|
|
|
Base string
|
|
|
|
Path string
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// ParseBytes parses the configuration from bytes b.
|
|
|
|
func ParseBytes(b []byte) (*Config, error) {
|
|
|
|
out := new(Config)
|
2023-04-29 14:49:41 +02:00
|
|
|
err := xyaml.Unmarshal(b, out)
|
2017-03-05 18:56:08 +11:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-06-05 00:15:07 +02: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
|
|
|
|
}
|
|
|
|
|
2017-03-05 18:56:08 +11:00
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseString parses the configuration from string s.
|
|
|
|
func ParseString(s string) (*Config, error) {
|
|
|
|
return ParseBytes(
|
|
|
|
[]byte(s),
|
|
|
|
)
|
|
|
|
}
|