forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
415 lines (398 loc) · 20.2 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
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
#!groovy
helpers = fileLoader.fromGit('helpers', 'https://github.com/keybase/jenkins-helpers.git', 'master', null, 'linux')
helpers.rootLinuxNode(env, {
helpers.slackOnError("client", env, currentBuild)
}, {}) {
properties([
[$class: "BuildDiscarderProperty",
strategy: [$class: "LogRotator",
numToKeepStr: "30",
daysToKeepStr: "10",
artifactNumToKeepStr: "10",
]
],
[$class: 'RebuildSettings',
autoRebuild: true,
],
//[$class: "ParametersDefinitionProperty",
// parameterDefinitions: [
// [$class: 'StringParameterDefinition',
// name: 'gregorProjectName',
// defaultValue: '',
// description: 'name of upstream gregor project',
// ]
// ]
//],
//[$class: "ParametersDefinitionProperty",
// parameterDefinitions: [
// [$class: 'StringParameterDefinition',
// name: 'kbwebProjectName',
// defaultValue: '',
// description: 'name of upstream kbweb project',
// ]
// ]
//],
])
env.BASEDIR=pwd()
env.GOPATH="${env.BASEDIR}/go"
def mysqlImage = docker.image("keybaseprivate/mysql")
def gregorImage = docker.image("keybaseprivate/kbgregor")
def kbwebImage = docker.image("keybaseprivate/kbweb")
def glibcImage = docker.image("keybaseprivate/glibc")
def clientImage = null
def kbwebNodePrivateIP = httpRequest("http://169.254.169.254/latest/meta-data/local-ipv4").content
println "Running on host $kbwebNodePrivateIP"
println "Setting up build: ${env.BUILD_TAG}"
def cause = helpers.getCauseString(currentBuild)
println "Cause: ${cause}"
println "Pull Request ID: ${env.CHANGE_ID}"
ws("${env.GOPATH}/src/github.com/keybase/client") {
stage("Setup") {
sh "docker rmi keybaseprivate/mysql || echo 'No mysql image to remove'"
docker.withRegistry("", "docker-hub-creds") {
parallel (
checkout: {
retry(3) {
checkout scm
sh 'echo -n $(git --no-pager show -s --format="%an" HEAD) > .author_name'
sh 'echo -n $(git --no-pager show -s --format="%ae" HEAD) > .author_email'
env.AUTHOR_NAME = readFile('.author_name')
env.AUTHOR_EMAIL = readFile('.author_email')
sh 'rm .author_name .author_email'
sh 'echo -n $(git rev-parse HEAD) > go/revision'
sh "git add go/revision"
env.GIT_COMMITTER_NAME = 'Jenkins'
env.GIT_COMMITTER_EMAIL = '[email protected]'
sh 'git commit --author="Jenkins <[email protected]>" -am "revision file added"'
env.COMMIT_HASH = readFile('go/revision')
}
},
pull_glibc: {
glibcImage.pull()
},
pull_mysql: {
mysqlImage.pull()
},
pull_gregor: {
gregorImage.pull()
},
pull_kbweb: {
kbwebImage.pull()
},
remove_dockers: {
sh 'docker stop $(docker ps -q) || echo "nothing to stop"'
sh 'docker rm $(docker ps -aq) || echo "nothing to remove"'
},
)
}
}
def hasGoChanges = hasChanges('go')
def hasJSChanges = hasChanges('shared')
println "Has go changes: " + hasGoChanges
println "Has JS changes: " + hasJSChanges
stage("Test") {
helpers.withKbweb() {
parallel (
test_linux_deps: {
if (hasGoChanges) {
// Build the client docker first so we can immediately kick off KBFS
dir('go') {
sh "go install github.com/keybase/client/go/keybase"
sh "cp ${env.GOPATH}/bin/keybase ./keybase/keybase"
clientImage = docker.build("keybaseprivate/kbclient")
sh "docker save keybaseprivate/kbclient | gzip > kbclient.tar.gz"
archive("kbclient.tar.gz")
sh "rm kbclient.tar.gz"
}
}
parallel (
test_linux: {
dir("protocol") {
sh "./diff_test.sh"
}
parallel (
test_linux_go: { withEnv([
"PATH=${env.PATH}:${env.GOPATH}/bin",
"KEYBASE_SERVER_URI=http://${kbwebNodePrivateIP}:3000",
"KEYBASE_PUSH_SERVER_URI=fmprpc://${kbwebNodePrivateIP}:9911",
]) {
if (hasGoChanges) {
testGo("test_linux_go_")
}
}},
test_linux_js: { withEnv([
"PATH=${env.HOME}/.node/bin:${env.PATH}",
"NODE_PATH=${env.HOME}/.node/lib/node_modules:${env.NODE_PATH}",
]) {
dir("shared") {
stage("JS Tests") {
sh "./jenkins_test.sh js ${env.COMMIT_HASH} ${env.CHANGE_TARGET}"
}
}
// Only run visdiff for PRs
if (env.CHANGE_ID) {
wrap([$class: 'Xvfb', screen: '1280x1024x16']) {
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'visdiff-aws-creds',
usernameVariable: 'VISDIFF_AWS_ACCESS_KEY_ID',
passwordVariable: 'VISDIFF_AWS_SECRET_ACCESS_KEY',
],[$class: 'StringBinding',
credentialsId: 'visdiff-github-token',
variable: 'VISDIFF_GH_TOKEN',
]]) {
withEnv([
"VISDIFF_S3_BUCKET=keybase-jenkins-visdiff",
"VISDIFF_WORK_DIR=${env.BASEDIR}/visdiff",
"VISDIFF_PR_ID=${env.CHANGE_ID}",
]) {
dir("shared") {
sh "./jenkins_test.sh visdiff-install ${env.COMMIT_HASH} ${env.CHANGE_TARGET}"
}
try {
timeout(time: 10, unit: 'MINUTES') {
dir("shared") {
stage("js visdiff") {
sh "./jenkins_test.sh visdiff ${env.COMMIT_HASH} ${env.CHANGE_TARGET}"
}
}
}
} catch (e) {
helpers.slackMessage("#breaking-visdiff", "warning", "<@mgood>: visdiff failed: <${env.BUILD_URL}|${env.JOB_NAME} ${env.BUILD_DISPLAY_NAME}>")
}
}}}
}
}},
)
},
test_kbfs: {
if (hasGoChanges) {
build([
job: "/kbfs/master",
parameters: [
string(
name: 'clientProjectName',
value: env.JOB_NAME,
),
string(
name: 'kbwebNodePrivateIP',
value: kbwebNodePrivateIP,
),
]
])
}
},
)
},
test_windows: {
// TODO: If we re-enable tests other than Go tests on
// Windows, this check should go away.
if (hasGoChanges) {
helpers.nodeWithCleanup('windows', {}, {}) {
def BASEDIR="${pwd()}\\${env.BUILD_NUMBER}"
def GOPATH="${BASEDIR}\\go"
withEnv([
'GOROOT=C:\\tools\\go',
"GOPATH=\"${GOPATH}\"",
"PATH=\"C:\\tools\\go\\bin\";\"C:\\Program Files (x86)\\GNU\\GnuPG\";\"C:\\Program Files\\nodejs\";\"C:\\tools\\python\";\"C:\\Program Files\\graphicsmagick-1.3.24-q8\";${env.PATH}",
"KEYBASE_SERVER_URI=http://${kbwebNodePrivateIP}:3000",
"KEYBASE_PUSH_SERVER_URI=fmprpc://${kbwebNodePrivateIP}:9911",
]) {
ws("$GOPATH/src/github.com/keybase/client") {
println "Checkout Windows"
retry(3) {
checkout scm
}
println "Test Windows"
parallel (
test_windows_go: {
if (hasGoChanges) {
dir("go/keybase") {
bat "go build"
}
testGo("test_windows_go_")
}
},
test_windows_js: {
// Only run visdiff for PRs
// FIXME (MBG): Disabled temporarily due to flaky false positives
// When this is re-enabled, remove the if (hasGoChanges) check at the
// beginning of this block.
if (false && env.CHANGE_ID) {
wrap([$class: 'Xvfb']) {
println "Test Windows JS"
dir("visdiff") {
bat "yarn cache clean"
bat "yarn install --pure-lockfile"
}
dir("desktop") {
bat "yarn cache clean"
bat "yarn install --pure-lockfile"
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'visdiff-aws-creds',
usernameVariable: 'VISDIFF_AWS_ACCESS_KEY_ID',
passwordVariable: 'VISDIFF_AWS_SECRET_ACCESS_KEY',
],[$class: 'StringBinding',
credentialsId: 'visdiff-github-token',
variable: 'VISDIFF_GH_TOKEN',
]]) {
withEnv([
"VISDIFF_PR_ID=${env.CHANGE_ID}",
]) {
bat '..\\node_modules\\.bin\\keybase-visdiff "merge-base(origin/master, HEAD)...HEAD"'
}}
}
}}},
)
}}
}
}
},
test_macos: {
// TODO: If we re-enable tests other than Go tests on
// macOS, this check should go away.
if (hasGoChanges) {
def mountDir='/Volumes/untitled/client'
helpers.nodeWithCleanup('macstadium', {}, {
sh "rm -rf ${mountDir} || echo 'Something went wrong with cleanup.'"
}) {
def BASEDIR="${pwd()}/${env.BUILD_NUMBER}"
def GOPATH="${BASEDIR}/go"
dir(mountDir) {
// Ensure that the mountDir exists
sh "touch test.txt"
}
withEnv([
"GOPATH=${GOPATH}",
"NODE_PATH=${env.HOME}/.node/lib/node_modules:${env.NODE_PATH}",
"PATH=${env.PATH}:${GOPATH}/bin:${env.HOME}/.node/bin",
"KEYBASE_SERVER_URI=http://${kbwebNodePrivateIP}:3000",
"KEYBASE_PUSH_SERVER_URI=fmprpc://${kbwebNodePrivateIP}:9911",
"TMPDIR=${mountDir}",
]) {
ws("$GOPATH/src/github.com/keybase/client") {
println "Checkout OS X"
retry(3) {
checkout scm
}
parallel (
//test_react_native: {
// println "Test React Native"
// dir("react-native") {
// sh "npm i"
// lock("iossimulator_${env.NODE_NAME}") {
// sh "npm run test-ios"
// }
// }
//},
test_macos_go: {
if (hasGoChanges) {
testGo("test_macos_go_")
}
}
)
}}
}
}
},
)
}
}
stage("Push") {
if (env.BRANCH_NAME == "master" && cause != "upstream") {
docker.withRegistry("https://docker.io", "docker-hub-creds") {
clientImage.push()
}
} else {
println "Not pushing docker"
}
}
}
}
def hasChanges(subdir) {
dir(subdir) {
def changes = helpers.getChanges(env.COMMIT_HASH, env.CHANGE_TARGET)
println "Number of changes: " + changes.size()
if (changes.size() == 0) {
println "No ${subdir} changes, skipping tests."
return false
}
return true
}
}
def getTestDirsNix() {
def dirs = sh(
returnStdout: true,
script: "go list ./... | grep -v 'vendor\\|bind'"
).trim()
println "Running tests for dirs: " + dirs
return dirs.tokenize()
}
def getTestDirsWindows() {
def dirs = bat(returnStdout: true, script: "@go list ./... | find /V \"vendor\" | find /V \"/go/bind\"").trim()
println "Running tests for dirs: " + dirs
return dirs.tokenize()
}
def testGo(prefix) {
dir('go') {
withEnv([
"KEYBASE_LOG_SETUPTEST_FUNCS=1",
]) {
def shell
def dirs
def slash
def goversion
if (isUnix()) {
shell = { params -> sh params }
dirs = getTestDirsNix()
slash = '/'
goversion = sh(returnStdout: true, script: "go version").trim()
} else {
shell = { params -> bat params }
dirs = getTestDirsWindows()
slash = '\\'
goversion = bat(returnStdout: true, script: "@go version").trim()
}
println "Running tests on commit ${env.COMMIT_HASH} with ${goversion}."
shell "go get \"github.com/stretchr/testify/require\""
shell "go get \"github.com/stretchr/testify/assert\""
def parallelTests = []
def tests = [:]
def specialTests = [:]
def specialTestFilter = ['chat', 'chat_storage']
for (def i=0; i<dirs.size(); i++) {
if (tests.size() == 2) {
parallelTests << tests
tests = [:]
}
def d = dirs[i]
def dirPath = d.replaceAll('github.com/keybase/client/go/', '')
println "Building tests for $dirPath"
dir(dirPath) {
shell "go test -i"
shell "go test -c -o test.test"
// Only run the test if a test binary should have been produced.
if (fileExists("test.test")) {
def testName = dirPath.replaceAll('/', '_')
def test = {
dir(dirPath) {
println "Running tests for $dirPath"
shell ".${slash}test.test -test.timeout 30m"
}
}
if (testName in specialTestFilter) {
specialTests[prefix + testName] = test
} else {
tests[prefix + testName] = test
}
} else {
println "Skipping tests for $dirPath because no test binary was produced."
}
}
}
parallelTests << specialTests
helpers.waitForURL(prefix, env.KEYBASE_SERVER_URI)
for (def i=0; i<parallelTests.size(); i++) {
parallel(parallelTests[i])
}
}}
}