-
Notifications
You must be signed in to change notification settings - Fork 3
/
zanata-nexus-staging
executable file
·299 lines (251 loc) · 7.47 KB
/
zanata-nexus-staging
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/bin/bash
set -e
function print_usage(){
cat <<-END
SYNOPSIS
zanata-nexus-staging [options] <PROJECT>
zanata-nexus-staging-tennera [options]
zanata-nexus-staging-openprops [options]
zanata-nexus-staging-parent [options]
zanata-nexus-staging-api [options]
zanata-nexus-staging-common [options]
zanata-nexus-staging-client [options]
OPTIONS
-h: Show this help
-b: Big release.
Integration/master need to be updated.
(e.g. when releasing from 3.7.X -> 3.8.0).
If not specified, only the default branch will be touch
(e.g. when releasing from 3.7.0 -> 3.7.1 ).
Default branch is:
release if it has release; otherwise
integration/master if it has release; otherwise
master.
-r: Skip release plugin
DESCRIPTION
This program perform the release and push the relese with nexus.
It can do following tasks:
* For making a X release (e.g. 3.Y.Z -> 4.0.0) or
Y release: (e.g. 3.7.Z -> 3.8.0 ), run:
zanata-nexus-staging-<module> -b
* For making a Z release (e.g. 3.7.0 -> 3.7.1 ), run
zanata-nexus-staging-<module>
* If tag is made but release failed, and you fixed it without changing
the source, You can resume the release process with
zanata-nexus-staging-<module> -r
ENVIRONMENT
DEFAULT_BRANCH
Branch is automatically determined by PROJECT.
Specify Environment DEFAULT_BRANCH to override.
WORK_ROOT
The base directory for repository checkout
As maven release plugin generally require a clean git working tree
This script will clean it for you.
Thus it is better not use normal working directory.
REPO_LOCAL_DIR (Optional)
The directory for maven repo
This should NOT be your normal work maven repo
EXIT_STATUS
EXIT_INVALID_OPTIONS=3
EXIT_FAIL_TO_CLONE=4
EXIT_RELEASE_GOAL_FAIL=5
END
}
function echo_stderr(){
echo "$1" > /dev/stderr
}
function ensure_repo(){
echo "### Ensure the repo $prj is at ${WORK_ROOT}/${prj}"
local prj=$1
local git_repo_url="git@github.com:zanata/${prj}.git"
pushd ${WORK_ROOT}
if [ ! -d ${prj} ];then
git clone ${git_repo_url}
if [ $? -ne 0 ];then
echo_stderr "[ERROR] Failed to clone ${git_repo_url}"
exit ${EXIT_FAIL_TO_CLONE}
fi
fi
popd
}
function does_branch_exist(){
local prj=$1
local branch=$2
echo -n "### Does ${prj} has branch ${branch}?..."
if git rev-parse --verify ${branch} &>/dev/null;then
echo "yes"
return 0
else
echo "no"
return 1
fi
}
: ${WORK_ROOT:=/tmp/zanata}
: ${REPO_LOCAL_DIR:=/tmp/maven-central-release-repo}
EXIT_INVALID_OPTIONS=3
EXIT_FAIL_TO_CLONE=4
EXIT_RELEASE_GOAL_FAIL=5
BIG_RELEASE=
SKIP_RELEASE_PLUGIN=
while getopts "brh" opt;do
case $opt in
h )
pring_usage
exit 0
;;
b )
BIG_RELEASE=1
;;
r )
SKIP_RELEASE_PLUGIN=1
;;
* )
echo "Invalid option $opt" > /dev/stderr
exit ${EXIT_INVALID_OPTIONS}
;;
esac
done
shift $((OPTIND-1))
if [ -n "$1" ];then
PROJECT="$1"
fi
case $0 in
*-tennera)
PROJECT=tennera
;;
*-openprops)
PROJECT=openprops
;;
*-parent)
PROJECT=zanata-parent
;;
*-api)
PROJECT=zanata-api
;;
*-common)
PROJECT=zanata-common
;;
*-client)
PROJECT=zanata-client
;;
*)
if [ -z "$PROJECT" ]; then
print_usage
exit ${EXIT_INVALID_OPTIONS}
fi
;;
esac
### Set default branches
if [ -z "${DEFAULT_BRANCH}" ];then
case ${PROJECT} in
tennera | openprops )
DEFAULT_BRANCH=master
;;
zanata-parent )
DEFAULT_BRANCH=integration/master
;;
zanata-api | zanata-common | zanata-client)
DEFAULT_BRANCH=release
;;
esac
fi
echo "### Releasing $PROJECT in branch ${DEFAULT_BRANCH}"
if [ ! -d ${WORK_ROOT} ];then
mkdir -p ${WORK_ROOT}
fi
ensure_repo ${PROJECT}
cd ${WORK_ROOT}/${PROJECT}
git fetch
HAS_RELEASE_BRANCH=
does_branch_exist ${PROJECT} origin/release && HAS_RELEASE_BRANCH=1
HAS_INTEGRATION_MASTER_BRANCH=
does_branch_exist ${PROJECT} origin/integration/master &&
HAS_INTEGRATION_MASTER_BRANCH=1
### Update existing release branch
echo "### Pre-release: update existing release branchs"
if [ -n "$HAS_RELEASE_BRANCH" ];then
git checkout release
echo "### [pre-release] Branch release: merge origin/release"
git merge origin/release --ff-only --quiet
if [ -n "${BIG_RELEASE}" ];then
echo "### [pre-release] Branch release: merge origin/master as we do the big release"
git merge origin/master --ff-only --quiet
fi
echo "### [pre-release] Branch release: updated"
git push origin release
fi
### Update existing integration/master branch on BIG_RELEASE
echo "### Pre-release: update existing integration/master branchs"
if [ -n "${BIG_RELEASE}" -a -n "$HAS_INTEGRATION_MASTER_BRANCH" ];then
git checkout integration/master
echo "### [pre-release] Branch integration/master merge origin/integration/master"
git merge origin/integration/master --ff-only --quiet
echo "### [pre-release] Branch integration/master: Create new version"
mvn -e release:update-versions -DautoVersionSubmodules=true
git commit pom.xml */pom.xml -m "prepare for next development iteration"
git push origin integration/master
echo "### [pre-release] integration/master branch updated"
fi
### Release process
function release_perform(){
if [ -z "${SKIP_RELEASE_PLUGIN}" ];then
git clean -f -d
if [ "$PROJECT" != "zanata-parent" ];then
ensure_repo zanata-parent
fi
echo "### [release_perform] Start"
mvn -e -Dmaven.repo.local=$REPO_LOCAL_DIR -Dgpg.useagent release:clean release:prepare release:perform
if [ $? -ne 0 ];then
echo_stderr "### [ERROR]: release goals failed"
exit ${EXIT_RELEASE_GOAL_FAIL}
fi
fi
echo "### [release_perform] Done"
return 0
}
echo "### [release] Start"
git checkout ${DEFAULT_BRANCH}
git fetch --tags
git pull
case $PROJECT in
zanata-parent | zanata-api | zanata-common )
### zanata-parent has only master
release_perform
echo "### [release] nexus-staging:release"
mvn -e nexus-staging:release -Psonatype-oss-release \
-DstagingRepositoryId=$(grep -oP '^stagingRepository\.id=\K.*' target/checkout/target/nexus-staging/staging/*.properties)
;;
zanata-client )
### auto nexus-staging does not seem to work with zanata-client
### Need to use manual bundle jars
release_perform
### Create and sign the artifacts
echo "### [release] Create and sign the artifacts"
mvn -e clean deploy source:jar javadoc:jar jar:jar gpg:sign -Dgpg.useagent -DskipTests=true -DskipArqTests=true -Dfindbugs.skip=true
### make bundles for each submodules:
SUBMODULES=(. zanata-cli zanata-client-commands zanata-maven-plugin zanata-rest-client)
BUNDLE_JARS=()
for sm in "${SUBMODULES[@]}"; do
pushd ${sm}/target
jar cvf bundle.jar $(for i in `LANG=C find . -name "*.asc" | sed -e 's/.asc$//' | xargs`;do echo -n $i $i.asc " ";done)
BUNDLE_JARS+="${sm}/target/bundle.jar"
popd
done
### Notify user to upload bundles
cat <<-END
Please:
1. Login to oss.sonatype.org
2. On Left panel, under Build Promotion section, click Staging Upload
3. Upload following files:
END
for bj in "${BUNDLE_JARS[@]}"; do
echo "$bj"
done
;;
* )
### Project like tennera or openprops
### These have only master
release_perform
mvn -e nexus-staging:close nexus-staging:release
;;
esac