-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.sh
67 lines (58 loc) · 1.22 KB
/
common.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
info() {
echo ">> $1"
}
git_compare_branches() {
local commit1=$(git rev-parse "$1")
local commit2=$(git rev-parse "$2")
if [ "$commit1" != "$commit2" ]; then
local base=$(git merge-base "$commit1" "$commit2")
if [ $? -ne 0 ]; then
return 4
elif [ "$commit1" = "$base" ]; then
return 1
elif [ "$commit2" = "$base" ]; then
return 2
else
return 3
fi
else
return 0
fi
}
compare_and_check() {
git_compare_branches "$(git_current_branch)" "origin/$(git_current_branch)"
local status=$?
if [ $status -eq 2 ]; then
info "ahead"
exit 0
elif [ $status -eq 1 ]; then
info "behind"
exit 0
fi
}
git_current_branch() {
git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g'
}
read_gradle_version() {
cat gradle.properties | sed s/version=// | head -n 1
}
update_gradle_version() {
local next_version=$1
sed -i '' 's/^version=.*$/version='"$1"'/g' gradle.properties
}
parse_snapshot_version() {
echo $1 | sed s/-SNAPSHOT// | head -n 1
}
upgrade_minor_version() {
local version=$1
a=( ${version//./ } )
((a[1]++))
a[2]=0
echo "${a[0]}.${a[1]}.${a[2]}"
}
upgrade_patch_version() {
local version=$1
a=( ${version//./ } )
((a[2]++))
echo "${a[0]}.${a[1]}.${a[2]}"
}