This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
/
types.go
137 lines (107 loc) · 3.14 KB
/
types.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package config
import (
"context"
"github.com/wavesoftware/go-magetasks/pkg/version"
)
// Config holds configuration information.
type Config struct {
// ProjectDir holds a path to the project.
ProjectDir string
// BuildDirPath holds a build directory path.
BuildDirPath []string
// Version contains the version information.
*Version
// Dependencies will hold additional Golang and pre-compiled dependencies
// that needs to be installed before running tasks.
Dependencies struct {
Golang Dependencies
Binaries
}
// Artifacts holds a list of artifacts to be built.
Artifacts []Artifact
// Builders holds a list of Builder's to be used for building project
// artifacts. If none is configured, default ones will be used.
Builders []Builder
// Publishers holds a list of Publisher's to be used for publishing project
// artifacts. If none is configured, default ones will be used.
Publishers []Publisher
// Cleaning additional cleaning tasks.
Cleaning []Task
// Checks holds a list of checks to perform.
Checks []Task
// BuildVariables holds extra list of variables to be passed to Golang's
// ldflags.
BuildVariables
// Overrides holds a list of overrides of this configuration.
Overrides []Configurator
// context.Context is standard Golang context.
context.Context //nolint:containedctx
}
// Notifier can notify of a pending status of long task.
type Notifier interface {
Notify(status string)
}
// Builder builds an artifact.
type Builder interface {
Accepts(artifact Artifact) bool
Build(artifact Artifact, notifier Notifier) Result
}
// Publisher publishes artifacts to a remote site.
type Publisher interface {
Accepts(artifact Artifact) bool
Publish(artifact Artifact, notifier Notifier) Result
}
// Resolver is a func that resolves to a string.
type Resolver func() string
// StaticResolver can be used to create a Resolver from static data.
func StaticResolver(value string) Resolver {
return func() string {
return value
}
}
// Result hold a result of an Artifact build or publish.
type Result struct {
Error error
Info map[string]interface{}
}
// Failed returns true if the artifact processing failed.
func (r Result) Failed() bool {
return r.Error != nil
}
// Artifact represents a thing that can be built and published.
type Artifact interface {
GetType() string
GetName() string
}
// ResultKey is used to store results of a build or publish.
type ResultKey string
// Version specifies the version information and how to set it into variable at
// compile time.
type Version struct {
Path string
version.Resolver
}
// Metadata holds additional contextual information.
type Metadata struct {
Name string
BuildVariables
}
func (m Metadata) GetName() string {
return m.Name
}
// Task is a custom function that will be used in the build.
type Task struct {
Name string
Operation func(Notifier) error
Overrides []Configurator
}
// Configurator will configure project.
type Configurator interface {
Configure(cfg Configurable)
}
// Configurable will allow changes of the Config structure.
type Configurable interface {
Config() *Config
}
// Configured represents a configured project.
type Configured interface{}