Skip to content

Instantly share code, notes, and snippets.

@phillbaker
Created July 3, 2012 17:08
Show Gist options
  • Save phillbaker/3041093 to your computer and use it in GitHub Desktop.
Save phillbaker/3041093 to your computer and use it in GitHub Desktop.
Auto-incrementing build numbers in Xcode 4.3 (based on http://davedelong.com/node/37)
#!/bin/bash
# Set the marketing version of the project.
# Take the number from git and apply it to the project.
# Any "v" prepended to the git tag will be removed.
# Get the current release description from git.
git_version=`git describe --tags`
# Check to see if the tag starts with with "v", and remove if so.
if [[ "${git_version}" == v* ]]; then
git_version="${git_version#*v}"
fi
git_head=`git rev-parse --short HEAD`
# Create the full version
version="${git_version} ${git_head}"
# Set the version number
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $version" "$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
# Set the build number, CFBundleVersion (misnomer a la Apple)
if [ -f "$PROJECT_DIR/BUILD" ]
then
build_number=`cat "$PROJECT_DIR/BUILD"`
build_number=$(($build_number + 1))
else
build_number=1
fi
# Store the version number in a file at the project root: BUILD
echo "$build_number" > "$PROJECT_DIR/BUILD"
# Set the build number
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $build_number" "$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
@phillbaker
Copy link
Author

Include quotation marks around plist values, Xcode does funky things with spaces in project names.

See http://paulpeelen.com/2011/08/03/automatic-incremental-build-number-in-xcode-4-3/ for how to insert into XCode build phases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment