Created
March 9, 2013 22:03
-
-
Save charlesbedrosian/5125945 to your computer and use it in GitHub Desktop.
XCode post build script to setup settings with current build information, different for Debug and Release versions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#get commit stats (date and SHA) | |
commit_sha=`git rev-parse --short HEAD` | |
commit_ts=`git show -s --format="%ci" $sha` | |
commit_dt=${commit_ts:0:16} | |
commit_count=`git log --oneline | wc -l | tr -d ' '` | |
SETTINGSBUNDLEPATH="$CODESIGNING_FOLDER_PATH/Settings.bundle/Root.plist" | |
#where are we getting the original data from? | |
echo Reading from plist: $INFOPLIST_FILE | |
echo Writing to plist: $SETTINGSBUNDLEPATH | |
echo Commit Hash: $commit_sha | |
echo Commit Date: $commit_dt | |
echo Commit Count: $commit_count | |
#set commit CFBundleVersion to the number of commits as this should consistently increase | |
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $commit_count" "$INFOPLIST_FILE" | |
#gather info about the settings bundle from the source code - it will get inserted | |
#into the built plist | |
productVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$INFOPLIST_FILE") | |
#if a release build, we only want to show the version | |
if [ "$CONFIGURATION" = "Release" ] ; then | |
echo "Replacing $CODESIGNING_FOLDER_PATH/Settings.bundle for '$CONFIGURATION' build" | |
/usr/libexec/PlistBuddy -c "Delete :PreferenceSpecifiers" "$SETTINGSBUNDLEPATH" | |
/usr/libexec/PlistBuddy -c "Add :StringsTable string 'Root'" "$SETTINGSBUNDLEPATH" | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers array" "$SETTINGSBUNDLEPATH" | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:0 dict" "$SETTINGSBUNDLEPATH" | |
#add version number in settings bundle | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:0:Type string 'PSGroupSpecifier'" "$SETTINGSBUNDLEPATH" | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:0:Title string 'Version Information'" "$SETTINGSBUNDLEPATH" | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:1:Type string 'PSTitleValueSpecifier'" "$SETTINGSBUNDLEPATH" | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:1:Title string '$CONFIGURATION:'" "$SETTINGSBUNDLEPATH" | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:1:Key string 'appVersion'" "$SETTINGSBUNDLEPATH" | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:1:DefaultValue string '$productVersion build $commit_count'" "$SETTINGSBUNDLEPATH" | |
echo "Version for $CONFIGURATION: '$productVersion build $commit_count'" | |
else | |
#for Ad-Hoc and Debug builds, we want to include the ability to set the API endpoint | |
#and view the commit information | |
#modify the PList, updating (or adding) the product version | |
key=3 | |
existing=`/usr/libexec/PlistBuddy -c "Print: PreferenceSpecifiers:$key" "$SETTINGSBUNDLEPATH"` | |
if [ -z "$existing" ] ; then | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:$key:DefaultValue string '$productVersion build $commit_count'" "$SETTINGSBUNDLEPATH" | |
else | |
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:$key:DefaultValue '$productVersion build $commit_count'" "$SETTINGSBUNDLEPATH" | |
fi | |
#modify the PList, updating (or adding) the commit sha1 | |
key=4 | |
existing=$(/usr/libexec/PlistBuddy -c "Print: PreferenceSpecifiers:$key" "$SETTINGSBUNDLEPATH") | |
if [ -z "$existing" ] ; then | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:$key:DefaultValue string '$commit_sha'" "$SETTINGSBUNDLEPATH" | |
else | |
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:$key:DefaultValue '$commit_sha'" "$SETTINGSBUNDLEPATH" | |
fi | |
#modify the PList, updating (or adding) the commit date | |
key=5 | |
existing=$(/usr/libexec/PlistBuddy -c "Print: PreferenceSpecifiers:$key" "$SETTINGSBUNDLEPATH") | |
if [ -z "$existing" ] ; then | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:$key:DefaultValue string '$commit_dt'" "$SETTINGSBUNDLEPATH" | |
else | |
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:$key:DefaultValue '$commit_dt'" "$SETTINGSBUNDLEPATH" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment