-
Notifications
You must be signed in to change notification settings - Fork 2
/
bumpversion.sh
executable file
·73 lines (67 loc) · 2.75 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
#!/bin/bash
# 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.
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ -f VERSION ]; then
echo "Fetching tags from origin"
git fetch origin --tags # Pull all tags from origin
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 "Current version : $BASE_STRING"
V_MINOR=$((V_MINOR + 1))
V_PATCH=0
SUGGESTED_VERSION="$V_MAJOR.$V_MINOR.$V_PATCH"
read -p "Enter a version number [$SUGGESTED_VERSION]: " INPUT_STRING
if [ "$INPUT_STRING" = "" ]; then
INPUT_STRING=$SUGGESTED_VERSION
fi
echo "Will set new version to be $INPUT_STRING"
echo $INPUT_STRING > VERSION
echo "Version $INPUT_STRING:" > tmpfile
git log --no-merges --date=iso --pretty=format:" - %cd #%h - %aN - %s" "v$BASE_STRING"...HEAD | sed -e 's/ -0300//g' | sed -e 's/ +0000//g' >> tmpfile
echo "" >> tmpfile
echo "" >> tmpfile
cat CHANGES >> tmpfile
mv tmpfile CHANGES
read -p "Confirm release [$SUGGESTED_VERSION] [YES or NO]: " INPUT_CONFIRM_RELEASE
if [ "$INPUT_CONFIRM_RELEASE" != "YES" ]; then
git checkout VERSION
echo "Exiting."
exit 0
fi
git add CHANGES VERSION
git commit -m "Version bump to $INPUT_STRING"
git tag -a -m "Tagging version $INPUT_STRING" "v$INPUT_STRING"
git push origin --tags
git push origin $CURRENT_BRANCH
else
echo "Could not find a VERSION file"
read -p "Do you want to create a version file and start from scratch? [y]" 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 "Version 0.1.0" > CHANGES
git log --no-merges --date=iso --pretty=format:"- %cd - %aN - %s" >> CHANGES
echo "" >> CHANGES
echo "" >> CHANGES
git add VERSION CHANGES
git commit -m "Added VERSION and CHANGES files, Version bump to v0.1.0"
git tag -a -m "Tagging version 0.1.0" "v0.1.0"
git push origin --tags
fi
fi