Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@andrewtheis
Last active December 26, 2015 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewtheis/7127573 to your computer and use it in GitHub Desktop.
Save andrewtheis/7127573 to your computer and use it in GitHub Desktop.
Grabs the latest tag and sets the version number. You must only have version numbers as tags and they must be in format "X.y[.z]-B" where: X, y are major and minor versions; z (patch version) is optional; and B is the build number. Execute this with a post-build script phase similar to this: https://gist.github.com/andrewtheis/7127566
#!/bin/sh
PLIST_PATH="${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}"
# Get the current version and extract the version/build from there
LATEST_TAG=`xcrun git describe --tags --abbrev=0`
TAG_BUILD_NUM=${LATEST_TAG#*-}
TAG_VERSION=${LATEST_TAG%-*}
NEW_BUILD_NUM=$(expr $TAG_BUILD_NUM + 1)
# Set the new version
defaults write "${PLIST_PATH%.*}" 'CFBundleVersion' "${NEW_BUILD_NUM}" &> /dev/null
BUILD_NUM_SET=`defaults read "${PLIST_PATH%.*}" 'CFBundleVersion'`
echo "Set build number to ${BUILD_NUM_SET} in ${INFOPLIST_PATH}"
# Tag it!
xcrun git tag ${TAG_VERSION}-${BUILD_NUM_SET}
xcrun git push origin --tags
echo "Bumped and tagged."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment