-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.sh
executable file
·142 lines (115 loc) · 3.99 KB
/
atom.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
140
141
142
#!/usr/bin/env bash
#
# Copyright (c) 2022-2023 Catch([email protected]).
# Atom is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
# http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
#
# 使用示例
# ./atom.sh version 1.0.0
# ./atom.sh deploy 1.0.0
set -e
ACTION=$1
VERSION=$2
function info() {
echo -e "\033[32m$1\033[0m"
}
function error() {
echo -e "\033[31m$1\033[0m"
}
function setCurrentVersion() {
VERSION=$(awk -F'[><]' '/<revision>/{print $3}' pom.xml)
}
if [ "${ACTION}" == "version" ]; then
info "参数校验..."
if [ -z "${VERSION}" ]; then
error "请输入版本号! 示例: 1.0.0"
exit
fi
info "参数校验...OK!\n"
info "修改 README.md 版本号..."
sed -i '' "s/<version>.*<\/version>/<version>${VERSION}<\/version>/g" README.md
info "修改 README.md 版本号...OK!\n"
info "更新 pom.xml 中 revision 版本号..."
sed -i '' "s/<revision>.*<\/revision>/<revision>${VERSION}<\/revision>/g" pom.xml
info "更新 pom.xml 中 revision 版本号...OK!\n"
info "版本${VERSION}设置完成!"
elif [ "${ACTION}" == "deploy" ]; then
if [ -z "${VERSION}" ]; then
setCurrentVersion
fi
info "发布版本 ${VERSION} ..."
info "检查本地是否有代码未提交..."
if [ -n "$(git status -s)" ]; then
error "本地有未提交的代码!"
exit
fi
info "检查本地是否有代码未提交...OK!\n"
info "切换到 main 分支..."
git checkout main
info "切换到 main 分支...OK!\n"
info "拉取 main 分支..."
git pull origin main
info "拉取 main 分支...OK!\n"
info "合并 2.x 分支到 main 分支..."
git merge 2.x
info "合并 2.x 分支到 main 分支...OK!\n"
info "发布到 maven..."
mvn -Possrh -Prelease clean deploy -U -DskipTests
info "发布到 maven...OK!\n"
info "提交代码并推送..."
set +e
git add .
git commit -m "发布 ${VERSION}"
git push origin main
set -e
info "提交代码并推送...OK!\n"
info "检查tag是否存在..."
if git rev-parse "${VERSION}" >/dev/null 2>&1; then
info "tag存在!"
info "删除本地旧的 tag..."
git tag -d "${VERSION}"
info "删除本地旧的 tag...OK!\n"
info "删除远程旧的 tag..."
git push --delete origin "${VERSION}"
info "删除远程旧的 tag...OK!\n"
fi
info "创建 tag..."
git tag -a "${VERSION}" -m "${VERSION}"
info "创建 tag...OK!\n"
info "推送 tag..."
git push origin "${VERSION}"
info "推送 tag...OK!\n"
info "切换到 2.x 分支..."
git checkout 2.x
info "切换到 2.x 分支...OK!\n"
info "将 main 分支合并到 2.x 分支..."
git merge main
info "将 main 分支合并到 2.x 分支...OK!\n"
info "新版本..."
MAJOR=$(cut -d. -f1 <<< "${VERSION}")
MINOR=$(cut -d. -f2 <<< "${VERSION}")
PATCH=$(cut -d. -f3 <<< "${VERSION}")
set +e
((PATCH++))
set -e
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
info "新版本 ${NEW_VERSION} ...OK!\n"
info "修改 README.md 版本号..."
sed -i '' "s/<version>.*<\/version>/<version>${NEW_VERSION}<\/version>/g" README.md
info "修改 README.md 版本号...OK!\n"
info "更新 pom.xml 中 revision 版本号..."
sed -i '' "s/<revision>.*<\/revision>/<revision>${NEW_VERSION}<\/revision>/g" pom.xml
info "更新 pom.xml 中 revision 版本号...OK!\n"
info "提交代码并推送..."
git add .
git commit -m "版本: ${NEW_VERSION}"
git push origin 2.x
info "提交代码并推送...OK!\n"
echo "进行 ${NEW_VERSION} 版本的开发..."
fi