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
pkg
/BUILD_NUMBER
# Status Desktop
cmake_install.cmake

View File

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

View File

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

View File

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

View File

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

View File

@ -17,7 +17,7 @@ def compile(type = 'nightly') {
/* configure build metadata */
plutil('CFBundleShortVersionString', common.version())
plutil('CFBundleVersion', common.tagBuild())
plutil('CFBundleVersion', common.buildNumber())
plutil('CFBundleBuildUrl', currentBuild.absoluteUrl)
/* build the actual app */
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"
else
RELEASE_VERSION=$(cat ../VERSION)
BUILD_NO=$(sh ../scripts/build_no.sh)
BUILD_NO=$(bash ../scripts/build_no.sh)
# For debugging:
echo "SHORT VERSION: $RELEASE_VERSION"

View File

@ -1,80 +1,39 @@
#!/usr/bin/env sh
set -e
#!/usr/bin/env bash
#####################################################################
#
# 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.
# The limit of size of the number is signed int, which is 2147483647.
#
# 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
#
REGEX='^build-[0-9]\+$'
getNumber () {
echo "$1" | sed 's/[^0-9]*//g'
}
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"
}
# History:
#
# This script used to tag builds with `build-[0-9]+` tags.
# Since only release builds actually get uploaded to Play or Apple
# stores only then is the uniqueness of numbers checked.
# Because of that we are fine using just hour granurality.
#
#####################################################################
# make sure we have all the tags
git fetch --tags --quiet >/dev/null || \
>&2 echo "Could not fetch tags from remote"
# Fail on first error
set -e
# check if this commit already has a build number
NUMBER=$(findNumber)
GIT_ROOT=$(git rev-parse --show-toplevel)
DEV_BUILD_NUMBER=9999
BUILD_NUMBER_FILE="${GIT_ROOT}/BUILD_NUMBER"
# if it doesn't, or we are forcing via cli option, increment
if [ -z "$NUMBER" ] || [ "$1" = "--increment" ]; then
NUMBER=$(increment)
tagBuild $NUMBER
# If running under Jenkins use a timestamp-based build number.
# That build number is generated by the scripts/gen_build_no.sh script.
if [[ -f "${BUILD_NUMBER_FILE}" ]]; then
cat "${BUILD_NUMBER_FILE}"
else
echo "${DEV_BUILD_NUMBER}"
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))))
(defmacro get-build-no []
(-> (shell/sh "bash" "-c" "sh ./scripts/build_no.sh")
(-> (shell/sh "bash" "./scripts/build_no.sh")
:out
(string/replace "\n" "")))