Skip to content

Instantly share code, notes, and snippets.

@jalvarezsamayoa
Created October 2, 2015 13:15
Show Gist options
  • Save jalvarezsamayoa/dd174b54eb1fafb3e489 to your computer and use it in GitHub Desktop.
Save jalvarezsamayoa/dd174b54eb1fafb3e489 to your computer and use it in GitHub Desktop.
Bump puppet module version with git-flow plugin
# add this fuction to your .bashrc or .zshrc
# REQUIRES:
# * git
# * git flow plugin (https://github.com/nvie/gitflow)
# bump_module_version
# This function will:
# 1. calculate your next patch version
# 2. open a release branch
# 3. update your metadata.json with the new version
# 4. close the release branch
# 5. push changes to master, develop and tags
function bump_module_version(){
if [ -f metadata.json ]; then
BASE_STRING="$(cat metadata.json | grep \"version\": | awk -F\" '{print $4}')"
BASE_LIST=(`echo $BASE_STRING | tr '.' ' '`)
V_MAJOR=${BASE_LIST[1]}
V_MINOR=${BASE_LIST[2]}
V_PATCH=${BASE_LIST[3]}
echo "Current version : $BASE_STRING"
V_PATCH=$((V_PATCH + 1))
NEW_VERSION="$V_MAJOR.$V_MINOR.$V_PATCH"
git flow release start $NEW_VERSION
sed -i '' "s/\"version\": \"$BASE_STRING\"/\"version\": \"$NEW_VERSION\"/" metadata.json
git add metadata.json
git commit -am "Bump version to $NEW_VERSION"
git flow release finish $NEW_VERSION
git checkout develop
git push origin develop
git checkout master
git push origin master
git push --tags origin
git checkout develop
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment