forked from fetchai/ledger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
299 lines (254 loc) · 6.33 KB
/
Jenkinsfile
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
DOCKER_IMAGE_NAME = 'gcr.io/organic-storm-201412/fetch-ledger-develop:v0.4.5'
STATIC_ANALYSIS_IMAGE = 'gcr.io/organic-storm-201412/ledger-ci-clang-tidy:v0.1.3'
HIGH_LOAD_NODE_LABEL = 'ledger'
MACOS_NODE_LABEL = 'osx'
enum Platform
{
DEFAULT_CLANG('Clang', 'clang', 'clang++', ''),
CLANG6 ('Clang 6', 'clang-6.0', 'clang++-6.0', 'gcr.io/organic-storm-201412/ledger-ci-clang6:v0.1.3'),
CLANG7 ('Clang 7', 'clang-7', 'clang++-7', 'gcr.io/organic-storm-201412/ledger-ci-clang7:v0.1.3'),
GCC7 ('GCC 7', 'gcc-7', 'g++-7', 'gcr.io/organic-storm-201412/ledger-ci-gcc7:v0.1.3'),
GCC8 ('GCC 8', 'gcc-8', 'g++-8', 'gcr.io/organic-storm-201412/ledger-ci-gcc8:v0.1.3')
public Platform(label, cc, cxx, image)
{
this.label = label
this.env_cc = cc
this.env_cxx = cxx
this.docker_image = image
}
public final String label
public final String env_cc
public final String env_cxx
public final String docker_image
}
LINUX_PLATFORMS_CORE = [
Platform.CLANG6,
Platform.GCC7]
LINUX_PLATFORMS_AUX = [
Platform.CLANG7,
Platform.GCC8]
enum Configuration
{
DEBUG ('Debug'),
RELEASE('Release')
public Configuration(label)
{
this.label = label
}
public final String label
}
def run_full_build()
{
return true
}
def set_up_pipenv()
{
sh "pipenv install --dev --deploy"
sh "pipenv check"
}
def static_analysis(Configuration config)
{
return {
stage('Static Analysis') {
node(HIGH_LOAD_NODE_LABEL) {
stage('SCM Static Analysis') {
checkout scm
}
docker.image(STATIC_ANALYSIS_IMAGE).inside {
stage('Set Up Static Analysis') {
set_up_pipenv()
}
stage('Run Static Analysis') {
sh "pipenv run ./scripts/ci-tool.py --lint ${config.label}"
}
}
}
}
}
}
def stage_name_suffix(Platform platform, Configuration config)
{
return "${platform.label} ${config.label}"
}
def build_stage(Platform platform, Configuration config)
{
return {
stage("Build ${stage_name_suffix(platform, config)}") {
sh "pipenv run ./scripts/ci-tool.py -B ${config.label}"
}
}
}
def fast_tests_stage(Platform platform, Configuration config)
{
return {
stage("Unit Tests ${stage_name_suffix(platform, config)}") {
sh "pipenv run ./scripts/ci-tool.py -T ${config.label}"
}
stage("Etch Lang Tests ${stage_name_suffix(platform, config)}") {
sh "pipenv run ./scripts/ci-tool.py -L ${config.label}"
}
}
}
def slow_tests_stage(Platform platform, Configuration config)
{
return {
stage("Slow Tests ${stage_name_suffix(platform, config)}") {
sh "pipenv run ./scripts/ci-tool.py -S ${config.label}"
}
stage("Integration Tests ${stage_name_suffix(platform, config)}") {
sh "pipenv run ./scripts/ci-tool.py -I ${config.label}"
}
stage("End-to-End Tests ${stage_name_suffix(platform, config)}") {
sh "pipenv run ./scripts/ci-tool.py -E ${config.label}"
}
}
}
def _create_build(
Platform platform,
Configuration config,
node_label,
stages_fn,
run_build_fn)
{
def environment = {
return [
"CC=${platform.env_cc}",
"CXX=${platform.env_cxx}"
]
}
return {
stage(stage_name_suffix(platform, config)) {
node(node_label) {
timeout(120) {
stage("SCM ${stage_name_suffix(platform, config)}") {
checkout scm
}
withEnv(environment()) {
run_build_fn(stages_fn(platform, config))
}
}
}
}
}
}
fast_run = { platform_, config_ ->
return {
build_stage(platform_, config_)()
fast_tests_stage(platform_, config_)()
}
}
full_run = { platform_, config_ ->
return {
build_stage(platform_, config_)()
fast_tests_stage(platform_, config_)()
slow_tests_stage(platform_, config_)()
}
}
def create_docker_build(Platform platform, Configuration config, stages)
{
def build = { build_stages ->
docker.image(platform.docker_image).inside {
stage("Set Up ${stage_name_suffix(platform, config)}") {
set_up_pipenv()
}
build_stages()
}
}
return _create_build(
platform,
config,
HIGH_LOAD_NODE_LABEL,
stages,
build)
}
def create_macos_build(Platform platform, Configuration config)
{
def build = { build_stages ->
try {
stage("Set Up ${stage_name_suffix(platform, config)}") {
set_up_pipenv()
}
build_stages()
} finally {
stage("Tear Down ${stage_name_suffix(platform, config)}") {
sh "pipenv --rm"
}
}
}
return _create_build(
platform,
config,
MACOS_NODE_LABEL,
fast_run,
build)
}
def run_builds_in_parallel()
{
def stages = [:]
for (config in Configuration.values())
{
for (platform in LINUX_PLATFORMS_CORE)
{
stages["${platform.label} ${config.label}"] = create_docker_build(
platform,
config,
full_run)
}
// Only run macOS builds on master and head branches
if (run_full_build())
{
stages["macOS ${Platform.DEFAULT_CLANG.label} ${config.label}"] = create_macos_build(
Platform.DEFAULT_CLANG,
config)
}
}
// for (config in (run_full_build() ? Configuration.values() : [Configuration.RELEASE]))
// {
// for (platform in LINUX_PLATFORMS_AUX)
// {
// stages["${platform.label} ${config.label}"] = create_docker_build(
// platform,
// config,
// run_full_build() ? full_run : fast_run)
// }
// }
if (run_full_build())
{
stages['Static Analysis'] = static_analysis(Configuration.DEBUG)
}
stage('Build and Test') {
// Execute stages
parallel stages
}
}
def run_basic_checks()
{
stage('Basic Checks') {
node {
stage('SCM Basic Checks') {
checkout scm
}
docker.image(DOCKER_IMAGE_NAME).inside {
stage('Set Up Basic Checks') {
set_up_pipenv()
}
stage('Style Check') {
sh 'pipenv run ./scripts/apply_style.py -d'
}
stage('Circular Dependencies') {
sh 'mkdir -p build-deps && cd build-deps && cmake ../'
sh 'pipenv run ./scripts/detect-circular-dependencies.py build-deps/'
}
}
}
}
}
def main()
{
timeout(180) {
run_basic_checks()
run_builds_in_parallel()
}
}
// Entry point
main()