-
Notifications
You must be signed in to change notification settings - Fork 23
/
master.cfg
196 lines (161 loc) · 5.12 KB
/
master.cfg
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# first, reload each module by name
import random
from datetime import timedelta
from metabbotcfg import reporters
from metabbotcfg import workers
from metabbotcfg import www
from buildbot.config import BuilderConfig
from buildbot.plugins import schedulers
from buildbot.plugins import steps
from buildbot.plugins import util
from buildbot.process import factory
from buildbot.schedulers.forcesched import CodebaseParameter
from buildbot.schedulers.triggerable import Triggerable
c = BuildmasterConfig = {
'workers': workers.workers,
'services': [],
'protocols': {"pb": {"port": 9989}},
'builders': [],
'schedulers': [],
'multiMaster': True,
'codebaseGenerator': lambda chdict: chdict['project'],
'title': 'Buildbot',
'titleURL': 'http://buildbot.net/',
'buildbotNetUsageData': None,
}
branches = ["master"]
reporters.setup_reporters(c)
def setup_git_step(f, name, repository):
f.addStep(
steps.GitHub(
repourl=repository,
codebase=name,
haltOnFailure=True,
flunkOnFailure=True,
getDescription={"tags": True, "always": True},
mode="full",
method="copy",
retryFetch=True,
retry=(2, 10),
)
)
def get_all_workers(c):
return [w.workername for w in c["workers"]]
def get_spawner_workers(c):
workers = [w.workername for w in c["workers"] if "local" in w.workername]
if not workers:
return get_all_workers()
return workers
def get_runner_workers(c):
workers = [
w.workername for w in c["workers"] if "kube" in w.workername or "p12" in w.workername
]
if not workers:
return get_all_workers()
return workers
def define_builders(c):
name = "buildbot"
repository = "https://github.com/buildbot/buildbot"
job_name = f"{name}-job"
try_name = f"{name}-try"
spawner_name = name
def uniq(tags):
"""tags needs to be unique list, so we need to filter them into a set"""
return list(set(tags))
tags = []
codebases = {spawner_name: {"repository": repository}}
# main job
f = factory.BuildFactory()
setup_git_step(f, name, repository)
f.addStep(steps.BuildbotCiSetupSteps())
c["builders"].append(
BuilderConfig(
name=job_name,
workernames=get_runner_workers(c),
collapseRequests=False,
tags=uniq(["job", name] + tags),
factory=f,
)
)
c["schedulers"].append(
Triggerable(
name=job_name,
builderNames=[job_name],
codebases=codebases,
)
)
# spawner
f = factory.BuildFactory()
setup_git_step(f, name, repository)
f.addStep(steps.BuildbotTestCiTrigger(scheduler=job_name))
c["builders"].append(
BuilderConfig(
name=spawner_name,
workernames=get_spawner_workers(c),
properties={"TRAVIS_PULL_REQUEST": False},
tags=uniq(["spawner", name] + tags),
factory=f,
)
)
# try job
f = factory.BuildFactory()
setup_git_step(f, name, repository)
f.addStep(steps.BuildbotTestCiTrigger(scheduler=job_name))
c["builders"].append(
BuilderConfig(
name=try_name,
workernames=get_spawner_workers(c),
properties={"TRAVIS_PULL_REQUEST": True},
tags=uniq(["try", name] + tags),
factory=f,
)
)
c["schedulers"].append(
schedulers.AnyBranchScheduler(
name=spawner_name,
builderNames=[spawner_name],
change_filter=util.ChangeFilter(branch=branches, repository=repository),
onlyImportant=True,
treeStableTimer=1,
codebases=codebases,
)
)
c["schedulers"].append(
schedulers.AnyBranchScheduler(
name=try_name,
builderNames=[try_name],
change_filter=util.ChangeFilter(category="pull", repository=repository),
onlyImportant=True,
codebases=codebases,
)
)
c["schedulers"].append(
schedulers.ForceScheduler(
name="force" + spawner_name,
builderNames=[spawner_name],
codebases=[
CodebaseParameter(
name,
project="",
repository=repository,
branch=None,
revision=None,
)
],
)
)
define_builders(c)
www.setupWWW(c)
def select_next_worker(builder, workers, buildrequest):
preferred_workers = [w for w in workers if "p12-" in w.worker.workername]
if preferred_workers:
return random.choice(preferred_workers)
if workers:
return random.choice(workers)
return None
c["select_next_worker"] = select_next_worker
# configure a janitor which will delete all logs older than two month, and will run on sundays at noon
c["configurators"] = [util.JanitorConfigurator(logHorizon=timedelta(weeks=8), hour=12, dayOfWeek=6)]
with open("metabbotcfg/db_url", encoding="utf-8") as f:
db_url = f.read().strip()
c["db"] = {"db_url": db_url}