Skip to content

Instantly share code, notes, and snippets.

@Galarius
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save Galarius/ef2a8792dd37fb6f41b9 to your computer and use it in GitHub Desktop.

Select an option

Save Galarius/ef2a8792dd37fb6f41b9 to your computer and use it in GitHub Desktop.
Build app version using the latest hg commit hash and datetime.
# Custom iOS app version
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Drag the "Run Script" below "Link Binaries With Libraries"
# 6. Insure that LastCommitHash and LastBuildDate are in your app plist file.
# 7. Somewhere in your obj-c code paste:
# + (NSString *)appVersionCommitHash {
# NSString *lastCommitHash = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"LastCommitHash"];
# return lastCommitHash; }
# + (NSString *)appVersionDate {
# NSString *lastBuildDate = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"LastBuildDate"];
# return lastBuildDate; }
# save the latest hg commit hash
# in case hg has alias in .bash_profile
if [ -f ~/.bash_profile ];
then
source ~/.bash_profile
fi
LAST_COMMIT_HASH=$(hg id -i)
/usr/libexec/PlistBuddy -c "Set :LastCommitHash $LAST_COMMIT_HASH" "$INFOPLIST_FILE"
# save the latest build date
NOW=$(date +'%y%m%d.%H%M')
/usr/libexec/PlistBuddy -c "Set :LastBuildDate $NOW" "$INFOPLIST_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment