Skip to content

Instantly share code, notes, and snippets.

@alinradut
Last active June 30, 2016 13:06
Show Gist options
  • Save alinradut/6ad7fb457ca48518cdf596cc39ad85b1 to your computer and use it in GitHub Desktop.
Save alinradut/6ad7fb457ca48518cdf596cc39ad85b1 to your computer and use it in GitHub Desktop.
Automatically bump up the version number when creating an iOS Release build
#
# License: Public domain
#
function bump_version() {
touch "$PROJECT_DIR/LASTVERSION"
typeset -i BUILD_VERSION=$(cat "$PROJECT_DIR/LASTVERSION")
BUILD_VERSION=$((BUILD_VERSION+1))
echo $BUILD_VERSION > "$PROJECT_DIR/LASTVERSION"
echo "Bumped up build version to $BUILD_VERSION"
}
if [ "${CONFIGURATION}" = "Release" ]; then
bump_version
fi
typeset -i BUILD_VERSION=$(cat "$PROJECT_DIR/LASTVERSION")
# Get location of unparsed Info.plist
PROJ_INFO_PLIST_INPUT=$(basename "$INFOPLIST_FILE" .plist)
# Get location of parsed Info.plist
PROJ_INFO_PLIST_PATH="$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME/Info"
# Get version number from unparsed Info.plist
PROJ_VERSION=$(defaults read "$PROJECT_DIR/$INFOPLIST_FILE" CFBundleVersion)
GIT_BRANCH=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
GIT_HASH=$(git rev-parse --short HEAD)
PROJ_NEW_VERSION=$PROJ_VERSION.$BUILD_VERSION
echo Version is $PROJ_NEW_VERSION
echo GIT branch is $GIT_BRANCH
echo GIT hash is $GIT_HASH
# Write new version number to parsed Info.plist
defaults write "$PROJ_INFO_PLIST_PATH" CFBundleVersion $PROJ_NEW_VERSION
defaults write "$PROJ_INFO_PLIST_PATH" GitBranch $GIT_BRANCH
defaults write "$PROJ_INFO_PLIST_PATH" GitHash $GIT_HASH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment