forked from simplesurance/baur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task.go
64 lines (53 loc) · 1.44 KB
/
task.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
package baur
import (
"fmt"
"sort"
"github.com/simplesurance/baur/v1/cfg"
)
// Task is a an execution step belonging to an app.
// A task has a set of Inputs that produce a set of outputs by executing it's
// Command.
type Task struct {
RepositoryRoot string
Directory string
AppName string
Name string
Command []string
UnresolvedInputs *cfg.Input
Outputs *cfg.Output
CfgFilepaths []string
}
// NewTask returns a new Task.
func NewTask(cfg *cfg.Task, appName, repositoryRootdir, workingDir string) *Task {
return &Task{
RepositoryRoot: repositoryRootdir,
Directory: workingDir,
Outputs: &cfg.Output,
CfgFilepaths: cfg.Filepaths(),
Command: cfg.Command,
Name: cfg.Name,
AppName: appName,
UnresolvedInputs: &cfg.Input,
}
}
// ID returns <APP-NAME>.<TASK-NAME>
func (t *Task) ID() string {
return fmt.Sprintf("%s.%s", t.AppName, t.Name)
}
// String returns ID()
func (t *Task) String() string {
return t.ID()
}
// HasInputs returns true if Inputs are defined for the task
func (t *Task) HasInputs() bool {
return !cfg.InputsAreEmpty(t.UnresolvedInputs)
}
// HasOutputs returns true if outputs are defined for the task
func (t *Task) HasOutputs() bool {
return len(t.Outputs.DockerImage) > 0 || len(t.Outputs.File) > 0
}
func SortTasksByID(tasks []*Task) {
sort.Slice(tasks, func(i int, j int) bool {
return tasks[i].ID() < tasks[j].ID()
})
}