A couple of years ago I posted my scripts for tagging and building. The build script doesn’t work so well for the App Stores and the Build and Archive-based submission process, so here’s an updated approach that works inside Xcode. (Same as my last article, I’m still using git, the tag.sh script, and Apple Generic Versioning (agv).)
- In your Xcode project, create a Shell Script target called GenGitVersion.
- Insert the following script in GenGitVersion’s Run Script phase, replacing the path to your git executable if need be:
Shell1234git=/usr/local/git/bin/gitversion=`$git describe`echo "#define GIT_VERSION $version" > InfoPlist.htouch Info.plist
- Make GenGitVersion a dependency of your main target.
- Add “InfoPlist.h” to your .gitignore file.
- In your main target’s build settings:
- Turn on Preprocess Info.plist File
- Set Info.plist Preprocessor Prefix File to InfoPlist.h
- In your app’s Info.plist set the Bundle versions string, short to GIT_VERSION
Now each time you build the main target, the version will be populated in the build’s Info.plist.
- If you tag a commit, the version returned by
git describeis the tag name. If the current commit isn’t tagged, you’ll get the most recent tag plus the number of additional commits and an abbreviated commit name. Here’s a 1.0b1 tag with 2 additional commits: 1.0b1-2-g3925f3b. This can be a good way to identify a private developer build.
- You can optionally add
git describeand the version will have
-dirtyappended if there are uncommitted changes to your working tree.
git describewill fail if there are no tags in the current working tree.