forked from realm/realm-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
222 lines (198 loc) · 5.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
#!groovy
import groovy.json.JsonOutput
repoName = 'realm-js' // This is a global variable
def gitTag
def gitSha
def dependencies
def version
// == Stages
stage('check') {
node('docker') {
// - checkout the source
checkout([
$class: 'GitSCM',
branches: scm.branches,
gitTool: 'native git',
extensions: scm.extensions + [
[$class: 'CleanCheckout'],
[$class: 'SubmoduleOption', recursiveSubmodules: true]
],
userRemoteConfigs: scm.userRemoteConfigs
])
stash name: 'source', includes:'**/*', excludes:'react-native/android/src/main/jni/src/object-store/.dockerignore'
dependencies = readProperties file: 'dependencies.list'
gitTag = readGitTag()
gitSha = readGitSha()
version = getVersion()
echo "tag: ${gitTag}"
if (gitTag == "") {
echo "No tag given for this build"
setBuildName("${gitSha}")
} else {
if (gitTag != "v${dependencies.VERSION}") {
echo "Git tag '${gitTag}' does not match v${dependencies.VERSION}"
} else {
echo "Building release: '${gitTag}'"
setBuildName("Tag ${gitTag}")
}
}
echo "version: ${version}"
if (['master'].contains(env.BRANCH_NAME)) {
// If we're on master, instruct the docker image builds to push to the
// cache registry
env.DOCKER_PUSH = "1"
}
}
}
stage('build') {
parallel(
eslint: doDockerBuild('eslint-ci', {
step([$class: 'CheckStylePublisher', canComputeNew: false, canRunOnFailed: true, defaultEncoding: '', healthy: '', pattern: 'eslint.xml', unHealthy: ''])
}),
jsdoc: doDockerBuild('jsdoc', {
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'docs/output', reportFiles: 'index.html', reportName: 'Docs'])
}),
linux_node_debug: doDockerBuild('node Debug'),
linux_node_release: doDockerBuild('node Release'),
linux_test_runners: doDockerBuild('test-runners'),
macos_node_debug: doMacBuild('node Debug'),
macos_node_release: doMacBuild('node Release'),
//macos_realmjs_debug: doMacBuild('realmjs Debug'),
//macos_realmjs_release: doMacBuild('realmjs Release'),
macos_react_tests_debug: doReactBuild('react-tests Debug'),
macos_react_tests_release: doReactBuild('react-tests Release'),
macos_react_example_debug: doMacBuild('react-example Debug'),
macos_react_example_release: doMacBuild('react-example Release'),
//android_react_tests: doAndroidBuild('react-tests-android', {
// junit 'tests/react-test-app/tests.xml'
//}),
windows_node: doWindowsBuild()
)
}
// == Methods
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 getVersion(){
def dependencies = readProperties file: 'dependencies.list'
def gitTag = readGitTag()
def gitSha = readGitSha()
if (gitTag == "") {
return "${dependencies.VERSION}-g${gitSha}"
}
else {
return dependencies.VERSION
}
}
def setBuildName(newBuildName) {
currentBuild.displayName = "${currentBuild.displayName} - ${newBuildName}"
}
def reportStatus(target, state, String message) {
echo "Reporting Status ${state} to GitHub: ${message}"
if (message && message.length() > 140) {
message = message.take(137) + '...' // GitHub API only allows for 140 characters
}
try {
step([
$class: 'GitHubCommitStatusSetter',
contextSource: [$class: 'ManuallyEnteredCommitContextSource', context: target],
statusResultSource: [$class: 'ConditionalStatusResultSource', results: [[
$class: 'AnyBuildResult', message: message, state: state]]
],
reposSource: [$class: 'ManuallyEnteredRepositorySource', url: 'https://github.com/realm/realm-js']
])
} catch(Exception err) {
echo "Error posting to GitHub: ${err}"
}
}
def doInside(script, target, postStep = null) {
try {
reportStatus(target, 'PENDING', 'Build has started')
retry(3) { // retry unstash up to three times to mitigate network and contention
dir(env.WORKSPACE) {
deleteDir()
unstash 'source'
}
}
wrap([$class: 'AnsiColorBuildWrapper']) {
sh "bash ${script} ${target}"
}
if(postStep) {
postStep.call()
}
dir(env.WORKSPACE) {
deleteDir() // solving realm/realm-js#734
}
reportStatus(target, 'SUCCESS', 'Success!')
} catch(Exception e) {
reportStatus(target, 'FAILURE', e.toString())
currentBuild.rawBuild.setResult(Result.FAILURE)
e.printStackTrace()
throw e
}
}
def doDockerInside(script, target, postStep = null) {
docker.withRegistry("https://${env.DOCKER_REGISTRY}", "ecr:eu-west-1:aws-ci-user") {
doInside(script, target, postStep)
}
}
def doAndroidBuild(target, postStep = null) {
return {
node('docker && android') {
timeout(time: 1, unit: 'HOURS') {
doDockerInside("./scripts/docker-android-wrapper.sh ./scripts/test.sh", target, postStep)
}
}
}
}
def doDockerBuild(target, postStep = null) {
return {
node('docker') {
doDockerInside("./scripts/docker-wrapper.sh ./scripts/test.sh", target, postStep)
}
}
}
def doMacBuild(target, postStep = null) {
return {
node('osx_vegas') {
doInside("./scripts/test.sh", target, postStep)
}
}
}
def doReactBuild(target, postStep = null) {
return {
node('xamarin-mac') {
try {
lock("${env.NODE_NAME} iOS Simulator") {
doInside("./scripts/test.sh", target, postStep)
}
} finally {
deleteDir()
}
}
}
}
def doWindowsBuild() {
return {
node('windows') {
unstash 'source'
try {
bat 'npm install --build-from-source'
dir('tests') {
bat 'npm install'
bat 'npm run test'
junit 'junitresults-*.xml'
}
} finally {
deleteDir()
}
}
}
}