forked from fetchai/ledger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
266 lines (228 loc) · 5.42 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
DOCKER_IMAGE_NAME = 'gcr.io/organic-storm-201412/fetch-ledger-develop:v0.3.0'
HIGH_LOAD_NODE_LABEL = 'ledger'
MACOS_NODE_LABEL = 'mac-mini'
enum Platform
{
DEFAULT_CLANG('Clang', 'clang', 'clang++' ),
CLANG6 ('Clang 6', 'clang-6.0', 'clang++-6.0'),
CLANG7 ('Clang 7', 'clang-7', 'clang++-7' ),
GCC7 ('GCC 7', 'gcc-7', 'g++-7' ),
GCC8 ('GCC 8', 'gcc-8', 'g++-8' )
public Platform(label, cc, cxx)
{
this.label = label
this.env_cc = cc
this.env_cxx = cxx
}
public final String label
public final String env_cc
public final String env_cxx
}
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 is_master_or_pull_request_head_branch()
{
return BRANCH_NAME == 'master' || BRANCH_NAME ==~ /^PR-\d+-head$/ || BRANCH_NAME ==~ /^PR-\d+$/
}
def static_analysis()
{
return {
stage('Static Analysis') {
node {
stage('SCM Static Analysis') {
checkout scm
}
stage('Run Static Analysis') {
docker.image(DOCKER_IMAGE_NAME).inside {
sh '''\
mkdir -p build-analysis
cd build-analysis
cmake ..
'''
sh './scripts/run_static_analysis.py build-analysis'
}
}
}
}
}
}
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 "./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 "./scripts/ci-tool.py -T ${config.label}"
}
stage("Etch Lang Tests ${stage_name_suffix(platform, config)}") {
sh "./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 "./scripts/ci-tool.py -S ${config.label}"
}
stage("Integration Tests ${stage_name_suffix(platform, config)}") {
sh "./scripts/ci-tool.py -I ${config.label}"
}
stage("End-to-End Tests ${stage_name_suffix(platform, config)}") {
sh './scripts/ci/install-test-dependencies.sh'
sh "./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(DOCKER_IMAGE_NAME).inside {
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 -> build_stages() }
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 (is_master_or_pull_request_head_branch())
{
stages["macOS ${Platform.DEFAULT_CLANG.label} ${config.label}"] = create_macos_build(
Platform.DEFAULT_CLANG,
config)
}
}
for (config in (is_master_or_pull_request_head_branch() ? Configuration.values() : [Configuration.RELEASE]))
{
for (platform in LINUX_PLATFORMS_AUX)
{
stages["${platform.label} ${config.label}"] = create_docker_build(
platform,
config,
is_master_or_pull_request_head_branch() ? full_run : fast_run)
}
}
if (is_master_or_pull_request_head_branch())
{
stages['Static Analysis'] = static_analysis()
}
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('Style Check') {
sh './scripts/apply_style.py -d'
}
}
}
}
}
def main()
{
timeout(180) {
run_basic_checks()
run_builds_in_parallel()
}
}
// Entry point
main()