|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Thanks goes to @pete-otaqui for the initial gist: |
| 4 | +# https://gist.github.com/pete-otaqui/4188238 |
| 5 | +# |
| 6 | +# Original version modified by Marek Suscak |
| 7 | +# |
| 8 | +# works with a file called VERSION in the current directory, |
| 9 | +# the contents of which should be a semantic version number |
| 10 | +# such as "1.2.3" or even "1.2.3-beta+001.ab" |
| 11 | + |
| 12 | +# this script will display the current version, automatically |
| 13 | +# suggest a "minor" version update, and ask for input to use |
| 14 | +# the suggestion, or a newly entered value. |
| 15 | + |
| 16 | +# once the new version number is determined, the script will |
| 17 | +# pull a list of changes from git history, prepend this to |
| 18 | +# a file called CHANGELOG.md (under the title of the new version |
| 19 | +# number), give user a chance to review and update the changelist |
| 20 | +# manually if needed and create a GIT tag. |
| 21 | + |
| 22 | +NOW="$(date +'%B %d, %Y')" |
| 23 | +RED="\033[1;31m" |
| 24 | +GREEN="\033[0;32m" |
| 25 | +YELLOW="\033[1;33m" |
| 26 | +BLUE="\033[1;34m" |
| 27 | +PURPLE="\033[1;35m" |
| 28 | +CYAN="\033[1;36m" |
| 29 | +WHITE="\033[1;37m" |
| 30 | +RESET="\033[0m" |
| 31 | + |
| 32 | +LATEST_HASH=`git log --pretty=format:'%h' -n 1` |
| 33 | + |
| 34 | +QUESTION_FLAG="${GREEN}?" |
| 35 | +WARNING_FLAG="${YELLOW}!" |
| 36 | +NOTICE_FLAG="${CYAN}❯" |
| 37 | + |
| 38 | +ADJUSTMENTS_MSG="${QUESTION_FLAG} ${CYAN}Now you can make adjustments to ${WHITE}CHANGELOG.md${CYAN}. Then press enter to continue." |
| 39 | +PUSHING_MSG="${NOTICE_FLAG} Pushing new version to the ${WHITE}origin${CYAN}..." |
| 40 | + |
| 41 | +if [ -f VERSION ]; then |
| 42 | + BASE_STRING=`cat VERSION` |
| 43 | + BASE_LIST=(`echo $BASE_STRING | tr '.' ' '`) |
| 44 | + V_MAJOR=${BASE_LIST[0]} |
| 45 | + V_MINOR=${BASE_LIST[1]} |
| 46 | + V_PATCH=${BASE_LIST[2]} |
| 47 | + echo -e "${NOTICE_FLAG} Current version: ${WHITE}$BASE_STRING" |
| 48 | + echo -e "${NOTICE_FLAG} Latest commit hash: ${WHITE}$LATEST_HASH" |
| 49 | + V_MINOR=$((V_MINOR + 1)) |
| 50 | + V_PATCH=0 |
| 51 | + SUGGESTED_VERSION="$V_MAJOR.$V_MINOR.$V_PATCH" |
| 52 | + echo -ne "${QUESTION_FLAG} ${CYAN}Enter a version number [${WHITE}$SUGGESTED_VERSION${CYAN}]: " |
| 53 | + read INPUT_STRING |
| 54 | + if [ "$INPUT_STRING" = "" ]; then |
| 55 | + INPUT_STRING=$SUGGESTED_VERSION |
| 56 | + fi |
| 57 | + echo -e "${NOTICE_FLAG} Will set new version to be ${WHITE}$INPUT_STRING" |
| 58 | + echo $INPUT_STRING > VERSION |
| 59 | + echo "## $INPUT_STRING ($NOW)" > tmpfile |
| 60 | + git log --pretty=format:" - %s" "v$BASE_STRING"...HEAD >> tmpfile |
| 61 | + echo "" >> tmpfile |
| 62 | + echo "" >> tmpfile |
| 63 | + cat CHANGELOG.md >> tmpfile |
| 64 | + mv tmpfile CHANGELOG.md |
| 65 | + echo -e "$ADJUSTMENTS_MSG" |
| 66 | + read |
| 67 | + echo -e "$PUSHING_MSG" |
| 68 | + git add CHANGELOG.md VERSION |
| 69 | + git commit -m "Bump version to ${INPUT_STRING}." |
| 70 | + git tag -a -m "Tag version ${INPUT_STRING}." "v$INPUT_STRING" |
| 71 | + git push origin --tags |
| 72 | +else |
| 73 | + echo -e "${WARNING_FLAG} Could not find a VERSION file." |
| 74 | + echo -ne "${QUESTION_FLAG} ${CYAN}Do you want to create a version file and start from scratch? [${WHITE}y${CYAN}]: " |
| 75 | + read RESPONSE |
| 76 | + if [ "$RESPONSE" = "" ]; then RESPONSE="y"; fi |
| 77 | + if [ "$RESPONSE" = "Y" ]; then RESPONSE="y"; fi |
| 78 | + if [ "$RESPONSE" = "Yes" ]; then RESPONSE="y"; fi |
| 79 | + if [ "$RESPONSE" = "yes" ]; then RESPONSE="y"; fi |
| 80 | + if [ "$RESPONSE" = "YES" ]; then RESPONSE="y"; fi |
| 81 | + if [ "$RESPONSE" = "y" ]; then |
| 82 | + echo "0.1.0" > VERSION |
| 83 | + echo "## 0.1.0 ($NOW)" > CHANGELOG.md |
| 84 | + git log --pretty=format:" - %s" >> CHANGELOG.md |
| 85 | + echo "" >> CHANGELOG.md |
| 86 | + echo "" >> CHANGELOG.md |
| 87 | + echo -e "$ADJUSTMENTS_MSG" |
| 88 | + read |
| 89 | + echo -e "$PUSHING_MSG" |
| 90 | + git add VERSION CHANGELOG.md |
| 91 | + git commit -m "Add VERSION and CHANGELOG.md files, Bump version to v0.1.0." |
| 92 | + git tag -a -m "Tag version 0.1.0." "v0.1.0" |
| 93 | + git push origin --tags |
| 94 | + fi |
| 95 | +fi |
| 96 | + |
| 97 | +echo -e "${NOTICE_FLAG} Finished." |
0 commit comments