forked from LiskArchive/lisk-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.sdk
340 lines (330 loc) · 8.58 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
@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
NODE_ENV=test LISK_CONSOLE_LOG_LEVEL=debug node test/test_app >.app.log 2>&1 &
'''
}
}
// 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_jest(test_name) {
ansiColor('xterm') {
timestamps {
nvm(getNodejsVersion()) {
dir('framework') {
sh 'npm run test:' + "${test_name}" + ' ${JEST_OPTIONS}'
}
}
}
}
}
def teardown_jest(test_name) {
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 test:\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: '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: 'SILENT', defaultValue: 'true', description: 'To turn off test debug logs.', )
])
])
pipeline {
agent { node { label 'lisk-sdk' } }
environment {
MAX_TASK_LIMIT = '20'
}
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 i -g yarn
yarn
yarn build
# needed by one of the "Functional HTTP GET tests"
git rev-parse HEAD > framework/REVISION
'''
}
stash name: 'build'
}
}
stage('Lint') {
steps {
nvm(getNodejsVersion()) {
sh '''
yarn lint
'''
}
}
}
stage('Format') {
steps {
nvm(getNodejsVersion()) {
sh '''
npm run format
if [ -z "$(git status --untracked-files=no --porcelain)" ]; then
echo "All files formatted"
else
echo "Running format is required"
exit 1
fi
'''
}
}
}
stage('Test') {
parallel {
stage('Lisk Elements') {
agent { node { label 'lisk-elements' }}
steps {
setup()
nvm(getNodejsVersion()) {
sh 'npx lerna run test:ci --ignore lisk-{framework,commander,@liskhq/lisk-framework-*}'
}
}
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 run test:ci
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 {
// jest ITs seem to need special treatment
nvm(getNodejsVersion()) {
sh '''
npm install --global yarn
yarn
yarn build
'''
}
run_jest('integration')
}
post {
cleanup {
teardown_jest('integration')
}
}
}
stage('Lisk Framework Functional') {
agent { node { label 'lisk-framework' }}
steps {
// jest ITs seem to need special treatment
nvm(getNodejsVersion()) {
sh '''
npm install --global yarn
yarn
yarn build
'''
}
run_jest('functional')
}
post {
cleanup {
teardown_jest('functional')
}
}
}
stage('Lisk Framework Plugins Unit') {
agent { node { label 'lisk-framework' }}
steps {
setup()
nvm(getNodejsVersion()) {
sh 'npx lerna run test:unit --scope=@liskhq/lisk-framework-*'
}
}
post {
cleanup {
// Save all the test results
sh '''
rm -rf coverage_framework_plugins; mkdir -p coverage_framework_plugins
for f in $( find framework-plugins/*/.coverage/ -type f ); do
cp $f coverage_framework_plugins/$( sha1sum $f | cut -d ' ' -f 1 )_$( basename $f )
done
'''
stash name: "coverage_framework_plugins", includes: "coverage_framework_plugins/*", allowEmpty: true
}
}
}
stage('Lisk Framework Plugins Integration') {
agent { node { label 'lisk-framework' }}
steps {
setup()
nvm(getNodejsVersion()) {
sh 'npx lerna run test:integration --scope=@liskhq/lisk-framework-*'
}
}
}
stage('Lisk Framework Plugins Functional') {
agent { node { label 'lisk-framework' }}
steps {
setup()
nvm(getNodejsVersion()) {
sh 'npx lerna run test:functional --scope=@liskhq/lisk-framework-*'
}
}
}
stage('Lisk Client End-to-End') {
agent { node { label 'lisk-client' }}
steps {
setup()
wrap([$class: 'Xvfb', parallelBuild: true, autoDisplayName: true]) {
nvm(getNodejsVersion()) {
sh 'npx lerna run test:e2e --scope=@liskhq/lisk-client'
}
}
}
}
}
}
}
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_framework_plugins"
} catch(err) {
println "Could not unstash framework_plugins. 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_framework_plugins/* ./.nyc_output
cp -r coverage_commander/* ./.nyc_output
cp coverage_jest_unit/coverage-final.json ./.nyc_output/coverage-framework-unit.json
'''
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