forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
368 lines (351 loc) · 16.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
#!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}",
"NODE_OPTIONS=--max-old-space-size=4096",
]) {
dir("shared") {
stage("JS Tests") {
sh "./jenkins_test.sh js ${env.COMMIT_HASH} ${env.CHANGE_TARGET}"
}
}
}},
)
},
test_kbfs: {
// Only build KBFS on master builds. This means
// that we can have master breaks, but it
// strikes a good balance between velocity and
// test coverage.
if (env.BRANCH_NAME == "master") {
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()}"
def GOPATH="${BASEDIR}\\go"
withEnv([
'GOROOT=C:\\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_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()
// Ideally, we'd do this on Windows, too, but we'd have to figure
// out how to do it with batch files or PowerShell.
sh '''
lint=$(make -s lint);
echo 2>&1 "$lint";
[ -z "$lint" -o "$lint" = "Lint-free!" ]
'''
sh 'test -z $(gofmt -l $(go list ./... | sed -e s/github.com.keybase.client.go.// ))'
} else {
shell = { params -> bat params }
dirs = getTestDirsWindows()
slash = '\\'
goversion = bat(returnStdout: true, script: "@go version").trim()
}
shell "go vet ./..."
println "Running tests on commit ${env.COMMIT_HASH} with ${goversion}."
def parallelTests = []
def tests = [:]
def specialTests = [:]
def specialTestFilter = ['chat', 'engine', 'teams', 'chat_storage']
for (def i=0; i<dirs.size(); i++) {
if (tests.size() == 4) {
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."
}
}
}
if (tests.size() > 0) {
parallelTests << tests
}
parallelTests << specialTests
helpers.waitForURL(prefix, env.KEYBASE_SERVER_URI)
for (def i=0; i<parallelTests.size(); i++) {
parallel(parallelTests[i])
}
}}
}