-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprepare-release.sh
89 lines (74 loc) · 2.49 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
#!/bin/bash
# Stop if no version flag is provided.
if ! [[ $1 == "major" || $1 == "minor" || $1 == "patch" ]] ; then
echo "FAILED: Use major, minor or patch to release a new version."
exit 1
fi
# Get the version numbers from the lua file and store them in an array.
i=0
while read line ; do
no=${line//[!0-9]/}
if [ ! -z "$no" ]; then
version[$i]=${line//[!0-9]/}
i=$((i+1))
fi
done < version.lua
# Assign to variables.
major=${version[0]}
minor=${version[1]}
patch=${version[2]}
build=${version[3]}
old="$major.$minor.$patch.$build"
# Increment version based on command.
if [ $1 == "major" ] ; then
major=$((major+1))
minor=0
patch=0
elif [[ $1 == "minor" ]]; then
minor=$((minor+1))
patch=0
elif [[ $1 == "patch" ]]; then
patch=$((patch+1))
fi
# Use the git count as build number.
build=$(git rev-list develop --count)
formatted="$major.$minor.$patch.$build"
echo "####################################################"
echo ""
echo " Preparing release ($old -> $formatted)"
echo ""
echo "####################################################"
# Create a new feature branch via git flow.
git flow release start "$formatted"
# Check if git flow branch was created.
if [ ! $? -eq 0 ]; then
echo "FAILED to create a release branch! Rolling back changes ..."
exit 1
fi
# Update README.md
tag="[![Version](https://img.shields.io/badge/Version-$formatted-blue.svg)](https://github.com/rm-code/on-the-roadside/releases/latest)";
sed -n "1, 2p" ./README.md >> tmp_README.md
echo $tag >> tmp_README.md
sed -n "4, 28p" ./README.md >> tmp_README.md
mv tmp_README.md README.md
# Add new section to changelog.
echo "# Version $formatted - $(date +"%Y-%m-%d")" >> tmp_changelog
cat CHANGELOG.md >> tmp_changelog
mv tmp_changelog CHANGELOG.md
# Update version.lua.
echo "local version = {" >> tmp_version
echo " major = $major," >> tmp_version
echo " minor = $minor," >> tmp_version
echo " patch = $patch," >> tmp_version
echo " build = $build," >> tmp_version
echo "}" >> tmp_version
echo "" >> tmp_version
echo 'return string.format( "%d.%d.%d.%d", version.major, version.minor, version.patch, version.build );' >> tmp_version
mv tmp_version version.lua
# Commit the changes.
git commit -a -m "Prepare version $formatted"
echo "####################################################"
echo ""
echo " Update the Changelog now!"
echo ""
echo "####################################################"