-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump_version
executable file
·79 lines (62 loc) · 2.21 KB
/
bump_version
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
#!/usr/bin/env bash
set -euo pipefail
USAGE='\033[1;31mUsage: ./bump_version major|minor|patch\033[0m'
if [ $# -ne 1 ]; then
echo -e $USAGE
exit 1
fi
major=$(grep 'versionMajor' gradle.properties | awk -F= '{print $2}')
minor=$(grep 'versionMinor' gradle.properties | awk -F= '{print $2}')
patch=$(grep 'versionPatch' gradle.properties | awk -F= '{print $2}')
version="${major}.${minor}.${patch}"
if [[ $1 = 'major' ]]; then
((major++))
minor=0
patch=0
elif [[ $1 = 'minor' ]]; then
((minor++))
patch=0
elif [[ $1 = 'patch' ]]; then
((patch++))
else
echo -e $USAGE
exit 1
fi
new_version="${major}.${minor}.${patch}"
read -p "Bump version from ${version} to ${new_version}? [y/N] " answer
case ${answer:0:1} in
y|Y)
if [[ -n $(git status --porcelain) ]]; then
echo -e "\033[1;32mStashing changes...\033[0m"
git stash push --include-untracked -m "version-bump-autostash"
autostashed=1
else
autostashed=0
fi
sed -i '' -e "s/^versionMajor=.*$/versionMajor=$major/" \
-e "s/^versionMinor=.*$/versionMinor=$minor/" \
-e "s/^versionPatch=.*$/versionPatch=$patch/" \
gradle.properties
echo -e "\033[1;34mBumped version to ${new_version}.\033[0m"
commits_since_last_tag=$(git log $(git describe --tags --abbrev=0)..HEAD --oneline --pretty=format:%s | sed -e 's/^/* /' -e 's/$/\\\\\\/')
echo "$commits_since_last_tag"
echo -e "\033[1;34mAdding build date to changelog...\033[0m"
today=$(date +'%Y-%m-%d %H:%M %Z')
cleaned_version=$(echo ${new_version} | sed 's/\./\\./g')
sed -i '' "3i \\
**${new_version}** (${today})\\
\\
${commits_since_last_tag}
\\
" CHANGELOG.md
echo -e "\033[1;34mOpening changelog for edition...\033[0m"
vim +5 '+normal $' +startinsert CHANGELOG.md
git commit -am "Bump version to ${new_version}"
git tag $new_version
if [[ "$autostashed" -eq 1 ]]; then
stash_id=$(git stash list | grep version-bump-autostash | head -n1 | awk -F: '{print $1}')
echo -e "\033[1;32mUnstashing changes...\033[0m"
git stash pop "$stash_id"
fi
;;
esac