Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.