-
Notifications
You must be signed in to change notification settings - Fork 1
/
schema.go
122 lines (96 loc) · 1.96 KB
/
schema.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package zbaction
import (
"context"
"fmt"
"strings"
"github.com/mitchellh/hashstructure/v2"
)
type MachineName = string
type ProcStepName = string
type ProcStepArgs = map[string]string
type ActionID = string
type JobID = string
type StepID = string
type Action struct {
ID ActionID
Variables map[string]string
Jobs []Job
Requirements []Requirement
Metadata map[string]string
}
func (a Action) String() string {
if a.ID != "" {
return a.ID
}
uuid, err := hashstructure.Hash(a, hashstructure.FormatV2, nil)
if err == nil {
return fmt.Sprintf("%x", uuid)
}
return "<unknown action>"
}
type Requirement struct {
Expr string
Description *string
}
func (r Requirement) String() string {
sb := strings.Builder{}
sb.WriteString(r.Expr)
if r.Description != nil {
sb.WriteString(" (")
sb.WriteString(*r.Description)
sb.WriteString(")")
}
return sb.String()
}
type Job struct {
ID JobID
Variables map[string]string
Steps []Step
}
func (j Job) String() string {
if j.ID != "" {
return j.ID
}
uuid, err := hashstructure.Hash(j, hashstructure.FormatV2, nil)
if err == nil {
return fmt.Sprintf("%x", uuid)
}
return "<unknown job>"
}
type Step struct {
ID StepID
Name string
Variables map[string]string
RunnableStep
}
func (s Step) HumanName() string {
if s.Name != "" {
return s.Name
}
return s.String()
}
func (s Step) String() string {
if s.ID != "" {
return s.ID
}
uuid, err := hashstructure.Hash(s, hashstructure.FormatV2, nil)
if err == nil {
return fmt.Sprintf("%x", uuid)
}
return "<unknown step>"
}
type RunnableStep interface {
Run(ctx context.Context, sc *StepContext) (CleanupFn, error)
}
type ProcStep struct {
Uses ProcStepName
With ProcStepArgs
}
func (p ProcStep) Run(ctx context.Context, sc *StepContext) (CleanupFn, error) {
step, err := ResolveProcedure(p.Uses, p.With)
if err != nil {
return nil, err
}
return step.Run(ctx, sc)
}
type CleanupFn func()