Skip to content

Instantly share code, notes, and snippets.

@u5-03
Last active March 20, 2023 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save u5-03/5a3c6d78f5c9cf3eaf4c3e7d68e4c2df to your computer and use it in GitHub Desktop.
Save u5-03/5a3c6d78f5c9cf3eaf4c3e7d68e4c2df to your computer and use it in GitHub Desktop.
Change CFBundleVersion value of iOS app
CONFIG_PATH="{path/to/xcconfig file}"
# Ref: https://www.curict.com/item/89/89a578b.html
# Check if executed in CI
if [ -n "$CI" ] && "$CI" ; then
echo "Run in CI"
BRANCH_NAME=$SOURCE_BRANCH # Add the appropriate environment variables used in CI.
else
echo "Run Not in CI"
BRANCH_NAME=`git rev-parse --abbrev-ref HEAD`
fi
# Ref1: http://171rr.blog.fc2.com/blog-entry-16.html
# Ref2: http://www.nucl.phys.tohoku.ac.jp/~shimpei.endo/Intro_shells/Chap2/2-6.html
TICKET_ID=`echo $BRANCH_NAME | sed -E 's/.*-([0-9]{3,}).*/\1/'` # Ticket ID is numeric only
# judge if numerical or not, Ref: https://zenn.dev/murnana/articles/bash-number-or-string
if [ -n "$TICKET_ID" ] && [[ "$TICKET_ID" =~ ^[0-9]+$ ]]; then
TICKET_ID_NUMBER=".$TICKET_ID"
else
# When the ticket is empty or when it is a string (such as develop)
TICKET_ID_NUMBER=""
fi
# Ref: https://qiita.com/niwasawa/items/9502e97b6c4d28d24042
DATETIME=`TZ=UTC-9 date '+%Y%m%d%H%M'`
BUILD_NUM_PREFIX=${DATETIME:2:10}
## Add a suffix to distinguish from other builds only for the following Configurations
case "${CONFIGURATION}" in
"Production-Release-Log") # To add log code even if the environment is Production
BUILD_CONFIGURATION_TYPE="0";;
*)
BUILD_CONFIGURATION_TYPE="";;
esac
if [[ "$CONFIGURATION" = "Production-Release" ]]; then
# Omitted in release apps
BRANCH_NAME_NUMBER=""
elif [[ "$BRANCH_NAME" == *master* ]]; then
BRANCH_NAME_NUMBER=".1"
elif [[ "$BRANCH_NAME" == *develop* ]]; then
BRANCH_NAME_NUMBER=".2"
elif [[ "$BRANCH_NAME" == *feature* ]]; then
BRANCH_NAME_NUMBER=".3"
elif [[ "$BRANCH_NAME" == *release* ]]; then
BRANCH_NAME_NUMBER=".4"
elif [[ "$BRANCH_NAME" == *hotfix* ]]; then
BRANCH_NAME_NUMBER=".5"
else
BRANCH_NAME_NUMBER="${BRANCH_NAME} is Non-Defined-Branch-Name"
fi
BUILD_INFO_NUMBER=${BRANCH_NAME_NUMBER}${BUILD_CONFIGURATION_TYPE}
BUILD_NUM="$BUILD_NUM_PREFIX$TICKET_ID_NUMBER$BUILD_INFO_NUMBER"
# Add "" not generate file for backup
# Ref: http://to-developer.com/blog/?p=1034
sed -i "" -e "s/CURRENT_PROJECT_VERSION=.*/CURRENT_PROJECT_VERSION=${BUILD_NUM}/g" $CONFIG_PATH
echo "Build Number is $BUILD_NUM!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment