-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.sh
executable file
·139 lines (112 loc) · 2.2 KB
/
version.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
noGitDirectory(){
echo "Can't find .git directory"
}
gitCheckout(){
git checkout -f $1
git pull -p
}
gitAdd(){
git add $*
}
gitCommit(){
git commit -m "${1}"
git push origin master
}
gitTag(){
git tag -a "v${1}" -m "${2}"
git push --tags
}
findGitDirectory(){
COUNT=0
while [ $COUNT -lt 5 ]
do
if [ ! -e ".git" ]
then
cd ../
fi
COUNT=$(expr $COUNT + 1)
done
if [ ! -e ".git" ]; then
noGitDirectory
exit 1
fi
}
getTagMode() {
line=$(git log --pretty=oneline --abbrev-commit --merges -n 1)
echo -e "$line"
param=$(echo $line | grep "tag")
if [ "$param" != "" ];
then
exit 0
fi
param=$(echo $line | grep "feature")
if [ "$param" != "" ];
then
echo "minor"
return
fi
param=$(echo $line | grep "develop")
if [ "$param" != "" ];
then
echo "minor"
return
fi
param=$(echo $line | grep "hotfix")
if [ "$param" != "" ];
then
echo "hotfix"
return
fi
echo "hotfix"
}
getChangeLog(){
git log "${1}".."${2}" | egrep -v "^commit|^Date:|^Author|Merge:|Merge pull request|^\s*$" | sed "s/^ */- /g"
}
createChangeLogFile(){
log=$(getChangeLog "${1}" "${2}")
current_log=$(cat ./CHANGELOG.md)
echo -e "## v$(cat ./version.txt) $(date '+%Y-%m-%d')"
echo -e "
$log
$current_log
"
}
findGitDirectory
PREV=$(git tag -l | tail -1)
MODE=$(getTagMode)
gitCheckout "master"
if [ ! -e version.txt ];then
echo "0.0.0" > version.txt
fi
major=$(cat version.txt | cut -d '.' -f 1)
minor=$(cat version.txt | cut -d '.' -f 2)
hotfix=$(cat version.txt | cut -d '.' -f 3)
if [ "$MODE" = "major" ];then
major=$(expr $major + 1)
minor=0
hotfix=0
fi
if [ "$MODE" = "minor" ];then
minor=$(expr $minor + 1)
hotfix=0
fi
if [ "$MODE" = "hotfix" ];then
hotfix=$(expr $hotfix + 1)
fi
current_log=$(getChangeLog "tags/$PREV" "origin/master")
log=$(createChangeLogFile "tags/$PREV" "origin/master")
if [ "$current_log" = "" ];
then
echo "
no changes.
"
exit 1;
fi
echo "$major.$minor.$hotfix" | tee version.txt
echo -e "$log" > ./CHANGELOG.md
echo $MODE
exit 1
gitAdd "version.txt" "./CHANGELOG.md"
gitCommit "v$(cat ./version.txt) release!"
gitTag "$(cat ./version.txt)" "$(echo -e $current_log)"