Created
November 17, 2014 06:10
-
-
Save ramonrails/27e14cdc61e1d9c41762 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Thu Nov 7 18:43:39 IST 2013, [email protected] (ramonrails) | |
# Borrowed from gitflow & bumpversion (URLs referenced below) and enhanced further | |
# works with a file called VERSION in the current directory, | |
# the contents of which should be a semantic version number | |
# such as "1.2.3" | |
# this script will display the current version, automatically | |
# suggest a "minor" version update, and ask for input to use | |
# the suggestion, or a newly entered value. | |
# once the new version number is determined, the script will | |
# pull a list of changes from git history, prepend this to | |
# a file called CHANGES (under the title of the new version | |
# number) and create a GIT tag. | |
# following methods are borrowed from gitflow source code | |
# https://github.com/nvie/gitflow/blob/develop/gitflow-common | |
git_local_branch_exists() { | |
has $1 $(git_local_branches) | |
} | |
gitflow_has_master_configured() { | |
local master=$(git config --get gitflow.branch.master) | |
[ "$master" != "" ] && git_local_branch_exists "$master" | |
} | |
gitflow_has_develop_configured() { | |
local develop=$(git config --get gitflow.branch.develop) | |
[ "$develop" != "" ] && git_local_branch_exists "$develop" | |
} | |
gitflow_has_prefixes_configured() { | |
git config --get gitflow.prefix.feature >/dev/null 2>&1 && \ | |
git config --get gitflow.prefix.release >/dev/null 2>&1 && \ | |
git config --get gitflow.prefix.hotfix >/dev/null 2>&1 && \ | |
git config --get gitflow.prefix.support >/dev/null 2>&1 && \ | |
git config --get gitflow.prefix.versiontag >/dev/null 2>&1 | |
} | |
gitflow_is_initialized() { | |
gitflow_has_master_configured && \ | |
gitflow_has_develop_configured && \ | |
[ "$(git config --get gitflow.branch.master)" != \ | |
"$(git config --get gitflow.branch.develop)" ] && \ | |
gitflow_has_prefixes_configured | |
} | |
# now bumpversion bash script continues | |
# borrowed from https://gist.github.com/pete-otaqui/4188238 | |
# Enahncements: | |
# * added parameter support major|minor|patch|bugfix|hotfix | |
# * without parameter, script assumes minor bump, as earlier | |
# * script will smartly use gitflow when available, or snap back to git | |
if [ -f VERSION ]; then | |
INPUT_STRING=`cat VERSION` | |
if [ gitflow_is_initialized ]; then | |
# git flow | |
# | |
echo "$(tput setaf 5)starting release $INPUT_STRING...$(tput sgr0)" | |
git flow release start "$INPUT_STRING" | |
# # mate CHANGES -w | |
# echo "git flow release finish $INPUT_STRING..." | |
# git flow release finish "$INPUT_STRING" | |
# # git push origin --all | |
else | |
# regular git tags | |
echo "$(tput setaf 5)git tag $INPUT_STRING...$(tput sgr0)" | |
git tag -a -m "Tagging version $INPUT_STRING" "v$INPUT_STRING" | |
echo "$(tput setaf 5)publishing tags...$(tput sgr0)" | |
git push origin --tags | |
fi | |
else | |
echo "$(tput setaf 5)Could not find a VERSION file$(tput sgr0)" | |
read -p "$(tput setaf 5)Do you want to create a VERSION file and start from scratch? [y] $(tput sgr0)" RESPONSE | |
if [ "$RESPONSE" = "" ]; then RESPONSE="y"; fi | |
if [ "$RESPONSE" = "Y" ]; then RESPONSE="y"; fi | |
if [ "$RESPONSE" = "Yes" ]; then RESPONSE="y"; fi | |
if [ "$RESPONSE" = "yes" ]; then RESPONSE="y"; fi | |
if [ "$RESPONSE" = "YES" ]; then RESPONSE="y"; fi | |
if [ "$RESPONSE" = "y" ]; then | |
echo "$(tput setaf 5)initializing VERSION & CHANGES...$(tput sgr0)" | |
echo "0.1.0" > VERSION | |
echo "Version 0.1.0" > CHANGES | |
echo "-------------------" >> CHANGES | |
echo "" >> CHANGES | |
git log --pretty=format:" - %s" >> CHANGES | |
echo "" >> CHANGES | |
echo "" >> CHANGES | |
git add VERSION CHANGES | |
git commit -m "Added VERSION and CHANGES files, Version updated to v0.1.0" | |
if [ gitflow_is_initialized ]; then | |
# git flow | |
git flow release start "v0.1.0" | |
git flow release finish "v0.1.0" | |
else | |
# regular git tags | |
git tag -a -m "Tagging version 0.1.0" "v0.1.0" | |
git push origin --tags | |
fi | |
echo "$(tput setaf 5)versioning and change log ready. $(tput setaf 2)let's roll!$(tput sgr0)" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment