xcodeVersions = ['9.2', '9.3', '9.4', '10.0', '10.1', '10.2'] platforms = ['osx', 'ios', 'watchos', 'tvos'] platformNames = ['osx': 'macOS', 'ios': 'iOS', 'watchos': 'watchOS', 'tvos': 'tvOS'] carthageXcodeVersion = '10.2' docsSwiftVersion = '5.0' def installationTest(platform, test, language) { return { node('osx') { deleteDir() unstash 'source' if (test == "dynamic" || test == "static") { unstash "${language}-packaged" } sh """ archive=\$(echo \$PWD/realm-${language}-*.zip) cd examples/installation if [[ -f \$archive ]]; then mv \$archive . unzip realm-${language}-*zip find . -name 'realm-${language}-*' -print0 | xargs -J% mv % realm-${language}-latest fi export REALM_XCODE_VERSION=${carthageXcodeVersion} ./build.sh test-${platform}-${language}-${test} """ } } } def buildObjC(platform, outputDirectory=null) { return { node('osx') { deleteDir() unstash 'source' sh "XCMODE=xcpretty ./build.sh package-${platform}" dir(outputDirectory ?: "build/${platform}") { stash includes: "realm-framework-${platform}.zip", name: "${platform}-objc" } } } } def doBuild() { stage('prepare') { node('docker') { deleteDir() checkout( [ $class : 'GitSCM', branches : scm.branches, gitTool : 'native git', extensions : scm.extensions + [[$class: 'CleanCheckout'], [$class: 'SubmoduleOption', parentCredentials: true]], userRemoteConfigs: scm.userRemoteConfigs, ] ) stash includes: '**', name: 'source' } } stage('build') { def parallelBuilds = [ 'Docs': { node('osx') { deleteDir() unstash 'source' sh """ export REALM_SWIFT_VERSION=${docsSwiftVersion} ./scripts/reset-simulators.sh ./build.sh docs cd docs zip -r objc-docs.zip objc_output zip -r swift-docs.zip swift_output """ dir('docs') { archiveArtifacts artifacts: '*-docs.zip' } } }, 'Examples': { node('osx') { deleteDir() unstash 'source' sh 'XCMODE=xcpretty ./build.sh package-examples' stash includes: 'realm-examples.zip', name: 'examples' } }, 'macOS Obj-C': buildObjC('osx', 'build/DerivedData/Realm/Build/Products/Release'), 'iOS Obj-C': buildObjC('ios'), 'watchOS Obj-C': buildObjC('watchos'), 'tvOS Obj-C': buildObjC('tvos'), 'iOS Obj-C static': buildObjC('ios-static'), ] for (def p in platforms) { def platform = p def platformName = platformNames[platform] parallelBuilds["${platformName} Carthage"] = { node('osx') { deleteDir() unstash 'source' sh """ export REALM_XCODE_VERSION=${carthageXcodeVersion} . ./scripts/swift-version.sh set_xcode_and_swift_versions carthage build --no-skip-current --platform ${platform} carthage archive --output Carthage-${platform}.framework.zip """ stash includes: "Carthage-${platform}.framework.zip", name: "${platform}-carthage" } } } for (def p in platforms) { def platform = p def platformName = platformNames[platform] for (def v in xcodeVersions) { def xcodeVersion = v parallelBuilds["${platformName} Swift ${xcodeVersion}"] = { node('osx') { deleteDir() unstash 'source' sh "XCMODE=xcpretty ./build.sh package-${platform}-swift-${xcodeVersion}" dir("build/${platform}") { stash includes: "realm-swift-framework-${platform}-swift-${xcodeVersion}.zip", name: "${platform}-swift-${xcodeVersion}" } } } } } parallel parallelBuilds } stage('package') { parallel ( "Obj-C": { node('osx') { deleteDir() for (def platform in platforms) { unstash "${platform}-objc" } unstash 'ios-static-objc' unstash 'examples' unstash 'source' sh './build.sh package-release objc' stash include: 'realm-objc-*.zip', name: 'objc-packaged' archiveArtifacts artifacts: 'realm-objc-*.zip' } }, "Swift": { node('osx') { deleteDir() for (def platform in platforms) { for (def xcodeVersion in xcodeVersions) { unstash "${platform}-swift-${xcodeVersion}" } } unstash 'examples' unstash 'source' sh './build.sh package-release swift' sh 'rm realm-swift-framework-*.zip' stash include: 'realm-swift-*.zip', name: 'swift-packaged' archiveArtifacts artifacts: 'realm-swift-*.zip' } }, "Carthage": { node('osx') { deleteDir() for (def platform in platforms) { unstash "${platform}-carthage" } sh ''' for zip in Carthage-*.framework.zip; do ditto -xk $zip merged/ done ditto -ck merged/ Carthage.framework.zip ''' archiveArtifacts artifacts: 'Carthage.framework.zip' } } ) } stage('test') { def parallelBuilds = [ 'Test Examples': { node('osx') { deleteDir() // FIXME: Split Obj-C and Swift. unstash 'objc-packaged' unstash 'swift-packaged' def sha = params.sha sh """ curl -O https://raw.githubusercontent.com/realm/realm-cocoa/${sha}/build.sh mkdir -p scripts curl https://raw.githubusercontent.com/realm/realm-cocoa/${sha}/scripts/swift-version.sh -o scripts/swift-version.sh curl https://raw.githubusercontent.com/realm/realm-cocoa/${sha}/scripts/reset-simulators.sh -o scripts/reset-simulators.sh curl https://raw.githubusercontent.com/realm/realm-cocoa/${sha}/scripts/reset-simulators.rb -o scripts/reset-simulators.rb chmod +x scripts/reset-simulators.rb XCMODE=xcpretty sh build.sh package-test-examples """ } }, 'Test iOS static': { node('osx') { deleteDir() unstash 'source' sh 'XCMODE=xcpretty IS_RUNNING_PACKAGING=1 sh build.sh test-ios-static' } }, 'Test macOS': { node('osx') { deleteDir() unstash 'source' sh 'XCMODE=xcpretty sh build.sh test-osx' } } ] for (def platform in ["osx", "ios"]) { def platformName = platformNames[platform] for (def test in ["dynamic", "cocoapods", "carthage"]) { parallelBuilds["Installation - ${platformName} Obj-C ${test}"] = installationTest(platform, test, 'objc') } } parallelBuilds["Installation - iOS Obj-C static"] = installationTest('ios', 'static', 'objc') parallelBuilds["Installation - iOS Obj-C CocoaPods dynamic"] = installationTest('ios', 'cocoapods-dynamic', 'objc') for (def platform in ["osx", "ios"]) { def platformName = platformNames[platform] for (def test in ["cocoapods", "carthage"]) { parallelBuilds["Installation - ${platformName} Swift ${test}"] = installationTest(platform, test, 'swift') } } parallel parallelBuilds } } try { doBuild() } catch (e) { // If there was an exception thrown, the build failed currentBuild.result = "FAILED" throw e }