From cd83c7da6db5fc5962d24c06381d381300a35720 Mon Sep 17 00:00:00 2001 From: Igor Mandrigin Date: Fri, 21 Sep 2018 13:57:06 +0200 Subject: [PATCH] Update release Jenkinsfiles to use `cmn` library. Jenkinsfile.upload_release_android Jenkinsfile.upload_release_ios Signed-off-by: Igor Mandrigin --- ci/Jenkinsfile.upload_release_android | 146 +++++++++----------------- ci/Jenkinsfile.upload_release_ios | 113 ++++++-------------- ci/android.groovy | 4 +- ci/ios.groovy | 20 +++- fastlane/Fastfile | 4 +- 5 files changed, 104 insertions(+), 183 deletions(-) diff --git a/ci/Jenkinsfile.upload_release_android b/ci/Jenkinsfile.upload_release_android index a4049cfc24..75b62ad704 100644 --- a/ci/Jenkinsfile.upload_release_android +++ b/ci/Jenkinsfile.upload_release_android @@ -1,102 +1,54 @@ -// We need release builds for users who want to test apps, diawi removes old builds and limits downloads, hence the need for Artifactory. -// To see env: echo sh(returnStdout: true, script: 'env') +pipeline { + agent { label 'linux' } -env.LANG="en_US.UTF-8" -env.LANGUAGE="en_US.UTF-8" -env.LC_ALL="en_US.UTF-8" -env.FASTLANE_DISABLE_COLORS=1 -env.REALM_DISABLE_ANALYTICS=1 + options { + buildDiscarder(logRotator( + numToKeepStr: '60', + daysToKeepStr: '30', + artifactNumToKeepStr: '60', + )) + } -def installJSDeps() { - def attempt = 1 - def maxAttempts = 10 - def installed = false - while (!installed && attempt <= maxAttempts) { - println "#${attempt} attempt to install npm deps" - sh 'npm install' - installed = fileExists('node_modules/web3/index.js') - attemp = attempt + 1 + environment { + BUILD_PLATFORM = 'android' + LANG = 'en_US.UTF-8' + LANGUAGE = 'en_US.UTF-8' + LC_ALL = 'en_US.UTF-8' + FASTLANE_DISABLE_COLORS = 1 + REALM_DISABLE_ANALYTICS = 1 + BUNDLE_PATH = "${HOME}/.bundle" + ANDROID_HOME = '/usr/lib/android-sdk' + ANDROID_SDK_ROOT = '/usr/lib/android-sdk' + ANDROID_NDK = '/usr/lib/android-ndk' + ANDROID_NDK_HOME = '/usr/lib/android-ndk' + } + + stages { + stage('Prep') { + steps { script { + /* Necessary to load methods */ + mobile = load 'ci/mobile.groovy' + cmn = load 'ci/common.groovy' + mobile.prep('release') + } } } -} - -timeout(90) { - node ('fastlane'){ - def version - def build_no - - load "$HOME/env.groovy" - - try { - - stage('Git & Dependencies') { - slackSend color: 'good', message: BRANCH_NAME + ' build started. ' + env.BUILD_URL - - if (!BRANCH_NAME.startsWith("release/")){ - error "Wrong branch name format: " + BRANCH_NAME + ", but it should be `release/version`" - } - - checkout scm - - sh 'git fetch --tags' - - sh 'rm -rf node_modules' - sh 'cp .env.prod .env' - - sh 'scripts/prepare-for-platform.sh mobile' - version = readFile("${env.WORKSPACE}/VERSION").trim() - installJSDeps() - - sh 'mvn -f modules/react-native-status/ios/RCTStatus dependency:unpack' - sh 'cd ios && pod install && cd ..' - } - - stage('Tag Build') { - withCredentials([[ - $class: 'UsernamePasswordMultiBinding', - credentialsId: 'status-im-auto', - usernameVariable: 'GIT_USER', - passwordVariable: 'GIT_PASS' - ]]) { - build_no = sh( - returnStdout: true, - script: './scripts/build_no.sh --increment' - ).trim() - } - } - - stage('Tests') { - sh 'lein test-cljs' - } - - stage('Build') { - sh 'lein prod-build' - } - - stage('Build (Android)') { - sh 'cd android && ./gradlew react-native-android:installArchives && ./gradlew assembleRelease -PreleaseVersion=' + version - } - - stage('Deploy (Android)') { - withCredentials([ - string( - credentialsId: "SUPPLY_JSON_KEY_DATA", - variable: 'GOOGLE_PLAY_JSON_KEY' - ), - string( - credentialsId: "SLACK_URL", - variable: 'SLACK_URL' - ) - ]) { - sh ('bundle exec fastlane android release') - } - } - } catch (e) { - slackSend color: 'bad', message: 'Release build failed uploading to the Play Market. ' + env.BUILD_URL - throw e - } - - stage('Slack Notification') { - slackSend color: 'good', message: 'Release build ' + version + ' succesfully aploade to the Play Market' - } + stage('Lint') { + steps { script { cmn.runLint() } } } + stage('Tests') { + steps { script { cmn.runTests() } } + } + stage('Build') { + steps { script { mobile.leinBuild('android') } } + } + stage('Compile') { + steps { script { apk = mobile.android.compile('release') } } + } + stage('Archive') { + steps { script { archiveArtifacts apk } } + } + stage('Upload') { + steps { script { mobile.android.uploadToPlayStore('release') } } + } + } } diff --git a/ci/Jenkinsfile.upload_release_ios b/ci/Jenkinsfile.upload_release_ios index 57060b1a7e..8602448795 100644 --- a/ci/Jenkinsfile.upload_release_ios +++ b/ci/Jenkinsfile.upload_release_ios @@ -1,91 +1,48 @@ -// We need release builds for users who want to test apps, diawi removes old builds and limits downloads, hence the need for Artifactory. -// To see env: echo sh(returnStdout: true, script: 'env') +pipeline { + agent { label 'fastlane' } -env.LANG="en_US.UTF-8" -env.LANGUAGE="en_US.UTF-8" -env.LC_ALL="en_US.UTF-8" -env.FASTLANE_DISABLE_COLORS=1 -env.REALM_DISABLE_ANALYTICS=1 - -def installJSDeps() { - def attempt = 1 - def maxAttempts = 10 - def installed = false - while (!installed && attempt <= maxAttempts) { - println "#${attempt} attempt to install npm deps" - sh 'npm install' - installed = fileExists('node_modules/web3/index.js') - attemp = attempt + 1 + options { + buildDiscarder( + logRotator( + numToKeepStr: '30', + daysToKeepStr: '30', + artifactNumToKeepStr: '30', + )) } -} -timeout(90) { - node ('fastlane'){ - def version - def build_no + environment { + BUILD_PLATFORM = 'ios' + LANG = 'en_US.UTF-8' + LANGUAGE = 'en_US.UTF-8' + LC_ALL = 'en_US.UTF-8' + FASTLANE_DISABLE_COLORS=1 + REALM_DISABLE_ANALYTICS=1 + BUNDLE_PATH = "${HOME}/.bundle" + } - load "$HOME/env.groovy" - - try { - stage('Git & Dependencies') { - slackSend color: 'good', message: BRANCH_NAME + ' build started. ' + env.BUILD_URL - - if (!BRANCH_NAME.startsWith("release/")){ - error "Wrong branch name format: " + BRANCH_NAME + ", but it should be `release/version`" - } - - checkout scm - - sh 'git fetch --tags' - - sh 'rm -rf node_modules' - sh 'cp .env.prod .env' - - sh 'scripts/prepare-for-platform.sh mobile' - version = readFile("${env.WORKSPACE}/VERSION").trim() - installJSDeps() - - sh 'mvn -f modules/react-native-status/ios/RCTStatus dependency:unpack' - sh 'cd ios && pod install && cd ..' + stages { + stage('Prep') { + steps { script { + if (!BRANCH_NAME.startsWith("release/")){ + error "Wrong branch name format: " + BRANCH_NAME + ", but it should be `release/`" + } + /* Necessary to load methods */ + mobile = load 'ci/mobile.groovy' + cmn = load 'ci/common.groovy' + mobile.prep('release') + } } } - - stage('Tag Build') { - withCredentials([[ - $class: 'UsernamePasswordMultiBinding', - credentialsId: 'status-im-auto', - usernameVariable: 'GIT_USER', - passwordVariable: 'GIT_PASS' - ]]) { - build_no = sh( - returnStdout: true, - script: './scripts/build_no.sh --increment' - ).trim() - } + stage('Lint') { + steps { script { cmn.runLint() } } } - stage('Tests') { - sh 'lein test-cljs' + steps { script { cmn.runTests() } } } - stage('Build') { - sh 'lein prod-build' + steps { script { mobile.leinBuild('ios') } } } - - stage('Build & TestFlight (iOS)') { - withCredentials([ - string(credentialsId: "slave-pass-${env.NODE_NAME}", variable: 'KEYCHAIN_PASSWORD'), - string(credentialsId: "SLACK_URL", variable: 'SLACK_URL'), - string(credentialsId: 'FASTLANE_PASSWORD', variable: 'FASTLANE_PASSWORD'), - string(credentialsId: 'APPLE_ID', variable: 'APPLE_ID'), - string(credentialsId: 'fastlane-match-password', variable:'MATCH_PASSWORD')]) { - sh "plutil -replace CFBundleShortVersionString -string ${version} ios/StatusIm/Info.plist" - sh "plutil -replace CFBundleVersion -string ${build_no} ios/StatusIm/Info.plist" - sh 'fastlane ios release' - } + stage('Compile') { + steps { script { api = mobile.ios.compile('testflight') } } } - - stage('Slack Notification') { - slackSend color: 'good', message: 'Release build ' + version + ' succesfully aploade to iTunes Connect' - } } } diff --git a/ci/android.groovy b/ci/android.groovy index 1976863be3..201842e40d 100644 --- a/ci/android.groovy +++ b/ci/android.groovy @@ -14,12 +14,12 @@ def compile(type = 'nightly') { return pkg } -def uploadToPlayStore() { +def uploadToPlayStore(type = 'nightly') { withCredentials([ string(credentialsId: "SUPPLY_JSON_KEY_DATA", variable: 'GOOGLE_PLAY_JSON_KEY'), string(credentialsId: "SLACK_URL", variable: 'SLACK_URL') ]) { - sh 'bundle exec fastlane android nightly' + sh "bundle exec fastlane android ${type}" } } diff --git a/ci/ios.groovy b/ci/ios.groovy index 1958e33023..797f75c896 100644 --- a/ci/ios.groovy +++ b/ci/ios.groovy @@ -5,7 +5,16 @@ def plutil(name, value) { } def compile(type = 'nightly') { - def target = (type == 'release' ? 'adhoc' : 'nightly') + def target = 'nightly' + + if (type == 'release') { + target = 'adhoc' + } + + if (type == 'testflight') { + target = 'release' + } + /* configure build metadata */ plutil('CFBundleShortVersionString', common.version()) plutil('CFBundleVersion', common.tagBuild()) @@ -20,9 +29,12 @@ def compile(type = 'nightly') { ]) { sh "bundle exec fastlane ios ${target}" } - def pkg = common.pkgFilename(type, 'ipa') - sh "cp status-adhoc/StatusIm.ipa ${pkg}" - return pkg + if (type != 'testflight') { + def pkg = common.pkgFilename(type, 'ipa') + sh "cp status-adhoc/StatusIm.ipa ${pkg}" + return pkg + } + return '' } def uploadToDiawi() { diff --git a/fastlane/Fastfile b/fastlane/Fastfile index d702a620f5..6daafb7715 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -5,12 +5,12 @@ # # https://docs.fastlane.tools/actions # +# Fastlane is updated quite frequently with security patches +# update_fastlane # There are a few env variables defined in the .env file in # this directory (fastlane/.env) -# Fastlane is updated quite frequently with security patches -update_fastlane # unlocks keychain if KEYCHAIN_PASSWORD variable is present # (to be used on CI machines)