Last active
July 19, 2018 06:48
-
-
Save muncman/6762380 to your computer and use it in GitHub Desktop.
Pair of scripts for automatically updating the build number for Xcode projects. The second one restores the number so you have no outgoing version control changes.
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
#!/bin/sh | |
# Set in Product | Scheme | Edit Scheme | Build | Post-actions as a new Run Script item. | |
# echo Restoring build number | |
# ${PROJECT_DIR}/Scripts/restore_build_number.sh | |
# Select your target in the "Provide build settings from" dropdown. | |
set -e | |
if [ -z "$SRCROOT" ] | |
then | |
echo "Run this from the project root." | |
export SRCROOT=`pwd` | |
echo "Setting SRCROOT to $SRCROOT" | |
fi | |
if [ -z "$INFOPLIST_FILE" ] | |
then | |
export INFOPLIST_FILE=YOUR_PROJECT/YOUR_PROJECT-Info.plist | |
echo "Setting INFOPLIST_FILE to $INFOPLIST_FILE" | |
fi | |
if [ -f "$SRCROOT/Scripts/previous_build_number.txt" ] | |
then | |
CFBundleVersion=`cat $SRCROOT/Scripts/previous_build_number.txt` | |
else | |
exit 0 | |
fi | |
echo Restoring CFBundleVersion to $CFBundleVersion | |
[ -f "$SRCROOT/Scripts/previous_build_number.txt" ] && rm -f "$SRCROOT/Scripts/previous_build_number.txt" | |
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $CFBundleVersion" "$SRCROOT/$INFOPLIST_FILE" |
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
#!/bin/sh | |
# Set in Product | Scheme | Edit Scheme | Build | Pre-actions as a new Run Script item. | |
# echo Updating build number | |
# ${PROJECT_DIR}/Scripts/update_build_number.sh | |
# Select your target in the "Provide build settings from" dropdown. | |
# NOTE: You need to change YOUR_PROJECT with your actual project name. | |
set -e | |
if [ -z "$SRCROOT" ] | |
then | |
echo "Run this from the project root." | |
export SRCROOT=`pwd` | |
echo "Setting SRCROOT to $SRCROOT" | |
fi | |
if [ -z "$INFOPLIST_FILE" ] | |
then | |
export INFOPLIST_FILE=YOUR_PROJECT/YOUR_PROJECT-Info.plist | |
echo "Setting INFOPLIST_FILE to $INFOPLIST_FILE" | |
fi | |
# Clean slate, if needed, to start. | |
# Sometimes Xcode is lame and doesn't complete the Post-action reset. | |
$SRCROOT/Scripts/restore_build_number.sh | |
CFBundleVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$SRCROOT/$INFOPLIST_FILE") | |
echo CFBundleVersion was $CFBundleVersion | |
# Save for restoration; to avoid outgoing VCS change. | |
[ -f "$SRCROOT/Scripts/previous_build_number.txt" ] && rm -f "$SRCROOT/Scripts/previous_build_number.txt" | |
echo $CFBundleVersion > $SRCROOT/Scripts/previous_build_number.txt | |
DotTimestamp=$(date '+.%m%d%H%M') | |
echo Appending timestamp of $DotTimestamp | |
CFBundleVersion=$CFBundleVersion$DotTimestamp | |
echo Updating CFBundleVersion to $CFBundleVersion | |
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $CFBundleVersion" "$SRCROOT/$INFOPLIST_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment