stop using build-* git tags for counting build numbers

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2018-11-02 13:16:29 +01:00
parent 20bd65c0c0
commit 01c8d9b25b
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
10 changed files with 61 additions and 83 deletions

1
.gitignore vendored
View File

@ -123,6 +123,7 @@ fastlane/README.md
# Jenkins # Jenkins
pkg pkg
/BUILD_NUMBER
# Status Desktop # Status Desktop
cmake_install.cmake cmake_install.cmake

View File

@ -98,7 +98,7 @@ def enableProguardInReleaseBuilds = false
def getVersionCode = { -> def getVersionCode = { ->
new ByteArrayOutputStream().withStream { stdOut -> new ByteArrayOutputStream().withStream { stdOut ->
exec { exec {
commandLine "sh", "../../scripts/build_no.sh" commandLine "bash", "../../scripts/build_no.sh"
standardOutput = stdOut standardOutput = stdOut
errorOutput = System.err errorOutput = System.err
} }

View File

@ -22,8 +22,6 @@ pipeline {
cmn = load('ci/common.groovy') cmn = load('ci/common.groovy')
/* just for a shorter access */ /* just for a shorter access */
btype = cmn.getBuildType() btype = cmn.getBuildType()
/* to avoid missing build tag parallel builds */
print "Build Number: ${cmn.tagBuild(true)}"
} } } }
} }
stage('Build') { stage('Build') {

View File

@ -1,7 +1,7 @@
common = load 'ci/common.groovy' common = load 'ci/common.groovy'
def compile(type = 'nightly') { def compile(type = 'nightly') {
common.tagBuild() common.buildNumber()
def gradleOpt = "-PbuildUrl='${currentBuild.absoluteUrl}' " def gradleOpt = "-PbuildUrl='${currentBuild.absoluteUrl}' "
if (type == 'release') { if (type == 'release') {
gradleOpt += "-PreleaseVersion='${common.version()}'" gradleOpt += "-PreleaseVersion='${common.version()}'"

View File

@ -56,7 +56,7 @@ def installJSDeps(platform) {
/* prepare environment for specific platform build */ /* prepare environment for specific platform build */
sh "scripts/prepare-for-platform.sh ${platform}" sh "scripts/prepare-for-platform.sh ${platform}"
while (!installed && attempt <= maxAttempts) { while (!installed && attempt <= maxAttempts) {
println "#${attempt} attempt to install npm deps" println("#${attempt} attempt to install npm deps")
sh 'npm install' sh 'npm install'
installed = fileExists('node_modules/web3/index.js') installed = fileExists('node_modules/web3/index.js')
attemp = attempt + 1 attemp = attempt + 1
@ -72,19 +72,13 @@ def doGitRebase() {
} }
} }
def tagBuild(increment = false) { def buildNumber() {
def opts = (increment ? '--increment' : '') def number = sh(
withCredentials([[ returnStdout: true,
$class: 'UsernamePasswordMultiBinding', script: "./scripts/gen_build_no.sh"
credentialsId: 'status-im-auto', ).trim()
usernameVariable: 'GIT_USER', println("Build Number: ${number}")
passwordVariable: 'GIT_PASS' return number
]]) {
return sh(
returnStdout: true,
script: "./scripts/build_no.sh ${opts}"
).trim()
}
} }
def getDirPath(path) { def getDirPath(path) {

View File

@ -17,7 +17,7 @@ def compile(type = 'nightly') {
/* configure build metadata */ /* configure build metadata */
plutil('CFBundleShortVersionString', common.version()) plutil('CFBundleShortVersionString', common.version())
plutil('CFBundleVersion', common.tagBuild()) plutil('CFBundleVersion', common.buildNumber())
plutil('CFBundleBuildUrl', currentBuild.absoluteUrl) plutil('CFBundleBuildUrl', currentBuild.absoluteUrl)
/* build the actual app */ /* build the actual app */
withCredentials([ withCredentials([

View File

@ -23,7 +23,7 @@ if [[ $(git ls-files -m "StatusIm/Info.plist") = *"Info.plist"* ]]; then
echo "version was set in Info.plist" echo "version was set in Info.plist"
else else
RELEASE_VERSION=$(cat ../VERSION) RELEASE_VERSION=$(cat ../VERSION)
BUILD_NO=$(sh ../scripts/build_no.sh) BUILD_NO=$(bash ../scripts/build_no.sh)
# For debugging: # For debugging:
echo "SHORT VERSION: $RELEASE_VERSION" echo "SHORT VERSION: $RELEASE_VERSION"

View File

@ -1,80 +1,39 @@
#!/usr/bin/env sh #!/usr/bin/env bash
set -e
#####################################################################
# #
# This script manages app build numbers. # This script manages app build numbers.
# It returns the next build number to be used. # It returns the next build number to be used.
# If ran with --tag it will mark current HEAD with new build number. # The limit of size of the number is signed int, which is 2147483647.
# #
# These numbers are used to mark app artifacts for: # These numbers are used to mark app artifacts for:
# * Play Store - versionCode attribute (gradle) # * Play Store - versionCode attribute (gradle)
# * Apple Store - CFBundleVersion attribute (plutil) # * 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: # For more details see:
# * https://developer.android.com/studio/publish/versioning # * https://developer.android.com/studio/publish/versioning
# * https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # * https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# #
# History:
REGEX='^build-[0-9]\+$' #
# This script used to tag builds with `build-[0-9]+` tags.
getNumber () { # Since only release builds actually get uploaded to Play or Apple
echo "$1" | sed 's/[^0-9]*//g' # stores only then is the uniqueness of numbers checked.
} # Because of that we are fine using just hour granurality.
#
findNumber () (
# check if current commit has a build tag
# since we are building in separate jobs we have to check for a tag
BUILD_TAG=$(git tag --points-at HEAD | grep -e "$REGEX" | tail -n1)
# use already existing build number if applicable
if [ -n "$BUILD_TAG" ]; then
echo "Current commit already tagged: $BUILD_TAG" >&2
getNumber $BUILD_TAG
fi
)
tagBuild () {
echo "Tagging HEAD: build-$1" >&2
git tag "build-$1" HEAD
if [ -n "$GIT_USER" ] && [ -n "$GIT_PASS" ]; then
git push --tags \
https://${GIT_USER}:${GIT_PASS}@github.com/status-im/status-react
else
git push --tags git@github.com:status-im/status-react
fi
}
increment () {
# 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))"
# finally print build number
echo "$BUILD_NO"
}
##################################################################### #####################################################################
# make sure we have all the tags # Fail on first error
git fetch --tags --quiet >/dev/null || \ set -e
>&2 echo "Could not fetch tags from remote"
# check if this commit already has a build number GIT_ROOT=$(git rev-parse --show-toplevel)
NUMBER=$(findNumber) DEV_BUILD_NUMBER=9999
BUILD_NUMBER_FILE="${GIT_ROOT}/BUILD_NUMBER"
# if it doesn't, or we are forcing via cli option, increment # If running under Jenkins use a timestamp-based build number.
if [ -z "$NUMBER" ] || [ "$1" = "--increment" ]; then # That build number is generated by the scripts/gen_build_no.sh script.
NUMBER=$(increment) if [[ -f "${BUILD_NUMBER_FILE}" ]]; then
tagBuild $NUMBER cat "${BUILD_NUMBER_FILE}"
else
echo "${DEV_BUILD_NUMBER}"
fi fi
# print build number
echo $NUMBER

26
scripts/gen_build_no.sh Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env bash
#####################################################################
#
# Save the timestamp-based build number for builds
# that get uploaded to places like:
# Apple Store, Play Store, or TestFlight
#
# The result of this script is used by scripts/build_no.sh
# when being run in Jenkins build context.
#
#####################################################################
# Fail on first error
set -e
GIT_ROOT=$(git rev-parse --show-toplevel)
BUILD_NUMBER_FILE="${GIT_ROOT}/BUILD_NUMBER"
if [[ -f "${BUILD_NUMBER_FILE}" ]]; then
cat "${BUILD_NUMBER_FILE}"
else
# Format: Year(2 digit) + Month + Day + Hour + Minutes
# Example: 1812011805
date '+%y%m%d%H%M' | tee "${BUILD_NUMBER_FILE}"
fi

View File

@ -22,7 +22,7 @@
(System/exit 1)))) (System/exit 1))))
(defmacro get-build-no [] (defmacro get-build-no []
(-> (shell/sh "bash" "-c" "sh ./scripts/build_no.sh") (-> (shell/sh "bash" "./scripts/build_no.sh")
:out :out
(string/replace "\n" ""))) (string/replace "\n" "")))