-
Notifications
You must be signed in to change notification settings - Fork 10
/
bumpversion.sh
executable file
·146 lines (126 loc) · 5.07 KB
/
bumpversion.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# Thanks goes to @pete-otaqui for the initial gist:
# https://gist.github.com/pete-otaqui/4188238
#
# Original version modified by Marek Suscak
#
# 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" or even "1.2.3-beta+001.ab"
# 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 CHANGELOG.md (under the title of the new version
# number), give user a chance to review and update the changelist
# manually if needed and create a GIT tag.
NOW="$(date +'%B %d, %Y')"
RED="\033[1;31m"
GREEN="\033[0;32m"
YELLOW="\033[1;33m"
BLUE="\033[1;34m"
PURPLE="\033[1;35m"
CYAN="\033[1;36m"
WHITE="\033[1;37m"
RESET="\033[0m"
LATEST_HASH=`git log --pretty=format:'%h' -n 1`
QUESTION_FLAG="${GREEN}?"
WARNING_FLAG="${YELLOW}!"
NOTICE_FLAG="${CYAN}❯"
ADJUSTMENTS_MSG="${QUESTION_FLAG} ${CYAN}Now you can make adjustments to ${WHITE}CHANGELOG.md${CYAN}. Then press enter to continue."
PUSHING_MSG="${NOTICE_FLAG} Pushing new version to the ${WHITE}origin${CYAN}..."
update_version_on_files () {
# Check all files in the given folder
for pathname in "$1"/*; do
# If the file is a directory check the files inside the directory
if [ -d "$pathname" ]; then
update_version_on_files "$pathname"
else
# Find files that end on *.yaml or *.yml
if [[ "$pathname" == *.yaml || "$pathname" == *.yml ]]; then
# Do not change the version of iris base images
if [[ "$pathname" != *irisdemo-base* ]];
then
# Change the version of our images
sed -E -i '' "s;version-[0-9][0-9.]*;version-$INPUT_STRING;g" $pathname
git add $pathname
fi
fi
fi
done
}
if [ -f VERSION ]; then
BASE_STRING=`cat VERSION`
BASE_LIST=(`echo $BASE_STRING | tr '.' ' '`)
V_MAJOR=${BASE_LIST[0]}
V_MINOR=${BASE_LIST[1]}
V_PATCH=${BASE_LIST[2]}
echo -e "${NOTICE_FLAG} Current version: ${WHITE}$BASE_STRING"
echo -e "${NOTICE_FLAG} Latest commit hash: ${WHITE}$LATEST_HASH"
V_MINOR=$((V_MINOR + 1))
V_PATCH=0
SUGGESTED_VERSION="$V_MAJOR.$V_MINOR.$V_PATCH"
echo -ne "${QUESTION_FLAG} ${CYAN}Enter a version number [${WHITE}$SUGGESTED_VERSION${CYAN}]: "
read INPUT_STRING
if [ "$INPUT_STRING" = "" ]; then
INPUT_STRING=$SUGGESTED_VERSION
fi
echo -e "${NOTICE_FLAG} Will set new version to be ${WHITE}$INPUT_STRING"
echo $INPUT_STRING > VERSION
#
# Fix files that make reference to the new version. Only change versions of images
# belonging to this repository. References to other images such as Spark and Zeppelin
# will be let alone.
#
for filename in ./docker-compose*.yml; do
sed -E -i '' "s;(intersystemsdc/irisdemo-demo-htap:.+)-version-[0-9][0-9.]*;\1-version-$INPUT_STRING;g" $filename
done
#sed -E -i '' "s;(intersystemsdc/irisdemo-demo-htap:.+)-version-[0-9][0-9.]*;\1-version-$INPUT_STRING;g" ./README.md
sed -E -i '' "s;version-[0-9][0-9.]*;version-$INPUT_STRING;g" ./ICM/ICMDurable/base_env.sh
update_version_on_files ./Kubernetes
echo "## $INPUT_STRING ($NOW)" > tmpfile
git log --pretty=format:" - %s" "v$BASE_STRING"...HEAD >> tmpfile
echo "" >> tmpfile
echo "" >> tmpfile
cat CHANGELOG.md >> tmpfile
mv tmpfile CHANGELOG.md
echo -e "$ADJUSTMENTS_MSG"
read
echo -e "$PUSHING_MSG"
#
# Add files that were changed by the bumpversion.sh:
#
git add CHANGELOG.md VERSION ./ICM/ICMDurable/base_env.sh
for filename in ./docker-compose*.yml; do
git add $filename
done
git commit -m "Bump version to ${INPUT_STRING}."
git tag -a -m "Tag version ${INPUT_STRING}." "v$INPUT_STRING"
git push origin --tags
git push
else
echo -e "${WARNING_FLAG} Could not find a VERSION file."
echo -ne "${QUESTION_FLAG} ${CYAN}Do you want to create a version file and start from scratch? [${WHITE}y${CYAN}]: "
read 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 "0.1.0" > VERSION
echo "## 0.1.0 ($NOW)" > CHANGELOG.md
git log --pretty=format:" - %s" >> CHANGELOG.md
echo "" >> CHANGELOG.md
echo "" >> CHANGELOG.md
echo -e "$ADJUSTMENTS_MSG"
read
echo -e "$PUSHING_MSG"
git add VERSION CHANGELOG.md
git commit -m "Add VERSION and CHANGELOG.md files, Bump version to v0.1.0."
git tag -a -m "Tag version 0.1.0." "v0.1.0"
git push origin --tags
fi
fi
echo -e "${NOTICE_FLAG} Finished."