automatic build number incrementing

33 views
Skip to first unread message

Mark Lilback

unread,
May 18, 2012, 12:06:00 PM5/18/12
to cocoaheads...@googlegroups.com
I mentioned this to Mark last night and thought I'd share with everyone. This a shell script I add as a build phase to all my products that increments the build number every time I do an archive build. Be share to place it before the Copy Resources phase.

#!/bin/bash
if [[ ${CONFIGURATION} == "Archive" ]]; then
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" ${INFOPLIST_FILE})
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" ${INFOPLIST_FILE}
fi


Ben Lachman

unread,
May 18, 2012, 3:41:09 PM5/18/12
to cocoaheads...@googlegroups.com
We do something similar for our latest app (in review), albeit a bit more complicated.  This would go after copy resources however since it modifies the info.plist in the app after it's built.  This has the advantage of basing your version number off of the svn version and not marking your info plist modified (and thus leading to endless commits).  Lastly, it will also write your version into your Settings.bundle if you have one which can be nice.

It handles some weird cases with paths we've run into as well.

->Ben

(uses) /bin/bash


STRIPPED_BASE_DIR=`echo ${TARGET_BUILD_DIR} | sed -e 's/"//g'`
INFOPLIST_TARGET_PATH="${STRIPPED_BASE_DIR}/${INFOPLIST_PATH}"
SETTINGS_ROOTPLIST="${STRIPPED_BASE_DIR}/${WRAPPER_NAME}/Settings.bundle/Root.plist"

REV=`svnversion -nc | /usr/bin/sed -e 's/^[^:]*://;s/[A-Za-z]//'`

/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${REV}" "${INFOPLIST_TARGET_PATH}"

# after this point we're just writing a human readable version into the Settings.bundle for an iOS app
# this is the key you want the version number stored in your NSUserDefaults under, make sure it appears in Settings.bundle/Root.plist
DEFAULTS_VERSION_KEY="ATSFullVersionString"

VER=`/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "${INFOPLIST_TARGET_PATH}"`

# ex: 1.0 (395)
HUMAN_VERSION_STRING="${VER} (${REV})"

# Check to see if Settings.bundle/Root.plist exists, otherwise does nothing (e.g. on Mac, if you don't use a Settings.bundle, etc.)
if [ -e ${SETTINGS_ROOTPLIST} ]; then
    # this checks the first 15 entries in the root.plist for a key matching our version number
    for i in {0..15}; do
        CURRENT_KEY=`/usr/libexec/PlistBuddy -c "Print PreferenceSpecifiers:${i}:Key" "${SETTINGS_ROOTPLIST}"`

        if [ "${CURRENT_KEY}" == "${DEFAULTS_VERSION_KEY}"
        then
            /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:${i}:DefaultValue ${HUMAN_VERSION_STRING}" "${SETTINGS_ROOTPLIST}"
            break
        fi
    done
fi
--
Ben Lachman
Acacia Tree Software

twitter: @blach
mobile: 740.590.0009

Mark Lilback

unread,
May 18, 2012, 7:42:06 PM5/18/12
to cocoaheads...@googlegroups.com
I used to do it that way, but I didn't like the way the numbers would jump so much. Also, while it works for svn, it doesn't work for git.

On May 18, 2012, at 3:41 PM, Ben Lachman wrote:

> We do something similar for our latest app (in review), albeit a bit more complicated. This would go after copy resources however since it modifies the info.plist in the app after it's built. This has the advantage of basing your version number off of the svn version and not marking your info plist modified (and thus leading to endless commits). Lastly, it will also write your version into your Settings.bundle if you have one which can be nice.
>


--
Mark Lilback
ma...@lilback.com
http://www.lilback.com/
Reply all
Reply to author
Forward
0 new messages