@@ -12,21 +12,24 @@ function __build_tagging {
1212
1313 __validate_options " $@ "
1414
15- APP_VERSION=" "
16- APP_PLATFORM=$( __check_platform)
17- if [ " $APP_PLATFORM " == " $PLATFORM_ANDROID_APK " ]; then
18- APP_VERSION=$( __generate_app_version_from_apk " $APP_PATH " " $BUILD_COUNT " )
19- elif [ " $APP_PLATFORM " == " $PLATFORM_ANDROID_AAB " ]; then
20- APP_VERSION=$( __generate_app_version_from_aab " $APP_PATH " " $BUILD_COUNT " )
21- elif [ " $APP_PLATFORM " == " $PLATFORM_IOS " ]; then
22- APP_VERSION=$( __generate_app_version_from_ipa " $APP_PATH " " $BUILD_COUNT " )
23- elif [[ ! -n " $CUSTOM_APP_VERSION " ]]; then
24- echo
25- echo " Unsupported file format: ${APP_PATH##* .} "
26- echo " If unsupported file format is used (i.e., none of apk, aab, or ipa),"
27- echo " you have to define the custom app version (option -v)."
28- echo
29- exit 1
15+ # There is no custom app version, try to extract from passed installation file
16+ if [[ -z " $CUSTOM_APP_VERSION " ]]; then
17+ APP_VERSION=" "
18+ APP_PLATFORM=$( __check_platform)
19+ if [ " $APP_PLATFORM " == " $PLATFORM_ANDROID_APK " ]; then
20+ APP_VERSION=$( __generate_app_version_from_apk " $APP_PATH " " $BUILD_COUNT " )
21+ elif [ " $APP_PLATFORM " == " $PLATFORM_ANDROID_AAB " ]; then
22+ APP_VERSION=$( __generate_app_version_from_aab " $APP_PATH " " $BUILD_COUNT " )
23+ elif [ " $APP_PLATFORM " == " $PLATFORM_IOS " ]; then
24+ APP_VERSION=$( __generate_app_version_from_ipa " $APP_PATH " " $BUILD_COUNT " )
25+ elif [[ ! -n " $CUSTOM_APP_VERSION " ]]; then
26+ echo
27+ echo " Unsupported file format: ${APP_PATH##* .} "
28+ echo " If unsupported file format is used (i.e., none of apk, aab, or ipa),"
29+ echo " you have to define the custom app version (option -v)."
30+ echo
31+ exit 1
32+ fi
3033 fi
3134
3235 __create_and_push_tag
@@ -35,14 +38,17 @@ function __build_tagging {
3538# Tag creation & push
3639
3740function __create_and_push_tag {
38-
41+
42+ CALCULATED_APP_VERSION=" "
3943 # If there is a custom app version passed, append build number to it
4044 if [[ -n " $CUSTOM_APP_VERSION " ]]; then
41- CUSTOM_APP_VERSION=" ${CUSTOM_APP_VERSION} b${BUILD_COUNT} "
45+ SUFFIX=" "
46+ [[ -n " ${BUILD_COUNT} " ]] && SUFFIX=" b${BUILD_COUNT} "
47+ CALCULATED_APP_VERSION=" ${CUSTOM_APP_VERSION}${SUFFIX} "
4248 fi
4349
4450 CHANGELOG=${CHANGELOG:- " " } # Set empty string if changelog is not available
45- TAG=" ${ENVIRONMENT} /v${CUSTOM_APP_VERSION :- $APP_VERSION } "
51+ TAG=" ${ENVIRONMENT} /v${CALCULATED_APP_VERSION :- $APP_VERSION } "
4652 git tag -a " $TAG " -m " ${CHANGELOG} "
4753 git push origin " $TAG "
4854}
@@ -83,7 +89,8 @@ function __validate_options {
8389 fi
8490
8591 # Ensure BUILD_COUNT is set (even if empty string is allowed)
86- if [[ ! -v BUILD_COUNT ]]; then
92+ # Used older syntax (instead of [[ ! -v BUILD_COUNT ]]) as this -v was introduced in bash v4, while macOS comes with preinstalled v3
93+ if ! declare -p BUILD_COUNT & > /dev/null; then
8794 echo " Error: Missing mandatory option -b (build count)."
8895 echo " Usage: app-deploy tagging -e \" environment_name\" [-p \" path/to/app.{ipa/apk}\" | -v \" version\" ] -b \" {build count}\" "
8996 exit 1
0 commit comments