Jenkinsfile
5.1 KB
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
#!groovy
def getSourceArchive() {
deleteDir()
unstash 'source'
}
def readGitTag() {
sh "git describe --exact-match --tags HEAD | tail -n 1 > tag.txt 2>&1 || true"
def tag = readFile('tag.txt').trim()
return tag
}
def readGitSha() {
sh "git rev-parse HEAD | cut -b1-8 > sha.txt"
def sha = readFile('sha.txt').readLines().last().trim()
return sha
}
def buildDockerEnv(name, dockerfile='Dockerfile', extra_args='') {
docker.withRegistry("https://${env.DOCKER_REGISTRY}", "ecr:eu-west-1:aws-ci-user") {
sh "sh ./workflow/docker_build_wrapper.sh $name . ${extra_args}"
}
return docker.image(name)
}
def publishReport(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: "${label}.build/coverage.xml",
failNoReports: true,
failUnhealthy: false,
failUnstable: false,
maxNumberOfBuilds: 0,
onlyStable: false,
sourceEncoding: 'ASCII',
zoomCoverageChart: false
])
}
if (env.BRANCH_NAME == 'master') {
env.DOCKER_PUSH = "1"
}
def doDockerBuild(String flavor, Boolean withCoverage, Boolean enableSync) {
def sync = enableSync ? "sync" : ""
def label = "${flavor}${enableSync ? '-sync' : ''}"
return {
node('docker') {
getSourceArchive()
def image = buildDockerEnv("ci/realm-object-store:${flavor}")
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}") {
if(withCoverage) {
sh "rm -rf coverage.build ${label}.build && ./workflow/test_coverage.sh ${sync} && mv coverage.build ${label}.build"
} else {
sh "./workflow/build.sh ${flavor} ${sync}"
}
}
}
if(withCoverage) {
echo "Stashing coverage-${label}"
stash includes: "${label}.build/coverage.xml", name: "coverage-${label}"
}
}
}
}
def doAndroidDockerBuild() {
return {
node('docker') {
getSourceArchive()
wrap([$class: 'AnsiColorBuildWrapper']) {
def image = buildDockerEnv('ci/realm-object-store:android')
docker.image('tracer0tong/android-emulator').withRun { emulator ->
image.inside("--link ${emulator.id}:emulator") {
sh '''rm -rf build
mkdir build
cd build
cmake -DREALM_PLATFORM=Android -DANDROID_NDK=/opt/android-ndk -GNinja ..
ninja
adb connect emulator
timeout 10m adb wait-for-device
adb push tests/tests /data/local/tmp
adb shell '/data/local/tmp/tests || echo __ADB_FAIL__' | tee adb.log
! grep __ADB_FAIL__ adb.log
'''
}
}
}
}
}
}
def doBuild(String nodeSpec, String flavor, Boolean enableSync, String version) {
def sync = enableSync ? "sync" : "false"
def label = "${flavor}${enableSync ? '-sync' : ''}"
return {
node(nodeSpec) {
getSourceArchive()
sshagent(['realm-ci-ssh']) {
sh "./workflow/test_coverage.sh ${sync} ${version} && mv coverage.build ${label}.build"
}
echo "Stashing coverage-${label}"
stash includes: "${label}.build/coverage.xml", name: "coverage-${label}"
}
}
}
def doWindowsBuild() {
return {
node('windows') {
getSourceArchive()
bat """
"${tool 'cmake'}" . -DCMAKE_SYSTEM_VERSION="8.1"
"${tool 'cmake'}" --build . --config Release
tests\\Release\\tests.exe
"""
}
}
}
def doWindowsUniversalBuild() {
return {
node('windows') {
getSourceArchive()
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}"
}
stage('prepare') {
node('docker') {
checkout scm
sh 'git clean -ffdx -e .????????'
sshagent(['realm-ci-ssh']) {
sh 'git submodule update --init --recursive'
}
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}")
}
stash includes: '**', name: 'source'
}
}
stage('unit-tests') {
parallel(
linux: doDockerBuild('linux', true, false),
linux_sync: doDockerBuild('linux', true, true),
android: doAndroidDockerBuild(),
macos: doBuild('osx', 'macOS', false, ''),
macos_sync: doBuild('osx', 'macOS', true, ''),
win32: doWindowsBuild(),
windows_universal: doWindowsUniversalBuild()
)
currentBuild.result = 'SUCCESS'
}
stage('publish') {
node('docker') {
publishReport('linux')
publishReport('linux-sync')
publishReport('macOS')
publishReport('macOS-sync')
}
}