Skip to content

Instantly share code, notes, and snippets.

@bmutinda
Forked from marteinn/bump-version.sh
Created February 18, 2017 09:01
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 bmutinda/66c64af0a172c9698d57e5cbfa7db994 to your computer and use it in GitHub Desktop.
Save bmutinda/66c64af0a172c9698d57e5cbfa7db994 to your computer and use it in GitHub Desktop.
This is a git hook for git-flow that I use for android studio that auto-bumps the project version and version code.
#!/bin/sh
# Bumps the version number to relevant files at the end of any release and hotfix start
#
# Positional arguments:
# $1 The version (including the version prefix)
# $2 The origin remote
# $3 The full branch name (including the release prefix)
# $4 The base from which this release is started
#
# The following variables are available as they are exported by git-flow:
#
# MASTER_BRANCH - The branch defined as Master
# DEVELOP_BRANCH - The branch defined as Develop
VERSION=$1
# Remove v prefix (if present)
VERSION=${VERSION#"v"}
# Generate clean build number
VERSION_CODE="$(cat gradle.properties | grep "^VERSION_CODE=.*$" | sed -E 's/^VERSION_CODE=(.*)/\1/')"
VERSION_CODE=$(expr $VERSION_CODE + 1)
ROOTDIR=$(git rev-parse --show-toplevel)
# Bump django version
sed -i.bak 's/^VERSION_NAME=.*/VERSION_NAME='''$VERSION'''/' $ROOTDIR/gradle.properties
rm gradle.properties.bak
# Bump django version
sed -i.bak 's/^VERSION_CODE=.*/VERSION_CODE='''$VERSION_CODE'''/' $ROOTDIR/gradle.properties
rm gradle.properties.bak
# Commit changes
git commit -a -m "Version bump $VERSION"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment