This repository has been archived by the owner on Nov 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Jenkinsfile
executable file
·235 lines (214 loc) · 7.97 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
#!groovy
@Library('realm-ci') _
// printing the timings is a placeholder until we can fix and integrate junit reporting via "-r junit"
testArguments = "-d=1"
dependencies = null
def readGitTag() {
sh "git describe --exact-match --tags HEAD | tail -n 1 > tag.txt 2>&1 || true"
return readFile('tag.txt').trim()
}
def readGitSha() {
sh "git rev-parse HEAD | cut -b1-8 > sha.txt"
return readFile('sha.txt').readLines().last().trim()
}
def publishCoverageReport(String label) {
// Unfortunately, we cannot add a title or tag to individual coverage reports.
echo "Unstashing coverage-${label}"
unstash("coverage-${label}")
step([
$class: 'CoberturaPublisher',
autoUpdateHealth: false,
autoUpdateStability: false,
coberturaReportFile: "build/coverage.xml",
failNoReports: true,
failUnhealthy: false,
failUnstable: false,
maxNumberOfBuilds: 0,
onlyStable: false,
sourceEncoding: 'ASCII',
zoomCoverageChart: false
])
}
def nodeWithSources(String nodespec, Closure steps) {
node(nodespec) {
echo "Running on ${env.NODE_NAME} in ${env.WORKSPACE}"
// Allocate a temp dir inside the workspace that will be deleted after the build
String tempDir = "${env.WORKSPACE}/._tmp"
try {
withEnv([
"TMP=${tempDir}",
"TMPDIR=${tempDir}"
]) {
// rlmCheckout will fetch object-store sources recursively and stash them,
// so that every subsequent call in later stages only has to unstash them
rlmCheckout(scm)
// since checkout above also deletes everything, we need to create a tmp after checkout
dir(tempDir) {
touch '.workspace temp directory'
}
steps()
}
} finally {
deleteDir()
}
}
}
def doDockerBuild(String flavor, Boolean enableSync, String sanitizerFlags = "") {
def sync = enableSync ? "sync" : ""
def label = "${flavor}${enableSync ? '-sync' : ''}"
def buildDir = "build"
def cmakeFlags = "-DCMAKE_BUILD_TYPE=RelWithDebInfo " + sanitizerFlags
return {
nodeWithSources('docker') {
def image = buildDockerEnv("ci/realm-object-store:${flavor}", push: env.BRANCH_NAME == 'master')
def sourcesDir = pwd()
def buildSteps = { String dockerArgs = "" ->
// The only reason we can't run commands directly is because sync builds need to
// use CI's credentials to pull from the private repository. This can be removed
// when sync is open sourced.
sshagent(['realm-ci-ssh']) {
image.inside("-v /etc/passwd:/etc/passwd:ro -v ${env.HOME}:${env.HOME} -v ${env.SSH_AUTH_SOCK}:${env.SSH_AUTH_SOCK} -e HOME=${env.HOME} ${dockerArgs}") {
if (enableSync) {
// sanity check the network to local stitch before continuing to compile everything
sh "curl http://mongodb-realm:9090"
cmakeFlags += "-DREALM_ENABLE_SYNC=1 -DREALM_ENABLE_AUTH_TESTS=1 -DREALM_MONGODB_ENDPOINT=\"http://mongodb-realm:9090\" -DREALM_STITCH_CONFIG=\"${sourcesDir}/tests/mongodb/stitch.json\" "
}
sh "cmake -B ${buildDir} -G Ninja ${cmakeFlags}"
sh "cmake --build ${buildDir} --target tests"
sh "./${buildDir}/tests/tests ${testArguments}"
}
}
}
if (enableSync) {
// stitch images are auto-published every day to our CI
// see https://github.com/realm/ci/tree/master/realm/docker/mongodb-realm
// we refrain from using "latest" here to optimise docker pull cost due to a new image being built every day
// if there's really a new feature you need from the latest stitch, upgrade this manually
withRealmCloud(version: dependencies.MDBREALM_TEST_SERVER_TAG, appsToImport: ['auth-integration-tests': "${env.WORKSPACE}/tests/mongodb"]) { networkName ->
buildSteps("--network=${networkName}")
}
} else {
buildSteps("")
}
}
}
}
def doAndroidDockerBuild() {
return {
node('docker') {
try {
rlmCheckout(scm)
wrap([$class: 'AnsiColorBuildWrapper']) {
def image = buildDockerEnv('ci/realm-object-store:android', extra_args: '-f android.Dockerfile', push: env.BRANCH_NAME == 'master')
docker.image('tracer0tong/android-emulator').withRun { emulator ->
image.inside("--link ${emulator.id}:emulator") {
sh """
cmake -B build -DREALM_PLATFORM=Android -DANDROID_NDK=\${ANDROID_NDK} -GNinja -DCMAKE_MAKE_PROGRAM=ninja
cmake --build build
adb connect emulator
timeout 30m adb wait-for-device
adb push build/tests/tests /data/local/tmp
adb shell '/data/local/tmp/tests || echo __ADB_FAIL__' | tee adb.log
! grep __ADB_FAIL__ adb.log
"""
}
}
}
} finally {
deleteDir()
}
}
}
}
def doBuild(String nodeSpec, String flavor, Boolean enableSync, String additionalFlags = "") {
def sync = enableSync ? "sync" : "false"
def label = "${flavor}${enableSync ? '-sync' : ''}"
def buildDir = "build"
def cmakeFlags = "-DCMAKE_CXX_FLAGS=-Werror "
if (enableSync) {
cmakeFlags += "-DREALM_ENABLE_SYNC=1 "
}
cmakeFlags += additionalFlags;
return {
nodeWithSources(nodeSpec) {
sh "cmake -B ${buildDir} -G Ninja ${cmakeFlags} && cmake --build ${buildDir}"
if (additionalFlags.contains('Coverage')) {
sh "cd ${buildDir} && ninja -v generate-coverage-cobertura"
echo "Stashing coverage-${label}"
stash includes: "${buildDir}/coverage.xml", name: "coverage-${label}"
}
else {
sh "${buildDir}/tests/tests ${testArguments}"
}
}
}
}
def doWindowsBuild() {
return {
nodeWithSources('windows') {
bat """
"${tool 'cmake'}" . -DCMAKE_SYSTEM_VERSION="8.1"
"${tool 'cmake'}" --build . --config Release
tests\\Release\\tests.exe ${testArguments}
"""
}
}
}
def doWindowsUniversalBuild() {
return {
nodeWithSources('windows') {
bat """
"${tool 'cmake'}" . -DCMAKE_SYSTEM_NAME="WindowsStore" -DCMAKE_SYSTEM_VERSION="10.0"
"${tool 'cmake'}" --build . --config Release --target realm-object-store
"""
}
}
}
def setBuildName(newBuildName) {
currentBuild.displayName = "${currentBuild.displayName} - ${newBuildName}"
}
jobWrapper { // sets the max build time to 2 hours
stage('prepare') {
nodeWithSources('docker') {
dependencies = readProperties(file: 'dependencies.list')
gitTag = readGitTag()
gitSha = readGitSha()
echo "tag: ${gitTag}"
if (gitTag == "") {
echo "No tag given for this build"
setBuildName("${gitSha}")
} else {
echo "Building release: '${gitTag}'"
setBuildName("Tag ${gitTag}")
}
}
}
stage('unit-tests') {
parallel(
linux: doDockerBuild('linux', false),
linux_sync: doDockerBuild('linux', true),
linux_asan: doDockerBuild('linux', true, '-DSANITIZE_ADDRESS=1'),
macos_asan: doBuild('osx', 'macOS', true, '-DSANITIZE_ADDRESS=1'),
// FIXME: the tsan build works, but it's reporting legit races that need to be fixed
// see https://github.com/realm/realm-object-store/pull/905
// linux_tsan: doDockerBuild('linux', true, '-DSANITIZE_THREAD=1'),
// macos_tsan: doBuild('osx', 'macOS', true, '-DSANITIZE_THREAD=1'),
android: doAndroidDockerBuild(),
macos: doBuild('osx', 'macOS', false),
macos_sync: doBuild('osx', 'macOS', true, '-DCMAKE_BUILD_TYPE=Coverage'),
win32: doWindowsBuild(),
windows_universal: doWindowsUniversalBuild()
)
currentBuild.result = 'SUCCESS'
}
stage('publish') {
node('docker') {
// we need sources to allow the coverage report to display them
rlmCheckout(scm)
// coverage reports assume sources are in the parent directory
dir("build") {
publishCoverageReport('macOS-sync')
}
}
}
} // jobWrapper