Skip to content

Instantly share code, notes, and snippets.

@wwwins
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save wwwins/8929205 to your computer and use it in GitHub Desktop.

Select an option

Save wwwins/8929205 to your computer and use it in GitHub Desktop.
auto-bump a version number
#!/bin/sh
# auto bump a version number for git
# ie: 1.1 -> 1.2
# usage: bump.sh Project-Info.plist
if [ $# -ne 1 ]; then
echo usage: $0 plist-file
exit 1
fi
PLIST="$1"
DIR="$(dirname "$plist")"
VERSIONNUM=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${PLIST}")
DATE=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PLIST}")
NEWDATE=$(date "+%Y%m%d")
NEWSUBVERSION=`echo $VERSIONNUM | awk -F "." '{print $2}'`
NEWSUBVERSION=$(($NEWSUBVERSION + 1))
NEWVERSIONSTRING=`echo $VERSIONNUM | awk -F "." '{print $1 ".'$NEWSUBVERSION'" }'`
if [ -z "$VERSIONNUM" ]; then
echo "No build number in $PLIST"
exit 2
fi
echo "Git commit and release..."
git checkout -b release/$NEWVERSIONSTRING develop
echo "Bumped build number $VERSIONNUM -> $NEWVERSIONSTRING ($NEWDATE)"
/usr/libexec/Plistbuddy -c "Set :CFBundleShortVersionString $NEWVERSIONSTRING" "${PLIST}"
/usr/libexec/Plistbuddy -c "Set :CFBundleVersion $NEWDATE" "${PLIST}"
echo "Prepare for $NEWVERSIONSTRING"
git commit -a -m "Prepare for $NEWVERSIONSTRING"
git checkout master
git merge --no-ff release/$NEWVERSIONSTRING
git tag -a $NEWVERSIONSTRING -m "Added tag $NEWVERSIONSTRING"
git checkout develop
git merge --no-ff release/$NEWVERSIONSTRING
git branch -d release/$NEWVERSIONSTRING
echo "done..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment