From 176817dc5577b51eb66e724d6516676620118976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 7 May 2018 14:32:46 +0200 Subject: [PATCH 01/14] add script for managing build numbers --- build_no.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 build_no.sh diff --git a/build_no.sh b/build_no.sh new file mode 100644 index 0000000000..8e56103163 --- /dev/null +++ b/build_no.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env sh + +# +# This script manages app build numbers. +# It returns the next build number to be used. +# If ran with --tag it will mark current HEAD with new build number. +# +# These numbers are used to mark app artifacts for: +# * Play Store - versionCode attribute (gradle) +# * Apple Store - CFBundleVersion attribute (plutil) +# +# The numbers need to be incremeneted and are maintained via +# git tags matching the '^build-[0-9]+$' regex. +# Builds from an already tagged commit should use the same number. +# +# For more details see: +# * https://developer.android.com/studio/publish/versioning +# * https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html +# + +getNumber () { + echo "$BUILD" | sed 's/[^0-9]*//g' +} + +REGEX='^build-[0-9]\+$' + +# check if current commit has a build tag +BUILD=$(git tag --points-at refs/tags/HEAD | grep -e "$REGEX") + +# chech for multiple lines +if [ 1 -lt $(echo "$BUILD" | grep -c -) ]; then + echo "Commit marked with one than one build tag!" >&2 + echo "$BUILD" >&2 + exit 1 +fi + +# use already existing build number if applicable +if [ -n "$BUILD" ]; then + echo "Current commit already tagged: $BUILD" >&2 + getNumber $BUILD + exit 0 +fi + +# otherwise find the last used build number +BUILD=$(git tag -l --sort=-v:refname | grep -e "$REGEX" | head -n 1) +# extract the number +BUILD_NO=$(getNumber "$BUILD") +# increment +BUILD_NO="$((BUILD_NO+1))" + +if [ "$1" = "--tag" ]; then + echo "Tagging refs/tags/HEAD: $BUILD" >&2 + echo "You will need to 'git push --tags' to make this tag take effect." >&2 + git tag "build-$BUILD_NO" refs/tags/HEAD +fi + +# finally print build number +echo "$BUILD_NO" From f97fec15474bb11c98461bfc4ee8f75dc0fa7398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 7 May 2018 14:32:56 +0200 Subject: [PATCH 02/14] update jenkinsfiles and build.gradle to use build_no.sh --- Jenkinsfile.release | 6 +++++- Jenkinsfile.upload_release | 6 +++++- android/app/build.gradle | 2 +- build_no.sh | 0 4 files changed, 11 insertions(+), 3 deletions(-) mode change 100644 => 100755 build_no.sh diff --git a/Jenkinsfile.release b/Jenkinsfile.release index 9e92384a4b..325b6423d3 100644 --- a/Jenkinsfile.release +++ b/Jenkinsfile.release @@ -63,13 +63,17 @@ node ('macos1'){ } stage('Build (iOS)') { - def build_no = sh(returnStdout: true, script: 'git rev-list --count HEAD').trim() + def build_no = sh(returnStdout: true, script: './build_no.sh').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' } + stage('Push Build Tag') { + sh ('git push --tags') + } + stage('Deploy (Android)') { def artifact_dir = pwd() + '/android/app/build/outputs/apk/release/' println (artifact_dir + 'app-release.apk') diff --git a/Jenkinsfile.upload_release b/Jenkinsfile.upload_release index 93bfb0dda4..492acef9b3 100644 --- a/Jenkinsfile.upload_release +++ b/Jenkinsfile.upload_release @@ -66,7 +66,7 @@ node ('macos1'){ stage('Build (iOS)') { withCredentials([string(credentialsId: 'jenkins_pass', variable: 'password')]) { - def build_no = sh(returnStdout: true, script: 'git rev-list --count HEAD').trim() + def build_no = sh(returnStdout: true, script: './build_no.sh').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' @@ -75,6 +75,10 @@ node ('macos1'){ } } + stage('Push build tag') { + sh ('git push --tags') + } + stage('Deploy (Android)') { sh ('bundle exec fastlane android release || exit 0') } diff --git a/android/app/build.gradle b/android/app/build.gradle index 93ad2080a0..4f4b9c66f5 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -98,7 +98,7 @@ def enableProguardInReleaseBuilds = false def getVersionCode = { -> new ByteArrayOutputStream().withStream { stdOut -> exec { - commandLine "git", "rev-list", "--count", "HEAD" + commandLine "./build_no.sh" standardOutput = stdOut } return stdOut.toString().toInteger() diff --git a/build_no.sh b/build_no.sh old mode 100644 new mode 100755 From ccbfc5bb7e49662da26e7aa24444dcdb61168aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 7 May 2018 14:34:48 +0200 Subject: [PATCH 03/14] fix workingDir for build.gradle running build_no.sh --- android/app/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/android/app/build.gradle b/android/app/build.gradle index 4f4b9c66f5..acc8303264 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -98,6 +98,7 @@ def enableProguardInReleaseBuilds = false def getVersionCode = { -> new ByteArrayOutputStream().withStream { stdOut -> exec { + workingDir "../" commandLine "./build_no.sh" standardOutput = stdOut } From 99e9316fda49874089fb4c21042e55a7dc3b61ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 7 May 2018 14:42:37 +0200 Subject: [PATCH 04/14] add use of --tag --- Jenkinsfile.release | 2 +- Jenkinsfile.upload_release | 2 +- android/app/build.gradle | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile.release b/Jenkinsfile.release index 325b6423d3..5735cb70d6 100644 --- a/Jenkinsfile.release +++ b/Jenkinsfile.release @@ -63,7 +63,7 @@ node ('macos1'){ } stage('Build (iOS)') { - def build_no = sh(returnStdout: true, script: './build_no.sh').trim() + def build_no = sh(returnStdout: true, script: './build_no.sh --tag').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' diff --git a/Jenkinsfile.upload_release b/Jenkinsfile.upload_release index 492acef9b3..a131da1d3e 100644 --- a/Jenkinsfile.upload_release +++ b/Jenkinsfile.upload_release @@ -66,7 +66,7 @@ node ('macos1'){ stage('Build (iOS)') { withCredentials([string(credentialsId: 'jenkins_pass', variable: 'password')]) { - def build_no = sh(returnStdout: true, script: './build_no.sh').trim() + def build_no = sh(returnStdout: true, script: './build_no.sh --tag').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' diff --git a/android/app/build.gradle b/android/app/build.gradle index acc8303264..a5c559f012 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -99,7 +99,7 @@ def getVersionCode = { -> new ByteArrayOutputStream().withStream { stdOut -> exec { workingDir "../" - commandLine "./build_no.sh" + commandLine "./build_no.sh --tag" standardOutput = stdOut } return stdOut.toString().toInteger() From 6aa2edd2b5c463d8475d477099460c8a64694efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 7 May 2018 14:46:19 +0200 Subject: [PATCH 05/14] just use HEAD when tagging --- build_no.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build_no.sh b/build_no.sh index 8e56103163..7e0dfe99e8 100755 --- a/build_no.sh +++ b/build_no.sh @@ -25,7 +25,7 @@ getNumber () { REGEX='^build-[0-9]\+$' # check if current commit has a build tag -BUILD=$(git tag --points-at refs/tags/HEAD | grep -e "$REGEX") +BUILD=$(git tag --points-at HEAD | grep -e "$REGEX") # chech for multiple lines if [ 1 -lt $(echo "$BUILD" | grep -c -) ]; then @@ -49,9 +49,9 @@ BUILD_NO=$(getNumber "$BUILD") BUILD_NO="$((BUILD_NO+1))" if [ "$1" = "--tag" ]; then - echo "Tagging refs/tags/HEAD: $BUILD" >&2 + echo "Tagging HEAD: $BUILD" >&2 echo "You will need to 'git push --tags' to make this tag take effect." >&2 - git tag "build-$BUILD_NO" refs/tags/HEAD + git tag "build-$BUILD_NO" HEAD fi # finally print build number From 3c0fa7feb5fb8bd8a1d4c7b2b8af04b8911a1e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 7 May 2018 15:13:10 +0200 Subject: [PATCH 06/14] move pushing build tag to after deploy stages --- Jenkinsfile.release | 8 ++++---- Jenkinsfile.upload_release | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile.release b/Jenkinsfile.release index 5735cb70d6..ea144154e3 100644 --- a/Jenkinsfile.release +++ b/Jenkinsfile.release @@ -70,10 +70,6 @@ node ('macos1'){ sh 'xcodebuild -exportArchive -exportPath status -archivePath status.xcarchive -exportOptionsPlist ~/archive.plist' } - stage('Push Build Tag') { - sh ('git push --tags') - } - stage('Deploy (Android)') { def artifact_dir = pwd() + '/android/app/build/outputs/apk/release/' println (artifact_dir + 'app-release.apk') @@ -101,6 +97,10 @@ node ('macos1'){ sh ('echo ARTIFACT iOS: ' + ipaUrl) } } + + stage('Push Build Tag') { + sh ('git push --tags') + } } catch (e) { slackSend color: 'bad', message: 'Release build failed to build. ' + env.BUILD_URL throw e diff --git a/Jenkinsfile.upload_release b/Jenkinsfile.upload_release index a131da1d3e..4b6871a0ed 100644 --- a/Jenkinsfile.upload_release +++ b/Jenkinsfile.upload_release @@ -75,10 +75,6 @@ node ('macos1'){ } } - stage('Push build tag') { - sh ('git push --tags') - } - stage('Deploy (Android)') { sh ('bundle exec fastlane android release || exit 0') } @@ -86,6 +82,10 @@ node ('macos1'){ stage('Deploy (iOS)') { sh ('bundle exec fastlane ios release || exit 0') } + + stage('Push build tag') { + sh ('git push --tags') + } } catch (e) { slackSend color: 'bad', message: 'Release build failed uploading to iTC/Play Market. ' + env.BUILD_URL throw e From c1af6448d64f3d674bef84369f5565f6eb8be197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 7 May 2018 17:10:21 +0200 Subject: [PATCH 07/14] separate --tag argument from the command --- android/app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index a5c559f012..c35280850b 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -99,7 +99,7 @@ def getVersionCode = { -> new ByteArrayOutputStream().withStream { stdOut -> exec { workingDir "../" - commandLine "./build_no.sh --tag" + commandLine "./build_no.sh", "--tag" standardOutput = stdOut } return stdOut.toString().toInteger() From ac7e412a9c23f32a41345797853a6fef6dc65f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 7 May 2018 18:51:49 +0200 Subject: [PATCH 08/14] print current working dir --- android/app/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/android/app/build.gradle b/android/app/build.gradle index c35280850b..c5446f05bc 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -97,6 +97,7 @@ def enableProguardInReleaseBuilds = false def getVersionCode = { -> new ByteArrayOutputStream().withStream { stdOut -> + println System.getProperty("user.dir") exec { workingDir "../" commandLine "./build_no.sh", "--tag" From 1b25e1f3bf41802fdd7918955136fba7b87c01f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 7 May 2018 19:19:22 +0200 Subject: [PATCH 09/14] fetch tags before checking them --- build_no.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build_no.sh b/build_no.sh index 7e0dfe99e8..1b4f0bab02 100755 --- a/build_no.sh +++ b/build_no.sh @@ -24,6 +24,9 @@ getNumber () { REGEX='^build-[0-9]\+$' +# make sure we have all the tags +git fetch --tags + # check if current commit has a build tag BUILD=$(git tag --points-at HEAD | grep -e "$REGEX") From 86c67013409254cbdd24de537cd4bb71506973de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 7 May 2018 19:56:50 +0200 Subject: [PATCH 10/14] use sh explicitly --- android/app/build.gradle | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index c5446f05bc..60597b9bdd 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -97,10 +97,8 @@ def enableProguardInReleaseBuilds = false def getVersionCode = { -> new ByteArrayOutputStream().withStream { stdOut -> - println System.getProperty("user.dir") exec { - workingDir "../" - commandLine "./build_no.sh", "--tag" + commandLine "sh", "../build_no.sh", "--tag" standardOutput = stdOut } return stdOut.toString().toInteger() From a2810999a6a56162c999f4b86b8ed00cc62b7e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 7 May 2018 19:56:59 +0200 Subject: [PATCH 11/14] we are actually in andoid/app dir --- android/app/build.gradle | 3 ++- build_no.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 60597b9bdd..8ef934906c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -98,8 +98,9 @@ def enableProguardInReleaseBuilds = false def getVersionCode = { -> new ByteArrayOutputStream().withStream { stdOut -> exec { - commandLine "sh", "../build_no.sh", "--tag" + commandLine "sh", "../../build_no.sh", "--tag" standardOutput = stdOut + errorOutput = System.err } return stdOut.toString().toInteger() } diff --git a/build_no.sh b/build_no.sh index 1b4f0bab02..4348f69385 100755 --- a/build_no.sh +++ b/build_no.sh @@ -25,7 +25,7 @@ getNumber () { REGEX='^build-[0-9]\+$' # make sure we have all the tags -git fetch --tags +git fetch --tags --quiet # check if current commit has a build tag BUILD=$(git tag --points-at HEAD | grep -e "$REGEX") From 68300dbc61d8b8f5bdce5621f2d1d1c24afd9c37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 14 May 2018 10:10:34 +0200 Subject: [PATCH 12/14] fix tag pusshing step to use jenkins-status-im credentials --- Jenkinsfile.upload_release | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile.upload_release b/Jenkinsfile.upload_release index 4b6871a0ed..163b0aa7b7 100644 --- a/Jenkinsfile.upload_release +++ b/Jenkinsfile.upload_release @@ -83,8 +83,16 @@ node ('macos1'){ sh ('bundle exec fastlane ios release || exit 0') } + stage('Push build tag') { - sh ('git push --tags') + withCredentials([[ + $class: 'UsernamePasswordMultiBinding', + credentialsId: 'jenkins-status-im', + usernameVariable: 'GIT_USER', + passwordVariable: 'GIT_PASS' + ]]) { + sh ('git push --tags https://${GIT_USER}:${GIT_PASS}@github.com/status-im/status-react --tags') + } } } catch (e) { slackSend color: 'bad', message: 'Release build failed uploading to iTC/Play Market. ' + env.BUILD_URL From df3ec429c9118b6c5154f46b3bf4f74525ff848c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 14 May 2018 10:10:45 +0200 Subject: [PATCH 13/14] fix printing build number when taggin --- build_no.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_no.sh b/build_no.sh index 4348f69385..c81df4c685 100755 --- a/build_no.sh +++ b/build_no.sh @@ -52,7 +52,7 @@ BUILD_NO=$(getNumber "$BUILD") BUILD_NO="$((BUILD_NO+1))" if [ "$1" = "--tag" ]; then - echo "Tagging HEAD: $BUILD" >&2 + echo "Tagging HEAD: build-$BUILD_NO" >&2 echo "You will need to 'git push --tags' to make this tag take effect." >&2 git tag "build-$BUILD_NO" HEAD fi From 79ef297bf75773df4b0a1d4bfab06538b8d469f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Wed, 16 May 2018 15:55:09 +0200 Subject: [PATCH 14/14] fix pushing for Jenkinsfile.release too --- Jenkinsfile.release | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile.release b/Jenkinsfile.release index ea144154e3..a1d90738a1 100644 --- a/Jenkinsfile.release +++ b/Jenkinsfile.release @@ -98,8 +98,15 @@ node ('macos1'){ } } - stage('Push Build Tag') { - sh ('git push --tags') + stage('Push build tag') { + withCredentials([[ + $class: 'UsernamePasswordMultiBinding', + credentialsId: 'jenkins-status-im', + usernameVariable: 'GIT_USER', + passwordVariable: 'GIT_PASS' + ]]) { + sh ('git push --tags https://${GIT_USER}:${GIT_PASS}@github.com/status-im/status-react --tags') + } } } catch (e) { slackSend color: 'bad', message: 'Release build failed to build. ' + env.BUILD_URL