-
Notifications
You must be signed in to change notification settings - Fork 1
/
prepare-release.sh
91 lines (76 loc) · 2.7 KB
/
prepare-release.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
#!/usr/bin/env bash
set -e
if [[ $(git rev-parse --abbrev-ref HEAD) != trunk ]]; then
echo Release version can be prepared automatically only from the trunk branch.
exit 0
fi
git reset --hard &> /dev/null
currentVersion=$(git describe --abbrev=0)
currentMajor=$(echo "$currentVersion" | cut -d. -f1)
currentMinor=$(echo "$currentVersion" | cut -d. -f2)
currentPatch=$(echo "$currentVersion" | cut -d. -f3)
echo "Ruler $currentVersion:"
PS3=$"What do you want to do? "
options=("Bump major" "Bump minor" "Bump patch" "Quit")
select option in "${options[@]}"
do
case $option in
"Bump major" )
newVersion="$((currentMajor + 1)).0.0"
break ;;
"Bump minor" )
newVersion="$currentMajor.$((currentMinor + 1)).0"
break ;;
"Bump patch" )
newVersion="$currentMajor.$currentMinor.$((currentPatch + 1))"
break ;;
"Quit" )
exit 0 ;;
* )
echo "Invalid option '$REPLY'."
exit 0 ;;
esac
done
function confirmBump {
read -rp "Bump version from $currentVersion to $newVersion? [Y/n] " choice
case "$choice" in
[nN][oO]|[n|N] ) echo 1 ;;
* ) echo 0 ;;
esac
}
if [[ $(confirmBump) != 0 ]] ; then
echo "No"
exit 0
else
echo "Yes"
fi
# Replace current version in gradle.properties
propertiesFile="./gradle.properties"
versionNameKey="VERSION_NAME"
sed -i "" "s/.*$versionNameKey.*/$versionNameKey=$newVersion/g" $propertiesFile
# Replace current version in changelog.md and update hyperlinks
changelogFile="./docs/changelog.md"
today=$(date +%F)
sed -i "" "s/## \[Unreleased\]/## \[Unreleased\]"$'\\\n\\\n'"## \[$newVersion\] - $today/g" $changelogFile
newVersionTag="[$newVersion]: https:\/\/github.com\/MiSikora\/ruler\/releases\/tag\/$newVersion"
sed -i "" "s/$currentVersion...HEAD/$newVersion...HEAD"$'\\\n'"$newVersionTag""/g" $changelogFile
# Replace current version in index.md
indexFile="./docs/index.md"
sed -i "" "s/$currentVersion/$newVersion/g" $indexFile
# Replace current version in README.md
readmeFile="./README.md"
sed -i "" "s/$currentVersion/$newVersion/g" $readmeFile
git add . &> /dev/null
git commit -am "Prepare for release $newVersion" &> /dev/null
git tag -a "$newVersion" -m "Version $newVersion" &> /dev/null
# Update current version to a snapshot one
newMajor="$(cut -d"." -f1 <<<"$newVersion")"
newMinor="$(cut -d"." -f2 <<<"$newVersion")"
newPatch="$(cut -d"." -f3 <<<"$newVersion")"
newSnapshotVersion="$newMajor.$newMinor.$((newPatch + 1))-SNAPSHOT"
sed -i "" "s/.*$versionNameKey.*/$versionNameKey=$newSnapshotVersion/g" $propertiesFile
git add . &> /dev/null
git commit -am "Prepare next development version" &> /dev/null
echo "\
Version bumped successfully to $newVersion and commit is tagged. \
Changes can be pushed to the origin."