-
Notifications
You must be signed in to change notification settings - Fork 1
/
pipeline.go
52 lines (44 loc) · 1.07 KB
/
pipeline.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
package ci
import "strings"
// Pipelines defines a collection of pipelines
type Pipelines []*Pipeline
// Pipeline defines a single execution tree
type Pipeline struct {
Name string
Desc string
Steps []Step
}
// Stage defines a set of steps to be executed
type Stage struct {
Name string
Parallel bool
Steps []Step
}
// Step defines an operation that is done in the execution tree
type Step interface {
// Setup creates the necessary subtasks
Setup(parent *Task)
}
// Find finds a named pipeline.
func (pipelines Pipelines) Find(name string) (*Pipeline, bool) {
for _, pipeline := range pipelines {
if strings.EqualFold(pipeline.Name, name) {
return pipeline, true
}
}
return nil, false
}
// Task creates a root task from a pipeline
func (pipeline *Pipeline) Task() *Task {
task := &Task{}
task.Name = pipeline.Name
task.Desc = pipeline.Desc
task.AddSteps(pipeline.Steps)
return task
}
// Setup sets up the step
func (stage *Stage) Setup(parent *Task) {
task := parent.Subtask(stage.Name)
task.Parallel = stage.Parallel
task.AddSteps(stage.Steps)
}