From 01c8d9b25b0648d82c8782ae1950d12f978b4b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Fri, 2 Nov 2018 13:16:29 +0100 Subject: [PATCH] stop using build-* git tags for counting build numbers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- .gitignore | 1 + android/app/build.gradle | 2 +- ci/Jenkinsfile.combined | 2 - ci/android.groovy | 2 +- ci/common.groovy | 22 +++------ ci/ios.groovy | 2 +- ios/scripts/set_xcode_version.sh | 2 +- scripts/build_no.sh | 83 ++++++++------------------------ scripts/gen_build_no.sh | 26 ++++++++++ src/status_im/utils/build.clj | 2 +- 10 files changed, 61 insertions(+), 83 deletions(-) create mode 100755 scripts/gen_build_no.sh diff --git a/.gitignore b/.gitignore index d3d50d52b8..3cddb83e86 100644 --- a/.gitignore +++ b/.gitignore @@ -123,6 +123,7 @@ fastlane/README.md # Jenkins pkg +/BUILD_NUMBER # Status Desktop cmake_install.cmake diff --git a/android/app/build.gradle b/android/app/build.gradle index 1c36960bd9..94f2493342 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 "sh", "../../scripts/build_no.sh" + commandLine "bash", "../../scripts/build_no.sh" standardOutput = stdOut errorOutput = System.err } diff --git a/ci/Jenkinsfile.combined b/ci/Jenkinsfile.combined index 1d0b84626d..3dc7cba950 100644 --- a/ci/Jenkinsfile.combined +++ b/ci/Jenkinsfile.combined @@ -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') { diff --git a/ci/android.groovy b/ci/android.groovy index 201842e40d..9a4cc6cae4 100644 --- a/ci/android.groovy +++ b/ci/android.groovy @@ -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()}'" diff --git a/ci/common.groovy b/ci/common.groovy index afd24d31eb..6d58d8dd35 100644 --- a/ci/common.groovy +++ b/ci/common.groovy @@ -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) { diff --git a/ci/ios.groovy b/ci/ios.groovy index 797f75c896..bb52c3507d 100644 --- a/ci/ios.groovy +++ b/ci/ios.groovy @@ -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([ diff --git a/ios/scripts/set_xcode_version.sh b/ios/scripts/set_xcode_version.sh index c3fa745b19..983e4d0a2a 100755 --- a/ios/scripts/set_xcode_version.sh +++ b/ios/scripts/set_xcode_version.sh @@ -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" diff --git a/scripts/build_no.sh b/scripts/build_no.sh index 4ee0f83453..1c15a6e7c5 100755 --- a/scripts/build_no.sh +++ b/scripts/build_no.sh @@ -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 diff --git a/scripts/gen_build_no.sh b/scripts/gen_build_no.sh new file mode 100755 index 0000000000..7f4b2627d0 --- /dev/null +++ b/scripts/gen_build_no.sh @@ -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 diff --git a/src/status_im/utils/build.clj b/src/status_im/utils/build.clj index d843e6d7f0..05134cb14b 100644 --- a/src/status_im/utils/build.clj +++ b/src/status_im/utils/build.clj @@ -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" "")))