Skip to content

Instantly share code, notes, and snippets.

@SamClewlow
Last active April 24, 2018 19:40
Show Gist options
  • Save SamClewlow/5f3c853c35f9b511f797872049fbf237 to your computer and use it in GitHub Desktop.
Save SamClewlow/5f3c853c35f9b511f797872049fbf237 to your computer and use it in GitHub Desktop.
CI Script to bump Xcode build number based on tags
# Call build-bump-tag.sh <PATH_TO_PLIST>
# Works for build numbers in major.minor.patch eg 0.0.1 versions
# Assumes at least one tag has already been added
# Get the variable values
lastTag=$(git describe --tags `git rev-list --tags --max-count=1`)
lastTagHash=$(git rev-parse --verify $lastTag^{commit})
headHash=$(git rev-parse --verify HEAD^{commit})
echo lastTag=$lastTag
echo lastTagHash=$lastTagHash
echo headHash=$headHash
# Does the current commit already have a tag (ie are we rebuilding?)
if [ "$lastTagHash" == "$headHash" ]
then
# Set build number to current tag value
echo "Set build number to current tag value"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $lastTag" $1
exit 0
fi
# Increment the least significant digit of the build number
echo "Increment the least significant digit of the build number"
newSubVersion=`echo $lastTag | awk -F "." '{print $3}'`
newSubVersion=$(($newSubVersion + 1))
newBuildNumber=`echo $lastTag | awk -F "." '{print $1 "." $2 ".'$newSubVersion'" }'`
echo newBuildNumber=$newBuildNumber
# Update the build version in the plist
echo "Update the build version in the plist - Expecting location to be passed in as $1"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $newBuildNumber" $1
# Create a new git tag and try to push it
git tag -a $newBuildNumber -m "$newBuildNumber"
git push origin $newBuildNumber
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment