Skip to content

Instantly share code, notes, and snippets.

@marteinn
Last active March 4, 2018 15:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marteinn/be178f437e17ade4a14aa838a07d95fa to your computer and use it in GitHub Desktop.
Save marteinn/be178f437e17ade4a14aa838a07d95fa 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. MIT license.
#!/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