From 6e80321f6c6352bf12828d1a89461a8a90c8637c Mon Sep 17 00:00:00 2001 From: Igor Mandrigin Date: Wed, 15 Aug 2018 08:15:45 +0200 Subject: [PATCH] Fix diawi upload for nightlies. BRANCH_NAME isn't set for nightly builds, fix fastlane script accordingly. Signed-off-by: Igor Mandrigin --- ci/Jenkinsfile | 5 --- ci/Jenkinsfile.nightly_fastlane | 27 +++++++------- ci/Jenkinsfile.parameters | 3 ++ ci/Jenkinsfile.release | 25 ++++++------- fastlane/Fastfile | 64 +++++++++++++++++++++++++++------ 5 files changed, 84 insertions(+), 40 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index de87da796c..1ecc4e27ce 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -25,11 +25,6 @@ def installJSDeps() { timeout(90) { node ('fastlane') { - def apkUrl = '' - def ipaUrl = '' - def testPassed = true - def branch; - load "$HOME/env.groovy" try { diff --git a/ci/Jenkinsfile.nightly_fastlane b/ci/Jenkinsfile.nightly_fastlane index 0079f270a3..8d4839c730 100644 --- a/ci/Jenkinsfile.nightly_fastlane +++ b/ci/Jenkinsfile.nightly_fastlane @@ -28,6 +28,7 @@ def installJSDeps() { timeout(90) { node ('fastlane'){ def apkUrl = '' + def testApkUrl = '' def ipaUrl = '' def testPassed = true def version @@ -129,6 +130,9 @@ timeout(90) { string(credentialsId: 'SLACK_JENKINS_WEBHOOK', variable: 'SLACK_URL') ]) { sh 'fastlane ios upload_diawi' + + env.WORKSPACE = pwd() + ipaUrl = readFile "${env.WORKSPACE}/fastlane/diawi.out" } } } catch (e) { @@ -151,18 +155,17 @@ timeout(90) { } stage('Upload apk for e2e tests') { - if (env.CHANGE_ID != null) { - env.SAUCE_LABS_APK = 'im.status.ethereum-e2e-' + env.CHANGE_ID + '.apk' - withCredentials([ - string(credentialsId: 'SAUCE_ACCESS_KEY', variable: 'SAUCE_ACCESS_KEY'), - string(credentialsId: 'SAUCE_USERNAME', variable: 'SAUCE_USERNAME'), - string(credentialsId: 'diawi-token', variable: 'DIAWI_TOKEN'), - string(credentialsId: 'GIT_HUB_TOKEN', variable: 'GITHUB_TOKEN'), - string(credentialsId: 'SLACK_JENKINS_WEBHOOK', variable: 'SLACK_URL') - ]) { - sh 'fastlane android saucelabs' - sh 'fastlane android upload_diawi' - } + env.SAUCE_LABS_APK = 'im.status.ethereum-e2e-' + shortCommit + '.apk' + withCredentials([ + string(credentialsId: 'SAUCE_ACCESS_KEY', variable: 'SAUCE_ACCESS_KEY'), + string(credentialsId: 'SAUCE_USERNAME', variable: 'SAUCE_USERNAME'), + string(credentialsId: 'diawi-token', variable: 'DIAWI_TOKEN'), + string(credentialsId: 'GIT_HUB_TOKEN', variable: 'GITHUB_TOKEN'), + string(credentialsId: 'SLACK_JENKINS_WEBHOOK', variable: 'SLACK_URL') + ]) { + sh 'fastlane android saucelabs' + sh 'fastlane android upload_diawi' + testApkUrl = readFile "${env.WORKSPACE}/fastlane/diawi.out" } } diff --git a/ci/Jenkinsfile.parameters b/ci/Jenkinsfile.parameters index e03663f1f7..d671a4aadf 100644 --- a/ci/Jenkinsfile.parameters +++ b/ci/Jenkinsfile.parameters @@ -105,6 +105,9 @@ timeout(90) { string(credentialsId: 'SLACK_JENKINS_WEBHOOK', variable: 'SLACK_URL') ]) { sh 'fastlane ios upload_diawi' + + env.WORKSPACE = pwd() + ipaUrl = readFile "${env.WORKSPACE}/fastlane/diawi.out" } } diff --git a/ci/Jenkinsfile.release b/ci/Jenkinsfile.release index 711a149454..edde35faa4 100644 --- a/ci/Jenkinsfile.release +++ b/ci/Jenkinsfile.release @@ -115,6 +115,9 @@ timeout(90) { string(credentialsId: 'SLACK_JENKINS_WEBHOOK', variable: 'SLACK_URL') ]) { sh 'fastlane ios upload_diawi' + + env.WORKSPACE = pwd() + ipaUrl = readFile "${env.WORKSPACE}/fastlane/diawi.out" } } @@ -133,18 +136,16 @@ timeout(90) { } stage('Upload apk for e2e tests') { - if (env.CHANGE_ID != null) { - env.SAUCE_LABS_APK = 'im.status.ethereum-e2e-' + env.CHANGE_ID + '.apk' - withCredentials([ - string(credentialsId: 'SAUCE_ACCESS_KEY', variable: 'SAUCE_ACCESS_KEY'), - string(credentialsId: 'SAUCE_USERNAME', variable: 'SAUCE_USERNAME'), - string(credentialsId: 'diawi-token', variable: 'DIAWI_TOKEN'), - string(credentialsId: 'GIT_HUB_TOKEN', variable: 'GITHUB_TOKEN'), - string(credentialsId: 'SLACK_JENKINS_WEBHOOK', variable: 'SLACK_URL') - ]) { - sh 'fastlane android saucelabs' - sh 'fastlane android upload_diawi' - } + env.SAUCE_LABS_APK = 'im.status.ethereum-e2e-' + shortCommit + '.apk' + withCredentials([ + string(credentialsId: 'SAUCE_ACCESS_KEY', variable: 'SAUCE_ACCESS_KEY'), + string(credentialsId: 'SAUCE_USERNAME', variable: 'SAUCE_USERNAME'), + string(credentialsId: 'diawi-token', variable: 'DIAWI_TOKEN'), + string(credentialsId: 'GIT_HUB_TOKEN', variable: 'GITHUB_TOKEN'), + string(credentialsId: 'SLACK_JENKINS_WEBHOOK', variable: 'SLACK_URL') + ]) { + sh 'fastlane android saucelabs' + sh 'fastlane android upload_diawi' } } diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 3d370b3fc3..9407efd9af 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -22,6 +22,15 @@ def unlock_keychain_if_needed end +def clean_up_realm_core_ios + realm_dir ="../node_modules/realm/vendor/realm-ios/" + if Dir.exists?(realm_dir) + FileUtils.remove_dir(realm_dir) + end + FileUtils.mkdir(realm_dir) +end + + # uploads `file` to sauce labs (overwrites if there is anoter file from the # same commit) def upload_to_saucelabs(file) @@ -58,6 +67,9 @@ def build_ios_adhoc readonly: true, keychain_name: "login.keychain" ) + + workaround_realm_core_sync_issues + build_ios_app( scheme: "StatusIm", workspace: "ios/StatusIm.xcworkspace", @@ -70,8 +82,10 @@ end def notify_about_new_build(source, url) + branch_name = ENV["BRANCH_NAME"] + branch_name = "develop" if branch_name.nil? - msg = "Branch: " + ENV["BRANCH_NAME"] + ", " + msg = "Branch: " + branch_name + ", " if source.end_with? ".ipa" msg = msg + "iOS build uploaded to diawi: " + url @@ -84,15 +98,21 @@ def notify_about_new_build(source, url) slack_url: ENV["SLACK_URL"] ) - github_api( - server_url: "https://api.github.com", - api_token: ENV["GITHUB_TOKEN"], - http_method: "POST", - path: "/repos/status-im/status-react/issues/" + ENV["CHANGE_ID"] + "/comments", - body: { - "body": msg - } - ) + change_id = ENV["CHANGE_ID"] + + unless change_id.nil? + + github_api( + server_url: "https://api.github.com", + api_token: ENV["GITHUB_TOKEN"], + http_method: "POST", + path: "/repos/status-im/status-react/issues/" + change_id + "/comments", + body: { + "body": msg + } + ) + + end end @@ -103,13 +123,14 @@ def upload_to_diawi_and_notify(source) file: source ) + File.write("diawi.out", lane_context[SharedValues::UPLOADED_FILE_LINK_TO_DIAWI]) + notify_about_new_build( source, lane_context[SharedValues::UPLOADED_FILE_LINK_TO_DIAWI] ) end - platform :ios do desc "`fastlane ios adhoc` - ad-hoc lane for iOS." desc "This lane is used PRs, Releases, etc." @@ -132,6 +153,9 @@ platform :ios do readonly: true, keychain_name: "login.keychain" ) + + workaround_realm_core_sync_issues + build_ios_app( scheme: "StatusIm", workspace: "ios/StatusIm.xcworkspace", @@ -162,6 +186,9 @@ platform :ios do readonly: true, keychain_name: "login.keychain" ) + + workaround_realm_core_sync_issues + build_ios_app( scheme: "StatusIm", workspace: "ios/StatusIm.xcworkspace", @@ -198,11 +225,24 @@ platform :ios do desc "expects to have a github token as GITHUB_TOKEN env variable" desc "expects to have a slack webhook URL as SLACK_URL env variable" desc "will fails if file isn't there" + desc "---" + desc "Output: writes `fastlane/diawi.out` file url of the uploded file" lane :upload_diawi do upload_to_diawi_and_notify( "status-adhoc/StatusIm.ipa" ) end + + + desc "This fastlane step is a workaround!" + desc "every now and then Realm fails on iOS on the 'Download Core` step" + desc "the issue is being `node_modules/realm/vendor/realm-ios/` dir not being empty" + desc "but missing the lock file" + desc "as a workaround, we clean up this directory" + lane :workaround_realm_core_sync_issues do + clean_up_realm_core_ios + end + end @@ -242,6 +282,8 @@ platform :android do desc "expects to have a github token as GITHUB_TOKEN env variable" desc "expects to have a slack webhook URL as SLACK_URL env variable" desc "will fails if file isn't there" + desc "---" + desc "Output: writes `fastlane/diawi.out` file url of the uploded file" lane :upload_diawi do upload_to_diawi_and_notify( "android/app/build/outputs/apk/release/app-release.apk"