2016-11-17 15:55:02 +00:00
|
|
|
#!groovy
|
|
|
|
import groovy.json.JsonOutput
|
|
|
|
|
|
|
|
repoName = 'realm-js' // This is a global variable
|
|
|
|
|
|
|
|
def gitTag
|
|
|
|
def gitSha
|
|
|
|
def dependencies
|
|
|
|
def version
|
|
|
|
|
2016-12-16 21:23:11 +00:00
|
|
|
// == Stages
|
|
|
|
|
2016-11-17 15:55:02 +00:00
|
|
|
stage('check') {
|
|
|
|
node('docker') {
|
2016-12-16 21:23:11 +00:00
|
|
|
// - 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'
|
2016-11-17 15:55:02 +00:00
|
|
|
|
|
|
|
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}"
|
2016-11-24 16:16:15 +00:00
|
|
|
|
2016-11-25 11:09:16 +00:00
|
|
|
if (['master'].contains(env.BRANCH_NAME)) {
|
2016-11-24 16:16:15 +00:00
|
|
|
// If we're on master, instruct the docker image builds to push to the
|
|
|
|
// cache registry
|
|
|
|
env.DOCKER_PUSH = "1"
|
|
|
|
}
|
2016-11-17 15:55:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-16 21:23:11 +00:00
|
|
|
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'),
|
2017-10-11 10:35:12 +00:00
|
|
|
macos_node_debug: doMacBuild('node Debug', true) {
|
|
|
|
withCredentials([string(credentialsId: 'codecov-token-js', variable: 'CODECOV_TOKEN')]) {
|
|
|
|
sh 'node_modules/.bin/codecov'
|
|
|
|
}
|
|
|
|
},
|
2016-12-16 21:23:11 +00:00
|
|
|
macos_node_release: doMacBuild('node Release'),
|
2017-03-07 16:41:19 +00:00
|
|
|
//macos_realmjs_debug: doMacBuild('realmjs Debug'),
|
|
|
|
//macos_realmjs_release: doMacBuild('realmjs Release'),
|
2017-09-05 14:01:55 +00:00
|
|
|
macos_react_tests_debug: doMacBuild('react-tests Debug'),
|
|
|
|
macos_react_tests_release: doMacBuild('react-tests Release'),
|
2016-12-16 21:23:11 +00:00
|
|
|
macos_react_example_debug: doMacBuild('react-example Debug'),
|
|
|
|
macos_react_example_release: doMacBuild('react-example Release'),
|
2017-03-07 16:41:19 +00:00
|
|
|
//android_react_tests: doAndroidBuild('react-tests-android', {
|
|
|
|
// junit 'tests/react-test-app/tests.xml'
|
2017-03-07 22:24:30 +00:00
|
|
|
//}),
|
|
|
|
windows_node: doWindowsBuild()
|
2016-12-16 21:23:11 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// == 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']
|
|
|
|
])
|
2017-05-05 13:31:52 +00:00
|
|
|
} catch(Exception err) {
|
2016-12-16 21:23:11 +00:00
|
|
|
echo "Error posting to GitHub: ${err}"
|
|
|
|
}
|
2016-11-22 10:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def doInside(script, target, postStep = null) {
|
|
|
|
try {
|
2016-11-22 10:52:32 +00:00
|
|
|
reportStatus(target, 'PENDING', 'Build has started')
|
2016-12-16 21:23:11 +00:00
|
|
|
|
|
|
|
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}"
|
|
|
|
}
|
2016-11-22 10:02:50 +00:00
|
|
|
if(postStep) {
|
|
|
|
postStep.call()
|
|
|
|
}
|
2016-12-16 21:23:11 +00:00
|
|
|
dir(env.WORKSPACE) {
|
|
|
|
deleteDir() // solving realm/realm-js#734
|
|
|
|
}
|
2016-11-22 10:02:50 +00:00
|
|
|
reportStatus(target, 'SUCCESS', 'Success!')
|
|
|
|
} catch(Exception e) {
|
2016-12-16 21:23:11 +00:00
|
|
|
reportStatus(target, 'FAILURE', e.toString())
|
2016-11-22 10:02:50 +00:00
|
|
|
currentBuild.rawBuild.setResult(Result.FAILURE)
|
2016-12-16 21:23:11 +00:00
|
|
|
e.printStackTrace()
|
2016-11-22 10:50:55 +00:00
|
|
|
throw e
|
2016-11-22 10:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 16:16:15 +00:00
|
|
|
def doDockerInside(script, target, postStep = null) {
|
|
|
|
docker.withRegistry("https://${env.DOCKER_REGISTRY}", "ecr:eu-west-1:aws-ci-user") {
|
2016-11-24 16:34:09 +00:00
|
|
|
doInside(script, target, postStep)
|
2016-11-24 16:16:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:29:19 +00:00
|
|
|
def doAndroidBuild(target, postStep = null) {
|
|
|
|
return {
|
2016-12-20 19:01:45 +00:00
|
|
|
node('docker && android') {
|
2017-03-07 09:11:36 +00:00
|
|
|
timeout(time: 1, unit: 'HOURS') {
|
|
|
|
doDockerInside("./scripts/docker-android-wrapper.sh ./scripts/test.sh", target, postStep)
|
|
|
|
}
|
2016-11-24 13:29:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-11 10:35:12 +00:00
|
|
|
def doDockerBuild(target, coverage = false, postStep = null) {
|
|
|
|
def prefix = coverage?'node_modules/.bin/nyc ':''
|
2016-11-17 15:55:02 +00:00
|
|
|
return {
|
2016-11-22 10:02:50 +00:00
|
|
|
node('docker') {
|
2017-10-10 08:25:56 +00:00
|
|
|
deleteDir()
|
|
|
|
unstash 'source'
|
|
|
|
|
2017-10-10 08:12:51 +00:00
|
|
|
try {
|
|
|
|
reportStatus(target, 'PENDING', 'Build has started')
|
|
|
|
|
|
|
|
docker.image('node:6').inside('-e HOME=/tmp') {
|
2017-10-11 10:35:12 +00:00
|
|
|
sh "${prefix}scripts/test.sh ${target}"
|
2017-10-10 08:12:51 +00:00
|
|
|
if(postStep) {
|
|
|
|
postStep.call()
|
|
|
|
}
|
|
|
|
deleteDir()
|
|
|
|
reportStatus(target, 'SUCCESS', 'Success!')
|
|
|
|
}
|
|
|
|
} catch(Exception e) {
|
|
|
|
reportStatus(target, 'FAILURE', e.toString())
|
|
|
|
throw e
|
|
|
|
}
|
2016-11-17 15:55:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:29:19 +00:00
|
|
|
def doMacBuild(target, postStep = null) {
|
2016-11-17 15:55:02 +00:00
|
|
|
return {
|
2016-11-24 13:29:19 +00:00
|
|
|
node('osx_vegas') {
|
|
|
|
doInside("./scripts/test.sh", target, postStep)
|
2016-11-17 15:55:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-11 17:22:41 +00:00
|
|
|
|
2017-03-07 22:24:30 +00:00
|
|
|
def doWindowsBuild() {
|
|
|
|
return {
|
2017-09-05 14:01:55 +00:00
|
|
|
node('windows && nodejs') {
|
2017-03-07 22:24:30 +00:00
|
|
|
unstash 'source'
|
|
|
|
try {
|
2017-09-05 14:01:55 +00:00
|
|
|
bat 'npm install --build-from-source=realm'
|
2017-03-07 22:24:30 +00:00
|
|
|
dir('tests') {
|
|
|
|
bat 'npm install'
|
2017-03-30 08:24:46 +00:00
|
|
|
bat 'npm run test'
|
2017-03-07 22:24:30 +00:00
|
|
|
junit 'junitresults-*.xml'
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
deleteDir()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|