-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
130 lines (100 loc) · 3.11 KB
/
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
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
#!/bin/bash
## --------- 控制流变量
GIT_TAG_COMMIT="[#1] 发布脚本自动递进"
LINE_NUM_TAG=20
## --------- 方法定义、引入 (随项目变动的)
function clean_local_cache () {
rm -fr ~/.m2/repository/com/github/kimffy24/uowgen-maven-plugin
}
## --------- 方法定义、引入
## 数组join成字符串
function join_by { local IFS="$1"; shift; echo "$*"; }
## 判断输入是否为整数
function isint () {
# 输入为空,返回 0
# 输入非整数,返回 0
# 输入整数,返回 1
if [ $# -lt 1 ]; then
return 0
fi
if [[ $1 =~ ^-?[1-9][0-9]*$ ]]; then
return 1
fi
if [[ $1 =~ ^0$ ]]; then
return 1
fi
return 0
}
## --------- 解析脚本参数
## 约定第一个参数为打tag时的前缀
TAG_PERFIX="v"
if [ "z" != "z$1" ] ; then
TAG_PERFIX="$1"
fi
## --------- 开始
WR=`dirname $0`
cd $WR
FORCE=
gstat=$(git status| grep "nothing to commit, working tree clean")
if [ "z" == "z$gstat" ] ; then
echo -e "=========\n"
echo "git status:"
git status
echo -e "\n========="
echo " -- It's a not clean work tree!!!"
echo " -- Script cannot execute this release action!!!"
exit 0
fi
VERSION_CURR=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
read -p "enter release version (default: ${VERSION_CURR}):" VERSION_TAG
if [ "z" == "z${VERSION_TAG}" ] ; then
VERSION_TAG=${VERSION_CURR}
fi
VERSION_NEW=${VERSION_TAG}
VERSION_DEPLOY="${VERSION_TAG}"
VERSION_TAG="${TAG_PERFIX}${VERSION_TAG}"
echo "------"
echo "Fetch current version in pom.xml: ${VERSION_CURR}"
echo "Detect release version: ${VERSION_DEPLOY}"
echo "Detect new tag name: ${VERSION_TAG}"
echo "------"
SED="sed"
OS=`uname -s`
if [ "Darwin" == ${OS} ] ; then
SED="gsed"
fi
LINE_NUM_TAG_NEW=$((LINE_NUM_TAG-1))
$SED -i "${LINE_NUM_TAG}d ; ${LINE_NUM_TAG_NEW}a\<tag\>${VERSION_TAG}\<\/tag\>" pom.xml
# 针对UoWgen-maven-pluginjia'd加的;
$SED -i "52d ; 51a\"${VERSION_DEPLOY}\"" src/main/java/com/github/kimffy24/uow/mavenplugin/UoWMojo.java
if [ "z${VERSION_CURR}" != "${VERSION_NEW}" ] ; then
echo "!!! we will change version in your maven project, do you accept this action?"
read -p "Input any key to continue or CRTL + c to break this script... " XYZ
mvn versions:set -DnewVersion="${VERSION_NEW}"
git add .
git commit -m "${GIT_TAG_COMMIT}"
fi
read -p "Check info and input anything to continue OR ctrl+c to interupt this script ... : " XYZ0
# 打上tag
git tag -m "Auto tag by script." "${VERSION_TAG}"
#git push origin "v${VERSION_TAG}"
# 清理本地安装
clean_local_cache
rm -fr "$WR/target/checkout"
mkdir -p "$WR/target/checkout"
cd "$WR/target/checkout"
## 虽然这方法不怎么规范,但是从远程的源中clone一次是更加痛苦的事。
cp -a ../../.git ./
## 还原所有文件
git checkout -- .
git checkout "${VERSION_TAG}"
echo "mvn clean compile package deploy -P release"
mvn clean compile package deploy -P release
RES=$?
if [ $RES -ne 0 ] ; then
echo "Something wrong!!!"
exit 1
fi
echo "Your can push tag to origin by using:"
echo " git push origin \"${VERSION_TAG}\""
echo