Skip to content

Commit 83a7878

Browse files
committed
Improved bump tool to fit the release branches
1 parent 94b9935 commit 83a7878

File tree

1 file changed

+50
-9
lines changed

1 file changed

+50
-9
lines changed

tools/bump.sh

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,20 @@ NODE_META="package.json"
2626

2727
_check_src() {
2828
if [[ ! -f $1 && ! -d $1 ]]; then
29-
echo -e "Error: missing file \"$1\"!\n"
29+
echo -e "Error: Missing file \"$1\"!\n"
3030
exit -1
3131
fi
3232
}
3333

3434
check() {
3535
if [[ -n $(git status . -s) ]]; then
36-
echo "Warning: commit unstaged files first, and then run this tool againt."
36+
echo "Error: Commit unstaged files first, and then run this tool againt."
37+
exit -1
38+
fi
39+
40+
# ensure the current branch is 'master'
41+
if [[ "$(git branch --show-current)" != "master" ]]; then
42+
echo "Error: This operation must be performed on the 'master' branch!"
3743
exit -1
3844
fi
3945

@@ -76,13 +82,51 @@ bump() {
7682
}
7783

7884
build_gem() {
85+
rm -f ./*.gem
7986
gem build "$GEM_SPEC"
8087
}
8188

89+
release() {
90+
_version="$1"
91+
_major=""
92+
_minor=""
93+
94+
IFS='.' read -r -a array <<< "$_version"
95+
96+
for elem in "${array[@]}"; do
97+
if [[ -z $_major ]]; then
98+
_major="$elem"
99+
elif [[ -z $_minor ]]; then
100+
_minor="$elem"
101+
else
102+
break
103+
fi
104+
done
105+
106+
_release_branch="$_major-$_minor-stable"
107+
108+
if [[ -z $(git branch -v | grep "$_release_branch") ]]; then
109+
git checkout -b "$_release_branch"
110+
else
111+
git checkout "$_release_branch"
112+
# cherry-pick the latest 2 commit from master to release branch
113+
git cherry-pick "$(git rev-parse master~1)" "$(git rev-parse master)"
114+
fi
115+
116+
echo -e "Create tag v$_version\n"
117+
git tag "v$_version"
118+
119+
build_gem
120+
121+
# head back to master branch
122+
git checkout master
123+
124+
}
125+
82126
main() {
83127
check
84128

85-
_latest_tag="$(git describe --tags --abbrev=0)"
129+
_latest_tag="$(git describe --tags $(git rev-list --tags --max-count=1))"
86130

87131
echo "Input a version number (hint: latest version is ${_latest_tag:1})"
88132

@@ -98,16 +142,13 @@ main() {
98142
echo -e "Bump version to $_version\n"
99143
bump "$_version"
100144

101-
echo -e "Create tag v$_version\n"
102-
git tag "v$_version"
103-
104-
build_gem
145+
echo -e "Release to v$_version\n"
146+
release "$_version"
105147

106148
else
107-
108149
echo "Error: Illegal version number: '$_version'"
109-
110150
fi
151+
111152
}
112153

113154
main

0 commit comments

Comments
 (0)