-
Notifications
You must be signed in to change notification settings - Fork 2
/
step_group.go
60 lines (49 loc) · 1.64 KB
/
step_group.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package pipeline
import (
"fmt"
"github.com/buildkite/go-pipeline/ordered"
)
// GroupStep models a group step.
//
// Standard caveats apply - see the package comment.
type GroupStep struct {
// Fields common to various step types
Key string `yaml:"key,omitempty" aliases:"id,identifier"`
// Group must always exist in a group step (so that we know it is a group).
// If it has a value, it is treated as equivalent to the label or name.
Group *string `yaml:"group" aliases:"label,name"`
Steps Steps `yaml:"steps"`
// RemainingFields stores any other top-level mapping items so they at least
// survive an unmarshal-marshal round-trip.
RemainingFields map[string]any `yaml:",inline"`
}
// UnmarshalOrdered unmarshals a group step from an ordered map.
func (g *GroupStep) UnmarshalOrdered(src any) error {
type wrappedGroup GroupStep
if err := ordered.Unmarshal(src, (*wrappedGroup)(g)); err != nil {
return fmt.Errorf("unmarshalling GroupStep: %w", err)
}
// Ensure Steps is never nil. Server side expects a sequence.
if g.Steps == nil {
g.Steps = Steps{}
}
return nil
}
func (g *GroupStep) interpolate(tf stringTransformer) error {
if err := interpolateString(tf, &g.Key); err != nil {
return err
}
if err := interpolateString(tf, g.Group); err != nil {
return err
}
if err := g.Steps.interpolate(tf); err != nil {
return err
}
return interpolateMap(tf, g.RemainingFields)
}
func (GroupStep) stepTag() {}
// MarshalJSON marshals the step to JSON. Special handling is needed because
// yaml.v3 has "inline" but encoding/json has no concept of it.
func (g *GroupStep) MarshalJSON() ([]byte, error) {
return inlineFriendlyMarshalJSON(g)
}