2018-05-07 12:32:46 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
2018-06-12 08:08:09 +00:00
|
|
|
set -e
|
|
|
|
|
2018-05-07 12:32:46 +00:00
|
|
|
#
|
|
|
|
# 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
|
2018-07-10 14:17:27 +00:00
|
|
|
#
|
2018-05-07 12:32:46 +00:00
|
|
|
|
|
|
|
getNumber () {
|
|
|
|
echo "$BUILD" | sed 's/[^0-9]*//g'
|
|
|
|
}
|
|
|
|
|
2018-07-10 14:17:27 +00:00
|
|
|
REGEX='^build-[0-9]\+$'
|
2018-05-07 12:32:46 +00:00
|
|
|
|
2018-05-07 17:19:22 +00:00
|
|
|
# make sure we have all the tags
|
2018-07-10 14:17:27 +00:00
|
|
|
git fetch --tags --quiet >/dev/null || >&2 echo "Could not fetch tags from remote"
|
2018-05-07 12:32:46 +00:00
|
|
|
|
2018-05-29 08:43:18 +00:00
|
|
|
# even if the current commit has a tag already, it is normal that the same commit
|
|
|
|
# is built multiple times (with different build configurations, for instance),
|
|
|
|
# so we increment the build number every time.
|
2018-05-07 12:32:46 +00:00
|
|
|
|
2018-05-29 08:43:18 +00:00
|
|
|
# find the last used build number
|
2018-05-07 12:32:46 +00:00
|
|
|
BUILD=$(git tag -l --sort=-v:refname | grep -e "$REGEX" | head -n 1)
|
|
|
|
# extract the number
|
|
|
|
BUILD_NO=$(getNumber "$BUILD")
|
|
|
|
|
2018-06-12 08:08:09 +00:00
|
|
|
if [ "$1" = "--increment" ]; then
|
|
|
|
# These need to be provided by Jenkins
|
|
|
|
if [ -z "${GIT_USER}" ] || [ -z "${GIT_PASS}" ]; then
|
|
|
|
echo "Git credentials not specified! (GIT_USER, GIT_PASS)" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
# increment
|
|
|
|
BUILD_NO="$((BUILD_NO+1))"
|
|
|
|
|
2018-05-14 08:10:45 +00:00
|
|
|
echo "Tagging HEAD: build-$BUILD_NO" >&2
|
2018-05-07 12:46:19 +00:00
|
|
|
git tag "build-$BUILD_NO" HEAD
|
2018-06-12 08:08:09 +00:00
|
|
|
git push --tags https://${GIT_USER}:${GIT_PASS}@github.com/status-im/status-react
|
2018-05-07 12:32:46 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# finally print build number
|
|
|
|
echo "$BUILD_NO"
|