From e83adf1b4620487d0ec5e6cee5445a11d6b75a88 Mon Sep 17 00:00:00 2001 From: David Balatero Date: Wed, 29 Nov 2017 12:45:46 -0800 Subject: [PATCH] Run build script against the develop branch --- Jenkinsfile | 73 +++++++++++------------- Jenkinsfile.nightly | 2 - ios/StatusIm.xcodeproj/project.pbxproj | 2 +- ios/scripts/set_xcode_version.sh | 79 ++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 44 deletions(-) create mode 100755 ios/scripts/set_xcode_version.sh diff --git a/Jenkinsfile b/Jenkinsfile index 88d38c9e12..3e035b023d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,22 +1,22 @@ env.LANG="en_US.UTF-8" env.LANGUAGE="en_US.UTF-8" env.LC_ALL="en_US.UTF-8" + node ('macos1') { def apkUrl = '' def ipaUrl = '' def testPassed = true def branch; - load "$HOME/env.groovy" + load "$HOME/env.groovy" try { stage('Git & Dependencies') { slackSend color: 'good', message: BRANCH_NAME + ' build started. ' + env.BUILD_URL + git([url: 'https://github.com/status-im/status-react.git', branch: BRANCH_NAME]) - // Checkout master because used for iOS Plist version information - sh 'git checkout -- .' - sh 'git checkout master' + sh 'git checkout ' + BRANCH_NAME sh 'rm -rf node_modules' sh 'cp .env.jenkins .env' @@ -34,54 +34,45 @@ node ('macos1') { sh 'lein prod-build' } - // Android - stage('Build (Android)') { - sh 'cd android && ./gradlew assembleRelease' - } - stage('Deploy (Android)') { - withCredentials([string(credentialsId: 'diawi-token', variable: 'token')]) { - def job = sh(returnStdout: true, script: 'curl https://upload.diawi.com/ -F token='+token+' -F file=@android/app/build/outputs/apk/app-release.apk -F find_by_udid=0 -F wall_of_apps=0 | jq -r ".job"').trim() - sh 'sleep 10' - def hash = sh(returnStdout: true, script: "curl -vvv 'https://upload.diawi.com/status?token="+token+"&job="+job+"'|jq -r '.hash'").trim() - apkUrl = 'https://i.diawi.com/' + hash + // Android + stage('Build (Android)') { + sh 'cd android && ./gradlew assembleRelease' + } - sh ('echo ARTIFACT Android: ' + apkUrl) - } - } + stage('Deploy (Android)') { + withCredentials([string(credentialsId: 'diawi-token', variable: 'token')]) { + def job = sh(returnStdout: true, script: 'curl https://upload.diawi.com/ -F token='+token+' -F file=@android/app/build/outputs/apk/app-release.apk -F find_by_udid=0 -F wall_of_apps=0 | jq -r ".job"').trim() + sh 'sleep 10' + def hash = sh(returnStdout: true, script: "curl -vvv 'https://upload.diawi.com/status?token="+token+"&job="+job+"'|jq -r '.hash'").trim() + apkUrl = 'https://i.diawi.com/' + hash - // try { - // stage('Test (Android)') { - // sauce('b9aded57-5cc1-4f6b-b5ea-42d989987852') { - // sh 'cd test/appium && mvn -DapkUrl=' + apkUrl + ' test' - // saucePublisher() - // } - // } - // } catch(e) { - // testPassed = false - // } + sh ('echo ARTIFACT Android: ' + apkUrl) + } + } // iOS stage('Build (iOS)') { - sh 'export RCT_NO_LAUNCH_PACKAGER=true && xcodebuild -workspace ios/StatusIm.xcworkspace -scheme StatusIm -configuration release -archivePath status clean archive' - sh 'xcodebuild -exportArchive -exportPath status -archivePath status.xcarchive -exportOptionsPlist ~/archive.plist' + sh 'export RCT_NO_LAUNCH_PACKAGER=true && xcodebuild -workspace ios/StatusIm.xcworkspace -scheme StatusIm -configuration release -archivePath status clean archive' + sh 'xcodebuild -exportArchive -exportPath status -archivePath status.xcarchive -exportOptionsPlist ~/archive.plist' } + stage('Deploy (iOS)') { - withCredentials([string(credentialsId: 'diawi-token', variable: 'token')]) { - def job = sh(returnStdout: true, script: 'curl https://upload.diawi.com/ -F token='+token+' -F file=@status/StatusIm.ipa -F find_by_udid=0 -F wall_of_apps=0 | jq -r ".job"').trim() - sh 'sleep 10' - def hash = sh(returnStdout: true, script: "curl -vvv 'https://upload.diawi.com/status?token="+token+"&job="+job+"'|jq -r '.hash'").trim() - ipaUrl = 'https://i.diawi.com/' + hash + withCredentials([string(credentialsId: 'diawi-token', variable: 'token')]) { + def job = sh(returnStdout: true, script: 'curl https://upload.diawi.com/ -F token='+token+' -F file=@status/StatusIm.ipa -F find_by_udid=0 -F wall_of_apps=0 | jq -r ".job"').trim() + sh 'sleep 10' + def hash = sh(returnStdout: true, script: "curl -vvv 'https://upload.diawi.com/status?token="+token+"&job="+job+"'|jq -r '.hash'").trim() + ipaUrl = 'https://i.diawi.com/' + hash - sh ('echo ARTIFACT iOS: ' + ipaUrl) - - } + sh ('echo ARTIFACT iOS: ' + ipaUrl) + } } stage('Slack Notification') { - def c = (testPassed ? 'good' : 'warning' ) - slackSend color: c, message: 'Branch: ' + BRANCH_NAME + - '\nAndroid: ' + apkUrl + - '\niOS: ' + ipaUrl + def c = (testPassed ? 'good' : 'warning' ) + + slackSend color: c, message: 'Branch: ' + BRANCH_NAME + + '\nAndroid: ' + apkUrl + + '\niOS: ' + ipaUrl } } catch (e) { diff --git a/Jenkinsfile.nightly b/Jenkinsfile.nightly index c20849953f..400c8b2a67 100644 --- a/Jenkinsfile.nightly +++ b/Jenkinsfile.nightly @@ -18,9 +18,7 @@ node ('macos1'){ slackSend color: 'good', message: 'Nightly build started. ' + env.BUILD_URL git([url: 'https://github.com/status-im/status-react.git', branch: 'develop']) // Checkout master because used for iOS Plist version information - sh 'git checkout -- .' sh 'git fetch --tags' - sh 'git checkout master' sh 'git checkout ' + 'develop' sh 'rm -rf node_modules' sh 'cp .env.jenkins .env' diff --git a/ios/StatusIm.xcodeproj/project.pbxproj b/ios/StatusIm.xcodeproj/project.pbxproj index bb70e9f886..ae3b69ed79 100644 --- a/ios/StatusIm.xcodeproj/project.pbxproj +++ b/ios/StatusIm.xcodeproj/project.pbxproj @@ -1869,7 +1869,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "#!/bin/bash\n\n# This script automatically sets the version and short version string of\n# an Xcode project from the Git repository containing the project.\n#\n# To use this script in Xcode, add the script's path to a \"Run Script\" build\n# phase for your application target.\n\nset -o errexit\nset -o nounset\n\n# First, check for git in $PATH\nhash git 2>/dev/null || { echo >&2 \"Git required, not installed. Aborting build number update script.\"; exit 0; }\n\n# Alternatively, we could use Xcode's copy of the Git binary,\n# but old Xcodes don't have this.\n#GIT=$(xcrun -find git)\n\n# Run Script build phases that operate on product files of the target that defines them should use the value of this build setting [TARGET_BUILD_DIR]. But Run Script build phases that operate on product files of other targets should use ?BUILT_PRODUCTS_DIR? instead.\nINFO_PLIST=\"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}\"\n\n# Build version (closest-tag-or-branch \"-\" commits-since-tag \"-\" short-hash dirty-flag)\nBUILD_VERSION=$(git describe --tags --always --dirty=+)\n\n# Use the latest tag for short version (expected tag format \"vn[.n[.n]]\")\n# or if there are no tags, we make up version 0.0.\nLATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null) || LATEST_TAG=\"HEAD\"\nif [ $LATEST_TAG = \"HEAD\" ]\nthen COMMIT_COUNT=$(git rev-list --count HEAD)\n LATEST_TAG=\"0.0.$COMMIT_COUNT\"\n COMMIT_COUNT_SINCE_TAG=0\nelse\n COMMIT_COUNT_SINCE_TAG=$(git rev-list --count ${LATEST_TAG}..)\n LATEST_TAG=${LATEST_TAG##v} # Remove the \"v\" from the front of the tag\nfi\nif [ $COMMIT_COUNT_SINCE_TAG = 0 ]; then\n SHORT_VERSION=\"$LATEST_TAG\"\nelse\n # increment final digit of tag and append \"d\" + commit-count-since-tag\n # e.g. commit after 1.0 is 1.1d1, commit after 1.0.0 is 1.0.1d1\n # this is the bit that requires /bin/bash\n OLD_IFS=$IFS\n IFS=\".\"\n VERSION_PARTS=($LATEST_TAG)\n LAST_PART=$((${#VERSION_PARTS[@]}-1))\n VERSION_PARTS[$LAST_PART]=$((${VERSION_PARTS[${LAST_PART}]}+1))\n SHORT_VERSION=\"${VERSION_PARTS[*]}d${COMMIT_COUNT_SINCE_TAG}\"\n IFS=$OLD_IFS\nfi\n \n# Bundle version (commits-on-master[-until-branch \".\" commits-on-branch])\n# Assumes that two release branches will not diverge from the same commit on master.\nif [ $(git rev-parse --abbrev-ref HEAD) = \"master\" ]; then\n MASTER_COMMIT_COUNT=$(git rev-list --count HEAD)\n BRANCH_COMMIT_COUNT=0\n BUNDLE_VERSION=\"$MASTER_COMMIT_COUNT\"\nelse\n MASTER_COMMIT_COUNT=$(git rev-list --count $(git rev-list master.. | tail -n 1)^)\n BRANCH_COMMIT_COUNT=$(git rev-list --count master..)\n if [ $BRANCH_COMMIT_COUNT = 0 ]\n then BUNDLE_VERSION=\"$MASTER_COMMIT_COUNT\"\n else BUNDLE_VERSION=\"${MASTER_COMMIT_COUNT}.${BRANCH_COMMIT_COUNT}\"\n fi\nfi\n \n# For debugging:\necho \"BUILD VERSION: $BUILD_VERSION\"\necho \"LATEST_TAG: $LATEST_TAG\"\necho \"COMMIT_COUNT_SINCE_TAG: $COMMIT_COUNT_SINCE_TAG\"\necho \"SHORT VERSION: $SHORT_VERSION\"\necho \"MASTER_COMMIT_COUNT: $MASTER_COMMIT_COUNT\"\necho \"BRANCH_COMMIT_COUNT: $BRANCH_COMMIT_COUNT\"\necho \"BUNDLE_VERSION: $BUNDLE_VERSION\"\n \n/usr/libexec/PlistBuddy -c \"Add :CFBundleBuildVersion string $BUILD_VERSION\" \"$INFO_PLIST\" 2>/dev/null || /usr/libexec/PlistBuddy -c \"Set :CFBundleBuildVersion $BUILD_VERSION\" \"$INFO_PLIST\"\n/usr/libexec/PlistBuddy -c \"Set :CFBundleShortVersionString $SHORT_VERSION\" \"$INFO_PLIST\"\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $BUNDLE_VERSION\" \"$INFO_PLIST\""; + shellScript = "#!/bin/bash\n\nsource \"${PROJECT_DIR}/scripts/set_xcode_version.sh\""; }; E883D1F9B22B8292CC879292 /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; diff --git a/ios/scripts/set_xcode_version.sh b/ios/scripts/set_xcode_version.sh new file mode 100755 index 0000000000..dbc5cd74f0 --- /dev/null +++ b/ios/scripts/set_xcode_version.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +# This script automatically sets the version and short version string of +# an Xcode project from the Git repository containing the project. +# +# To use this script in Xcode, add the script's path to a "Run Script" build +# phase for your application target. + +MAIN_GIT_BRANCH="develop" # status-react uses develop instead of master as the main dev tree + +set -o errexit +set -o nounset + +# First, check for git in $PATH +hash git 2>/dev/null || { echo >&2 "Git required, not installed. Aborting build number update script."; exit 0; } + +# Alternatively, we could use Xcode's copy of the Git binary, +# but old Xcodes don't have this. +#GIT=$(xcrun -find git) + +# Run Script build phases that operate on product files of the target that defines them should use the value of this build setting [TARGET_BUILD_DIR]. But Run Script build phases that operate on product files of other targets should use ?BUILT_PRODUCTS_DIR? instead. +INFO_PLIST="${TARGET_BUILD_DIR}/${INFOPLIST_PATH}" + +# Build version (closest-tag-or-branch "-" commits-since-tag "-" short-hash dirty-flag) +BUILD_VERSION=$(git describe --tags --always --dirty=+) + +# Use the latest tag for short version (expected tag format "vn[.n[.n]]") +# or if there are no tags, we make up version 0.0. +LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null) || LATEST_TAG="HEAD" +if [ $LATEST_TAG = "HEAD" ] +then COMMIT_COUNT=$(git rev-list --count HEAD) + LATEST_TAG="0.0.$COMMIT_COUNT" + COMMIT_COUNT_SINCE_TAG=0 +else + COMMIT_COUNT_SINCE_TAG=$(git rev-list --count ${LATEST_TAG}..) + LATEST_TAG=${LATEST_TAG##v} # Remove the "v" from the front of the tag +fi +if [ $COMMIT_COUNT_SINCE_TAG = 0 ]; then + SHORT_VERSION="$LATEST_TAG" +else + # increment final digit of tag and append "d" + commit-count-since-tag + # e.g. commit after 1.0 is 1.1d1, commit after 1.0.0 is 1.0.1d1 + # this is the bit that requires /bin/bash + OLD_IFS=$IFS + IFS="." + VERSION_PARTS=($LATEST_TAG) + LAST_PART=$((${#VERSION_PARTS[@]}-1)) + VERSION_PARTS[$LAST_PART]=$((${VERSION_PARTS[${LAST_PART}]}+1)) + SHORT_VERSION="${VERSION_PARTS[*]}d${COMMIT_COUNT_SINCE_TAG}" + IFS=$OLD_IFS +fi + +# Bundle version (commits-on-master[-until-branch "." commits-on-branch]) +# Assumes that two release branches will not diverge from the same commit on master. +if [ $(git rev-parse --abbrev-ref HEAD) = "$MAIN_GIT_BRANCH" ]; then + MASTER_COMMIT_COUNT=$(git rev-list --count HEAD) + BRANCH_COMMIT_COUNT=0 + BUNDLE_VERSION="$MASTER_COMMIT_COUNT" +else + MASTER_COMMIT_COUNT=$(git rev-list --count $(git rev-list ${MAIN_GIT_BRANCH}.. | tail -n 1)^) + BRANCH_COMMIT_COUNT=$(git rev-list --count ${MAIN_GIT_BRANCH}..) + if [ $BRANCH_COMMIT_COUNT = 0 ] + then BUNDLE_VERSION="$MASTER_COMMIT_COUNT" + else BUNDLE_VERSION="${MASTER_COMMIT_COUNT}.${BRANCH_COMMIT_COUNT}" + fi +fi + +# For debugging: +echo "BUILD VERSION: $BUILD_VERSION" +echo "LATEST_TAG: $LATEST_TAG" +echo "COMMIT_COUNT_SINCE_TAG: $COMMIT_COUNT_SINCE_TAG" +echo "SHORT VERSION: $SHORT_VERSION" +echo "MASTER_COMMIT_COUNT: $MASTER_COMMIT_COUNT" +echo "BRANCH_COMMIT_COUNT: $BRANCH_COMMIT_COUNT" +echo "BUNDLE_VERSION: $BUNDLE_VERSION" + +/usr/libexec/PlistBuddy -c "Add :CFBundleBuildVersion string $BUILD_VERSION" "$INFO_PLIST" 2>/dev/null || /usr/libexec/PlistBuddy -c "Set :CFBundleBuildVersion $BUILD_VERSION" "$INFO_PLIST" +/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $SHORT_VERSION" "$INFO_PLIST" +/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUNDLE_VERSION" "$INFO_PLIST"