-
Notifications
You must be signed in to change notification settings - Fork 3
/
zanata-nexus-staging
executable file
·249 lines (210 loc) · 7.52 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
#!/bin/bash
set -e
### NAME
### zanata-nexus-staging - Staging and Release to Sonatype nexus
###
### SYNOPSIS
### zanata-nexus-staging [options] <MODULE>
### 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]
### zanata-nexus-staging-assets [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 big release (e.g. 3.Y.Z -> 4.0.0 or 3.7.Z -> 3.8.0 ), run:
###
### zanata-nexus-staging-<module> -b
###
### It will commit to both RELEASING_BRANCH and DEVEL_BRANCH, see
### section ENVIRONMENT for details.
###
### * For making a Z release (e.g. 3.7.0 -> 3.7.1 ), run
###
### zanata-nexus-staging-<module>
###
### It will commit to RELEASING_BRANCH.
###
### * 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
### RELEASING_BRANCH
### The branch that we recommend downstream to use, and
### release process should mainly happen here.
### It is:
### 'release' if that branch exists; otherwise
### 'integration/master' if that branch exists; otherwise
### 'master'.
###
### DEVEL_BRANCH
### The branch for committing new features. It is:
### 'integration/master' if that branch exists; otherwise
### 'master'.
###
### MAVEN_RELEASE_OPTIONS
### The maven options to be use in this scripts
### Default: -e -Dmaven.repo.local=$REPO_LOCAL_DIR -Dgpg.useagent -Psonatype-oss-release
###
### REPO_LOCAL_DIR (Optional)
### The directory for maven repo
### This should NOT be your normal work maven repo
###
### 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 development directory.
###
SCRIPT_DIR=$(dirname $(readlink -q -f $0))
FUNCTION_SCRIPT_FILE=${SCRIPT_DIR}/zanata-functions
source "${FUNCTION_SCRIPT_FILE}"
trap exit_print_error EXIT
BIG_RELEASE=
SKIP_RELEASE_PLUGIN=
: ${MAVEN_RELEASE_OPTIONS:="-e -Dmaven.repo.local=$REPO_LOCAL_DIR -Dgpg.useagent -Psonatype-oss-release"}
while getopts "brh" opt;do
case $opt in
h )
zanata_script_help $0
exit ${EXIT_OK}
;;
b )
BIG_RELEASE=1
;;
r )
SKIP_RELEASE_PLUGIN=1
;;
* )
echo "Invalid option $opt" > /dev/stderr
exit ${EXIT_FATAL_INVALID_OPTIONS}
;;
esac
done
shift $((OPTIND-1))
##=== parsing Start ===
Stage=parsing
print_status -s "Start"
## Get Module
moduleResult=$(get_module_from_command $1)
echo "moduleResult=$moduleResult"
Module=$(sed -e 's/ .*//'<<<"$moduleResult")
if [[ $moduleResult == *1 ]];then
shift
fi
print_status " Module=$Module"
##=== parpare Start ===
Stage=prepare
print_status -s "Start"
## Ensure repo
if [ ! -d ${WORK_ROOT} ];then
mkdir -p ${WORK_ROOT}
fi
ensure_repo ${Module}
## Determine RELEASING_BRANCH
: ${RELEASING_BRANCH:=$(get_releasing_branch $Module)}
print_status " RELEASING_BRANCH for $Module is ${RELEASING_BRANCH}"
: ${DEVEL_BRANCH:=$(get_devel_branch $Module)}
print_status " DEVEL_BRANCH for $Module is ${DEVEL_BRANCH}"
cd ${WORK_ROOT}/${Module}
git fetch
Stage=pre-release
print_status -s "Start"
print_status " updating existing RELEASING_BRANCH (${RELEASING_BRANCH})"
git checkout ${RELEASING_BRANCH}
git pull
print_status " Branch ${RELEASING_BRANCH}: merge origin/${RELEASING_BRANCH}"
git merge origin/${RELEASING_BRANCH} --ff-only --quiet
if [ -n "${BIG_RELEASE}" -a "${RELEASING_BRANCH}" != "master" ];then
print_status " Branch ${RELEASING_BRANCH}: merge origin/master as we do the big release"
git merge origin/master --ff-only --quiet
print_status " Branch ${RELEASING_BRANCH}: pushing back to origin"
git push origin ${RELEASING_BRANCH}
fi
## Update existing DEVEL_BRANCH on BIG_RELEASE
if [ -n "${BIG_RELEASE}" ]; then
print_status " update existing DEVEL_BRANCH (${DEVEL_BRANCH}) for big release"
git checkout ${DEVEL_BRANCH}
print_status " Branch ${DEVEL_BRANCH} merge origin/${DEVEL_BRANCH}"
git merge origin/${DEVEL_BRANCH} --ff-only --quiet
print_status " Branch ${DEVEL_BRANCH}: Create new version"
mvn -e release:update-versions -DautoVersionSubmodules=true
git commit $(find . -name 'pom.xml' | xargs ) -m "prepare for next development iteration"
git push origin ${DEVEL_BRANCH}
print_status " ${DEVEL_BRANCH} branch updated"
fi
print_status " back to RELEASING_BRANCH (${RELEASING_BRANCH})"
git checkout ${RELEASING_BRANCH}
git fetch --tags
git pull
## Release start
function release_perform(){
if [ -z "${SKIP_RELEASE_PLUGIN}" ];then
Stage=release-tagging
print_status -s "Start"
git clean -f -d
### Other Modules might related to zanata-parent
if [ "$Module" != "zanata-parent" ];then
ensure_repo zanata-parent
fi
mvn ${MAVEN_RELEASE_OPTIONS} release:clean
print_status " Dry-run: release:prepare release:perform"
mvn -e ${MAVEN_RELEASE_OPTIONS} release:prepare release:perform -DupdateReleaseInfo=true -DdryRun=true
print_status " Real-run: it should sign artifacts, push $Module to nexus, then close it"
mvn -e ${MAVEN_RELEASE_OPTIONS} release:clean release:prepare release:perform -DupdateReleaseInfo=true
if [ $? -ne 0 ];then
EXIT_MSG="release goals failed"
exit ${EXIT_FATAL_FAIL}
fi
print_status " Done"
fi
return 0
}
case $Module in
zanata-assets | zanata-parent | zanata-api | zanata-common | zanata-client)
release_perform
Stage=nexus-release
print_status -s "Start"
StagingRepositoryId=$(mvn org.sonatype.plugins:nexus-staging-maven-plugin:rc-list -DnexusUrl=https://oss.sonatype.org/ -DserverId=sonatype-nexus-staging | sed -n -e '/orgzanata-.* CLOSED/ s/.*\(orgzanata-[0-9]*\).*$/\1/p')
if [ -z "$StagingRepositoryId" ];then
StagingRepositoryId=$(grep -oP '^stagingRepository\.id=\K.*' target/checkout/target/nexus-staging/staging/*.properties)
test -n "$StagingRepositoryId"
exit_if_failed $? $EXIT_FATAL_FAIL " Cannot obtain staging repository id from both nexus-staging plugin and local target files"
fi
print_status " StagingRepositoryId=${StagingRepositoryId}"
read -p "### Please login sonatype and check maven-metadata.xml. Press [Ctrl-C] to break, [Enter] to continue"
print_status " nexus-staging:release"
mvn -e nexus-staging:release -Psonatype-oss-release \
-DstagingRepositoryId=$(StagingRepositoryId)
;;
* )
### Module like tennera or openprops
### These have only master
release_perform
read -p "### Pause for checking metadata"
print_status " nexus-staging:close nexus-stage:release"
mvn -e nexus-staging:close nexus-staging:release
;;
esac