forked from organicmaps/organicmaps
[tools] Version script without params now shows actual values
Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
parent
b852ac84f9
commit
98cdd8760b
1 changed files with 44 additions and 37 deletions
|
@ -1,21 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Should be used everywhere to generate a consistent version number based
|
||||
# on the date of the last commit and a number of commits on that day.
|
||||
set -euo pipefail
|
||||
|
||||
function usage {
|
||||
cat << EOF
|
||||
Prints Organic Maps version in specified format.
|
||||
Version is the last git commit's date plus a number of commits on that day.
|
||||
Usage: $0 format
|
||||
Where format is one of the following arguments:
|
||||
ios_version 2021.12.26
|
||||
ios_build 3
|
||||
android_name 2021.12.26-3
|
||||
android_code 21122603
|
||||
git_hash abcdef01
|
||||
EOF
|
||||
}
|
||||
|
||||
# Note: other ways to get date use the "when commit was rebased" date.
|
||||
# This approach counts a number of commits each day based on author's commit date.
|
||||
COUNT_AND_DATE=( $(git log --date=short --pretty=format:%ad --date=format:'%Y.%m.%d' --since="30 days ago" | sort | uniq -c | tail -1) )
|
||||
|
@ -26,16 +13,20 @@ fi
|
|||
DATE=${COUNT_AND_DATE[1]}
|
||||
COUNT=${COUNT_AND_DATE[0]}
|
||||
|
||||
case "${1:-}" in
|
||||
ios_version)
|
||||
echo $DATE
|
||||
;;
|
||||
ios_build)
|
||||
echo $COUNT
|
||||
;;
|
||||
android_name)
|
||||
echo $DATE-$COUNT
|
||||
;;
|
||||
|
||||
function ios_version {
|
||||
echo "$DATE"
|
||||
}
|
||||
|
||||
function ios_build {
|
||||
echo "$COUNT"
|
||||
}
|
||||
|
||||
function android_name {
|
||||
echo "$DATE-$COUNT"
|
||||
}
|
||||
|
||||
function android_code {
|
||||
# RR_yy_MM_dd_CC
|
||||
# RR - reserved to identify special markets, max value is 21.
|
||||
# yy - year
|
||||
|
@ -44,15 +35,31 @@ case "${1:-}" in
|
|||
# CC - the number of commits from the current day
|
||||
# 21_00_00_00_00 is the the greatest value Google Play allows for versionCode.
|
||||
# See https://developer.android.com/studio/publish/versioning for details.
|
||||
android_code)
|
||||
CUT_YEAR=${DATE:2}
|
||||
echo ${CUT_YEAR//./}$(printf %02d $COUNT)
|
||||
;;
|
||||
git_hash)
|
||||
git describe --match="" --always --abbrev=8 --dirty
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
local cutYear=${DATE:2}
|
||||
echo "${cutYear//./}$(printf %02d "$COUNT")"
|
||||
}
|
||||
|
||||
function git_hash {
|
||||
git describe --match="" --always --abbrev=8 --dirty
|
||||
}
|
||||
|
||||
function usage {
|
||||
cat << EOF
|
||||
Prints Organic Maps version in specified format.
|
||||
Version is the last git commit's date plus a number of commits on that day.
|
||||
Usage: $0 <format>
|
||||
Where format is one of the following arguments (shows current values):
|
||||
ios_version $(ios_version)
|
||||
ios_build $(ios_build)
|
||||
android_name $(android_name)
|
||||
android_code $(android_code)
|
||||
git_hash $(git_hash)
|
||||
EOF
|
||||
}
|
||||
|
||||
if [ -z ${1:-} ] || [[ ! $(type -t "$1") == function ]]; then
|
||||
usage
|
||||
exit 1
|
||||
else
|
||||
"$1"
|
||||
fi
|
||||
|
|
Loading…
Add table
Reference in a new issue