Merge pull request #4131 from status-im/fix/build-numbering

Fix for versionCode conflicts when uploading to Play Store
This commit is contained in:
Jakub 2018-05-16 16:55:54 +02:00 committed by GitHub
commit 436ac1d798
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 88 additions and 3 deletions

View File

@ -63,7 +63,7 @@ node ('macos1'){
} }
stage('Build (iOS)') { 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 --tag').trim()
sh ('plutil -replace CFBundleShortVersionString -string ' + version + ' ios/StatusIm/Info.plist') sh ('plutil -replace CFBundleShortVersionString -string ' + version + ' ios/StatusIm/Info.plist')
sh ('plutil -replace CFBundleVersion -string ' + build_no + ' 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 'export RCT_NO_LAUNCH_PACKAGER=true && xcodebuild -workspace ios/StatusIm.xcworkspace -scheme StatusIm -configuration release -archivePath status clean archive'
@ -97,6 +97,17 @@ node ('macos1'){
sh ('echo ARTIFACT iOS: ' + ipaUrl) sh ('echo ARTIFACT iOS: ' + ipaUrl)
} }
} }
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) { } catch (e) {
slackSend color: 'bad', message: 'Release build failed to build. ' + env.BUILD_URL slackSend color: 'bad', message: 'Release build failed to build. ' + env.BUILD_URL
throw e throw e

View File

@ -64,7 +64,7 @@ node ('macos1'){
stage('Build (iOS)') { stage('Build (iOS)') {
withCredentials([string(credentialsId: 'jenkins_pass', variable: 'password')]) { 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 --tag').trim()
sh ('plutil -replace CFBundleShortVersionString -string ' + version + ' ios/StatusIm/Info.plist') sh ('plutil -replace CFBundleShortVersionString -string ' + version + ' ios/StatusIm/Info.plist')
sh ('plutil -replace CFBundleVersion -string ' + build_no + ' 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 'export RCT_NO_LAUNCH_PACKAGER=true && xcodebuild -workspace ios/StatusIm.xcworkspace -scheme StatusIm -configuration release -archivePath status clean archive'
@ -80,6 +80,18 @@ node ('macos1'){
stage('Deploy (iOS)') { stage('Deploy (iOS)') {
sh ('bundle exec fastlane ios release || exit 0') sh ('bundle exec fastlane ios release || exit 0')
} }
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) { } catch (e) {
slackSend color: 'bad', message: 'Release build failed uploading to iTC/Play Market. ' + env.BUILD_URL slackSend color: 'bad', message: 'Release build failed uploading to iTC/Play Market. ' + env.BUILD_URL
throw e throw e

View File

@ -98,8 +98,9 @@ def enableProguardInReleaseBuilds = false
def getVersionCode = { -> def getVersionCode = { ->
new ByteArrayOutputStream().withStream { stdOut -> new ByteArrayOutputStream().withStream { stdOut ->
exec { exec {
commandLine "git", "rev-list", "--count", "HEAD" commandLine "sh", "../../build_no.sh", "--tag"
standardOutput = stdOut standardOutput = stdOut
errorOutput = System.err
} }
return stdOut.toString().toInteger() return stdOut.toString().toInteger()
} }

61
build_no.sh Executable file
View File

@ -0,0 +1,61 @@
#!/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]\+$'
# make sure we have all the tags
git fetch --tags --quiet
# check if current commit has a build tag
BUILD=$(git tag --points-at 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 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
# finally print build number
echo "$BUILD_NO"