Skip to content

Instantly share code, notes, and snippets.

@stig
Created August 10, 2013 09:11
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stig/6199708 to your computer and use it in GitHub Desktop.
Save stig/6199708 to your computer and use it in GitHub Desktop.
Short script to set CFBundleShortVersionString from the latest tag + CFBundleVersion from the number of commits on the master branch. It is useful to use with Jenkins, and doesn't require you to update the repository, so you don't pollute your change history with "updated version" commits.
#!/bin/sh
# This script automatically sets the version and short version string of an
# Xcode project from the Git repository containing the project.
#
# To use this script in Xcode 4, add the contents to a "Run Script" build
# phase for your application target.
set -o errexit
set -o nounset
INFO_PLIST="${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Info"
# Use the latest version tag for CFBundleShortVersionString. I tag releases
# in Git using the format 0.0.0; this assumes you're doing the same.
MARKETING_VERSION=$(git --git-dir="${PROJECT_DIR}/.git" --work-tree="${PROJECT_DIR}" describe --abbrev=0)
# Apple wants CFBundleVersion to be a monotonically increasing integer, so
# use the number of commits on master.
VERSION=$(git --git-dir="${PROJECT_DIR}/.git" --work-tree="${PROJECT_DIR}" rev-list master | wc -l)
defaults write $INFO_PLIST CFBundleShortVersionString $MARKETING_VERSION
defaults write $INFO_PLIST CFBundleVersion $VERSION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment