diff --git a/Jenkinsfile.release b/Jenkinsfile.release index 90e93abe13..9e92384a4b 100644 --- a/Jenkinsfile.release +++ b/Jenkinsfile.release @@ -21,6 +21,7 @@ node ('macos1'){ def apkUrl = '' def ipaUrl = '' def testPassed = true + def version load "$HOME/env.groovy" @@ -29,6 +30,13 @@ node ('macos1'){ 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`" + } + + version = BRANCH_NAME.substring(8) + sh 'echo "' + version + '" > .version' + checkout scm sh 'git fetch --tags' @@ -51,10 +59,13 @@ node ('macos1'){ } stage('Build (Android)') { - sh 'cd android && ./gradlew assembleRelease' + sh 'cd android && ./gradlew assembleRelease -PreleaseVersion=' + version } stage('Build (iOS)') { + def build_no = sh(returnStdout: true, script: 'git rev-list --count HEAD').trim() + sh ('plutil -replace CFBundleShortVersionString -string ' + version + ' ios/StatusIm/Info.plist') + sh ('plutil -replace CFBundleVersion -string ' + build_no + ' ios/StatusIm/Info.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' } diff --git a/Jenkinsfile.upload_release b/Jenkinsfile.upload_release index 456b760e58..93bfb0dda4 100644 --- a/Jenkinsfile.upload_release +++ b/Jenkinsfile.upload_release @@ -35,6 +35,7 @@ node ('macos1'){ } version = BRANCH_NAME.substring(8) + sh 'echo "' + version + '" > .version' println version diff --git a/ios/scripts/set_xcode_version.sh b/ios/scripts/set_xcode_version.sh index 3b8b3f5f83..089eef0141 100755 --- a/ios/scripts/set_xcode_version.sh +++ b/ios/scripts/set_xcode_version.sh @@ -19,40 +19,44 @@ hash git 2>/dev/null || { echo >&2 "Git required, not installed. Aborting build # 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 +if [[ $(git ls-files -m "StatusIm/Info.plist") = *"Info.plist"* ]]; then + echo "version was set in Info.plist" 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 + # Build version (closest-tag-or-branch "-" commits-since-tag "-" short-hash dirty-flag) + BUILD_VERSION=$(git describe --tags --always --dirty=+) -# 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" + # 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 -/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" + # 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" + + /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" +fi diff --git a/src/status_im/utils/build.clj b/src/status_im/utils/build.clj index 320286be04..11444eef7f 100644 --- a/src/status_im/utils/build.clj +++ b/src/status_im/utils/build.clj @@ -1,7 +1,8 @@ (ns status-im.utils.build (:require [cljs.analyzer :as analyzer] [clojure.string :as string] - [clojure.java.shell :as shell])) + [clojure.java.shell :as shell] + [clojure.java.io :as io])) ;; Some warnings are unavoidable due to dependencies. For example, reagent 0.6.0 ;; has a warning in its util.cljs namespace. Adjust this as is necessary and @@ -21,4 +22,10 @@ (System/exit 1)))) (defmacro git-short-version [] - (string/replace (:out (shell/sh "bash" "-c" "git describe --always")) "\n" "")) + (let [version-file-path ".version" + version-file (io/file version-file-path)] + (if (.exists version-file) + (string/trim (slurp version-file-path)) + (-> (shell/sh "bash" "-c" "git describe --always") + :out + (string/replace "\n" "")))))