mirrored from https://chromium.googlesource.com/infra/luci/luci-go
/
edit.go
178 lines (148 loc) · 5.54 KB
/
edit.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Copyright 2020 The LUCI Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package job
import (
bbpb "go.chromium.org/luci/buildbucket/proto"
"go.chromium.org/luci/common/errors"
)
// Editor represents low-level mutations you can make on a job.Definition.
//
// You may edit a job.Definition by calling its Edit method.
type Editor interface {
// ClearCurrentIsolated removes all isolateds from this Definition.
ClearCurrentIsolated()
// ClearDimensions removes all dimensions.
ClearDimensions()
// SetDimensions sets the full set of dimensions.
SetDimensions(dims ExpiringDimensions)
// EditDimensions edits the swarming dimensions.
EditDimensions(dimEdits DimensionEditCommands)
// CIPDPkgs allows you to edit the cipd packages. The mapping is in the form
// of:
//
// "subdir:name/of/package" -> "version"
//
// If version is empty, this package will be removed (if it's present).
CIPDPkgs(cipdPkgs CIPDPkgs)
// Env edits the swarming environment variables (i.e. those set before the
// user payload runs).
//
// The map given is a map of environment variable to its value; If the value
// is "", then the environment variable is removed.
Env(env map[string]string)
// PrefixPathEnv controls swarming's env_prefix mapping for $PATH.
//
// Values prepended with '!' will remove them from the existing list of values
// (if present). Otherwise these values will be appended to the current list
// of PATH-prefix-envs.
PrefixPathEnv(values []string)
// Priority edits the swarming task priority.
Priority(priority int32)
// SwarmingHostname allows you to modify the current SwarmingHostname used by
// this led pipeline.
SwarmingHostname(host string)
// TaskName allows you to set the swarming task name of the job.
TaskName(name string)
// Tags appends the given values to the task's tags.
Tags(values []string)
}
// HighLevelEditor represents high-level mutations you can make on
// a job.Definition.
//
// Currently only Buildbucket job.Definitions support high level edits.
//
// You may edit a job.Definition by calling its HighLevelEdit method.
type HighLevelEditor interface {
Editor
// Experimental sets the task to either be marked 'experimental' or not.
Experimental(isExperimental bool)
// Experiments enables or disables experiments.
//
// If `exps[<name>]` is true, the corresponding experiment will be enabled.
// If it is false, the experiment will be disabled (if it was enabled).
//
// Experiments enabled in the build, but not mentioned in `exps` map are left
// enabled.
Experiments(exps map[string]bool)
// Properties edits the recipe properties.
//
// `props` should be a mapping of the top-level property to JSON-encoded data
// for the value of this property. If the value is "", then the top-level
// property will be deleted.
//
// If `auto` is true, then values which do not decode as JSON will be treated
// as literal strings. For example, given a value `literal string` with
// auto=true, this would be equivalent to passing the value `"literal string"`
// with auto=false.
Properties(props map[string]string, auto bool)
// TaskPayloadSource sets the task payload to either use the provided CIPD
// package and version, or the UserPayload if they are empty.
//
// If cipdPkg is specified without cipdVers, cipdVers will be set to "latest".
TaskPayloadSource(cipdPkg, cipdVers string)
// TaskPayloadPath sets the location of where bbagent should locate the task
// payload data within the task.
TaskPayloadPath(path string)
// TaskPayloadCmd sets the arguments used to run the task payload.
//
// args[0] is the path, relative to the payload path, of the executable to
// run.
//
// NOTE: Kitchen tasks ignore this value.
TaskPayloadCmd(args []string)
// ClearGerritChanges removes all GerritChanges from the job.
ClearGerritChanges()
// AddGerritChange ensures the GerritChange is in the set of input CLs.
AddGerritChange(cl *bbpb.GerritChange)
// RemoveGerritChange ensures the GerritChange is not in the set of input CLs.
RemoveGerritChange(cl *bbpb.GerritChange)
// GitilesCommit sets the GitilesCommit.
//
// If `commit` is nil, removes the commit.
GitilesCommit(commit *bbpb.GitilesCommit)
}
// Edit runs a mutator function with an Editor.
//
// If one of the edit operations has an error, further method calls on the
// Editor are ignored and this returns the error.
func (jd *Definition) Edit(cb func(m Editor)) error {
var m interface {
Editor
Close() error
}
if jd.GetBuildbucket() != nil {
m = newBuildbucketEditor(jd)
} else {
m = newSwarmingEditor(jd)
}
cb(m)
return m.Close()
}
// HighLevelEdit runs a mutator function with a HighLevelEditor.
//
// If one of the edit operations has an error, further method calls on the
// HighLevelEditor are ignored and this returns the error.
func (jd *Definition) HighLevelEdit(cb func(m HighLevelEditor)) error {
var m interface {
HighLevelEditor
Close() error
}
if jd.GetBuildbucket() != nil {
m = newBuildbucketEditor(jd)
} else {
return errors.New("job.HighLevelEdit not supported for this Job")
}
cb(m)
return m.Close()
}