forked from LiskArchive/lisk-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.sdk
390 lines (381 loc) · 9.78 KB
/
Jenkinsfile.sdk
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
@Library('lisk-jenkins') _
def setup(start_application=false) {
cleanWs()
unstash 'build'
if(start_application) {
nvm(getNodejsVersion()) {
dir('framework') {
sh '''
# teardown_*() should have killed all node processes but we want to be sure
# this shouldn't hurt assuming the 'lisk-core' jenkins nodes have 1 executor
killall --verbose --wait node || true
for database in $( psql --tuples-only --command='SELECT datname FROM pg_database WHERE datdba = (SELECT usesysid FROM pg_user WHERE usename = current_user);' |awk '{ print $1 }' ); do
dropdb --if-exists $database
done
createdb lisk_dev
NODE_ENV=test LISK_CONSOLE_LOG_LEVEL=debug NEWRELIC_LICENSE_KEY= node test/test_app >.app.log 2>&1 &
'''
}
}
// wait for the Core API to be reachable
timeout(1) {
waitUntil {
script {
def api_available = sh script: 'curl http://localhost:4000/api/node/constants >/dev/null', returnStatus: true
return (api_available == 0)
}
}
}
}
}
def run_mocha(test_name) {
ansiColor('xterm') {
timestamps {
nvm(getNodejsVersion()) {
dir('framework') {
sh 'npm run mocha:' + "${test_name}" + ' ${MOCHA_OPTIONS:-$DEFAULT_MOCHA_OPTIONS}'
}
}
}
}
}
def run_jest(test_name) {
ansiColor('xterm') {
timestamps {
nvm(getNodejsVersion()) {
dir('framework') {
sh 'npm run jest:' + "${test_name}" + ' ${JEST_OPTIONS}'
}
}
}
}
}
def teardown_mocha(test_name) {
// teardown_mocha() gets called in post actions and so we don't want it to fail
try {
nvm(getNodejsVersion()) {
dir('framework') {
sh """
rm -rf coverage_mocha_${test_name}; mkdir -p coverage_mocha_${test_name}
cp test/mocha/.coverage-${test_name}/* coverage_mocha_${test_name}/ || true
"""
}
}
} catch(err) {
println "Could gather coverage statistics from mocha:\n${err}"
}
dir('framework') {
stash name: "coverage_mocha_${test_name}", includes: "coverage_mocha_${test_name}/*", allowEmpty: true
}
timeout(1) {
sh 'killall --verbose --wait node || true'
}
dir('framework') {
sh """
mv .app.log lisk_${test_name}.stdout.txt || true
mv logs/devnet/lisk.log lisk_${test_name}.log || true
"""
archiveArtifacts artifacts: 'lisk_*.log', allowEmptyArchive: true
archiveArtifacts artifacts: 'lisk_*.stdout.txt', allowEmptyArchive: true
}
cleanWs()
}
def teardown_jest(test_name) {
// teardown_mocha() gets called in post actions and so we don't want it to fail
try {
nvm(getNodejsVersion()) {
sh """
rm -rf coverage_jest_${test_name}; mkdir -p coverage_jest_${test_name}
cp framework/.coverage/${test_name}/coverage-final.json coverage_jest_${test_name}/ || echo "Jest lcov coverage not found"
"""
}
} catch(err) {
println "Could gather coverage statistics from jest:\n${err}"
}
stash name: "coverage_jest_${test_name}", includes: "coverage_jest_${test_name}/*", allowEmpty: true
timeout(1) {
sh 'killall --verbose --wait node || true'
}
dir('framework') {
sh """
mv .app.log lisk_${test_name}.stdout.txt || true
mv logs/devnet/lisk.log lisk_${test_name}.log || true
"""
archiveArtifacts artifacts: 'lisk_*.log', allowEmptyArchive: true
archiveArtifacts artifacts: 'lisk_*.stdout.txt', allowEmptyArchive: true
}
cleanWs()
}
properties([
parameters([
string(name: 'MOCHA_OPTIONS', defaultValue: '-- --grep @slow|@unstable --invert', description: 'Please check readme to see available test tags. Example: `-- --grep something`', ),
string(name: 'JEST_OPTIONS', defaultValue: '', description: 'Additional jest options that you want to provide to test runner. Example: `-- --config=<path>`'),
// read by the application
string(name: 'LOG_LEVEL', defaultValue: 'error', description: 'To get desired build log output change the log level', ),
string(name: 'FILE_LOG_LEVEL', defaultValue: 'error', description: 'To get desired file log output change the log level', ),
// used by tests
string(name: 'LOG_DB_EVENTS', defaultValue: 'false', description: 'To get detailed info on db events log.', ),
string(name: 'SILENT', defaultValue: 'true', description: 'To turn off test debug logs.', )
])
])
pipeline {
agent { node { label 'lisk-sdk' } }
environment {
MAX_TASK_LIMIT = '20'
DEFAULT_MOCHA_OPTIONS = "-- --grep @slow|@unstable --invert"
}
stages {
stage('Cancel previous build') {
steps {
script {
if (env.CHANGE_ID) {
// we are build a pull request, try cancelling previous build
cancelPreviousBuild()
}
}
}
}
stage('Build') {
steps {
nvm(getNodejsVersion()) {
sh '''
npm ci
npm run bootstrap
npm run build
# needed by one of the "Functional HTTP GET tests"
git rev-parse HEAD > framework/REVISION
'''
}
stash name: 'build'
}
}
stage('Lint') {
steps {
setup()
nvm(getNodejsVersion()) {
sh '''
npm run lint
'''
}
}
}
stage('Test') {
parallel {
stage('Lisk Elements') {
agent { node { label 'lisk-elements' }}
steps {
setup()
nvm(getNodejsVersion()) {
sh 'npx lerna run test --ignore lisk-{framework,commander}'
}
}
post {
cleanup {
// Save all the test results
sh '''
rm -rf coverage_elements; mkdir -p coverage_elements
for f in $( find elements/*/.coverage/ -type f ); do
cp $f coverage_elements/$( sha1sum $f | cut -d ' ' -f 1 )_$( basename $f )
done
'''
stash name: "coverage_elements", includes: "coverage_elements/*", allowEmpty: true
}
}
}
stage('Lisk Commander') {
agent { node { label 'lisk-commander' }}
steps {
setup()
nvm(getNodejsVersion()) {
dir('commander') {
sh '''
rm -rf coverage_commander; mkdir -p coverage_commander
LISK_COMMANDER_CONFIG_DIR=$WORKSPACE/.lisk npm test
cp -r .nyc_output/* ./coverage_commander
'''
stash name: "coverage_commander", includes: "coverage_commander/*", allowEmpty: true
}
}
}
post {
cleanup {
// Save all the test results
sh 'rm -f $WORKSPACE/.lisk/config.lock'
}
}
}
stage('Lisk Framework Unit') {
agent { node { label 'lisk-framework' }}
steps {
setup()
run_jest('unit')
}
post {
cleanup {
teardown_jest('unit')
}
}
}
stage('Lisk Framework Integration') {
agent { node { label 'lisk-framework' }}
steps {
setup()
run_jest('integration')
}
post {
cleanup {
teardown_jest('integration')
}
}
}
stage('Lisk Framework Functional') {
agent { node { label 'lisk-framework' }}
steps {
setup(true)
run_jest('functional')
}
post {
cleanup {
teardown_jest('functional')
}
}
}
}
}
stage('Legacy Framework test (mocha)') {
parallel {
stage('Functional HTTP GET tests') {
agent { node { label 'lisk-framework' }}
steps {
setup(true)
run_mocha('functional:get')
}
post {
cleanup {
teardown_mocha('get')
}
}
}
stage('Functional HTTP POST tests') {
agent { node { label 'lisk-framework' }}
steps {
setup(true)
run_mocha('functional:post')
}
post {
cleanup {
teardown_mocha('post')
}
}
}
stage('Functional HTTP PUT tests') {
agent { node { label 'lisk-framework' }}
steps {
setup(true)
run_mocha('functional:put')
}
post {
cleanup {
teardown_mocha('put')
}
}
}
stage ('Functional WS tests') {
agent { node { label 'lisk-framework' }}
steps {
setup(true)
run_mocha('functional:ws')
}
post {
cleanup {
teardown_mocha('ws')
}
}
}
stage('Unit tests') {
agent { node { label 'lisk-framework' }}
steps {
setup()
run_mocha('unit')
}
post {
cleanup {
teardown_mocha('unit')
}
}
}
stage('Integration tests') {
agent { node { label 'lisk-framework' }}
options {
timeout(time: 10, unit: 'MINUTES')
}
steps {
setup()
run_mocha('integration')
}
post {
cleanup {
teardown_mocha('integration')
}
}
}
}
}
}
post {
always {
script {
try {
unstash "coverage_elements"
} catch(err) {
println "Could not unstash elements. Continuing."
}
try {
unstash "coverage_commander"
} catch(err) {
println "Could not unstash commander. Continuing."
}
try {
unstash "coverage_jest_unit"
} catch(err) {
println "Could not unstash jest_unit. Continuing."
}
try {
unstash "coverage_mocha_unit"
} catch(err) {
println "Could not unstash mocha_unit. Continuing."
}
sh '''
rm -rf .nyc_output; mkdir -p .nyc_output
rm -rf ci_coverage; mkdir -p ci_coverage
cp -r coverage_elements/* ./.nyc_output
cp -r coverage_commander/* ./.nyc_output
cp coverage_jest_unit/coverage-final.json ./.nyc_output/coverage-framework-unit.json
cp -r coverage_mocha_unit/* ./.nyc_output
'''
try {
nvm(getNodejsVersion()) {
sh '''
npx nyc merge ./.nyc_output ci_coverage/coverage.json
node scripts/map_coverage.js ci_coverage/coverage.json
'''
}
cobertura coberturaReportFile: 'coverage/cobertura-coverage.xml'
} catch(err) {
println "Could not report coverage statistics:\n${err}"
}
currentBuild.result = 'SUCCESS'
if (env.BRANCH_NAME == 'master') {
step([$class: 'MasterCoverageAction', scmVars: [GIT_URL: env.GIT_URL]])
}
if (env.CHANGE_ID != null) {
step([$class: 'CompareCoverageAction', publishResultAs: 'statusCheck', scmVars: [GIT_URL: env.GIT_URL]])
}
}
}
cleanup {
cleanWs()
}
}
}
// vim: filetype=groovy