Skip to content

Instantly share code, notes, and snippets.

@codeb2cc
Created May 16, 2014 06:31
Show Gist options
  • Save codeb2cc/76c21793f3d96c4eaed3 to your computer and use it in GitHub Desktop.
Save codeb2cc/76c21793f3d96c4eaed3 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Bump project version
PY_INIT=__init__.py
PACKAGE_JSON=public/package.json
BOWER_JSON=public/bower.json
VERSION=(`grep -Eo "[0-9]+\.[0-9]+\.[0-9]" $PY_INIT`)
echo "Project current version: [$VERSION] "
for FILE in $PACKAGE_JSON $BOWER_JSON
do
grep -q "\"version\": \"$VERSION\"" $FILE
if [ ! $? = 0 ]; then
echo "$(tput setaf 1)Version $VERSION not found in $FILE $(tput sgr0)"
exit 1
fi
done
BASES=(`echo $VERSION | tr '.' ' '`)
V_MAJOR=${BASES[0]}
V_MINOR=${BASES[1]}
V_PATCH=${BASES[2]}
if [ "$1" = "" ]; then
BUMP="minor"
else
BUMP=$1
fi
if [ "$BUMP" = "major" ]; then
V_MAJOR=$((V_MAJOR + 1))
V_MINOR=0
V_PATCH=0
elif [ "$BUMP" = "minor" ]; then
V_MINOR=$((V_MINOR + 1))
V_PATCH=0
elif [ "$BUMP" = "patch" ]; then
V_PATCH=$((V_PATCH + 1))
else
echo "$(tput setaf 1)Invalid Bump Option. [majon|minor|patch]$(tput sgr0)"
exit 1
fi
NEXT_VERSION="$V_MAJOR.$V_MINOR.$V_PATCH"
read -p "Bump to [$NEXT_VERSION] and update changelog? (Y): " CONFIRM
if [ "$CONFIRM" = "" ]; then CONFIRM="Y"; fi
if [ "$CONFIRM" = "y" ]; then CONFIRM="Y"; fi
if [ "$CONFIRM" = "yes" ]; then CONFIRM="Y"; fi
if [ "$CONFIRM" = "YES" ]; then CONFIRM="Y"; fi
if [ "$CONFIRM" = "Y" ]; then
sed -i "s/$VERSION/$NEXT_VERSION/" $PY_INIT
sed -i 's/\("version": "\)'$VERSION'/\1'$NEXT_VERSION'/' $PACKAGE_JSON
sed -i 's/\("version": "\)'$VERSION'/\1'$NEXT_VERSION'/' $BOWER_JSON
git changelog --tag $NEXT_VERSION
echo "$(tput setaf 2)Done.$(tput sgr0)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment