-
Notifications
You must be signed in to change notification settings - Fork 4
/
zanata-maven-release
executable file
·300 lines (273 loc) · 8.61 KB
/
zanata-maven-release
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
299
#!/bin/bash
### NAME
### zanata-maven-release - Release in maven
###
### SYNOPSIS
### zanata-maven-release [options] <RepoName>
### zanata-maven-release-assets [options]
### zanata-maven-release-platform [options]
###
### DESCRIPTION
### This program does maven release, as well as tag the release version.
###
### It does following:
### 1. Checkout correct branch, ( -j to skip this)
### 2. Do pre-release tasks ( -Q to skip this)
### This incluldes update org.zanata dependency, pull translation,
### and insert release-notes
### 3. Set the new release version in pom.
### 4. mvn verify the project
### 5. mvn deploy to sonatype or cloudbee
### 6. release in sonatype
### 7. Set the next development version.
###
### EXAMPLES
### 1. (Recommended) To release platform-4.5.1, just run:
### zanata-maven-release -r 4.5.1 platform
###
### It will release platform 4.5.1 and set the development version to 4.5.2-SNAPSHOT
###
### 2. If you already checked out and cd to the releasing branch, you can skip the
### checkout action by specifying '-j' like:
### zanata-maven-release -j -r 4.5.1 platform
###
###
### ENVIRONMENT
### ZANATA_RELEASE_MODE:
### <empty> : Default mode. Builds, deploy to nexus staging, and push changes
### to source control
### testBuild: Builds, deploy to nexus staging, but does not push changes to
### source control
### dryRun : Only show command to be run.
###
### Note that option -n (dryRun) and -T (testBuild) override this.
: ${ZANATA_RELEASE_MODE:=}
###
export LC_ALL=C
set -eu
ScriptDir=$(dirname $(readlink -q -f $0))
FunctionScriptFile=${ScriptDir}/zanata-functions
source "$FunctionScriptFile"
trap exit_print_error EXIT
## Maven options are defined in zanata-env.sh
##=== parsing Start ===
print_status -t parsing -s "Start"
WorkingBranch=
DevelopmentVersion=
DryRunMode=0
JustUseCurrentDirectoryMode=0
PullRequestMode=0
QuickMode=0
UpdateDependencies=0
UpdateReleaseNotes=1
UpdateTranslations=0
ReleaseVersion=
###
### OPTIONS
###
while getopts "hd:jnPQr:tT" opt;do
case $opt in
### -h: Show this help
h )
zanata_script_help $0
exit ${EXIT_OK}
;;
###
### -d <developmentVersion>:
### Development Vesion like: 4.1.0-SNAPSHOT
### Default: <release version+1>-SNAPSHOT
d )
DevelopmentVersion=$OPTARG
;;
###
### -j: Just use current directory (no git checkout)
### This assumes that current directory is repo work directory.
### and correct branch is checked out.
j )
JustUseCurrentDirectoryMode=1
;;
###
### -n: Dry-run mode.
### Just show what would be done.
n )
DryRunMode=1
ZANATA_RELEASE_MODE=dryRun
;;
###
### -P: Working on pull request branch
### pr-<artifactId>-<version>
P )
PullRequestMode=1
;;
###
### -Q:
### Quick mode that skip prepare steps.
### Prepare steps include update dependency, translation,
### and release-notes prepend.
Q )
UpdateTranslations=0
UpdateDependencies=0
UpdateReleaseNotes=0
;;
###
### -r <releaseVersion>
### Release Vesion like: 4.4.4
r )
ReleaseVersion=$OPTARG
;;
###
### -t
### Pull translations
t )
UpdateTranslations=1
;;
###
### -T: testBuild mode
### This script builds and deploy artifacts to nexus staging,
### but does not push changes to source control.
T )
ZANATA_RELEASE_MODE=testBuild
;;
* )
failed ${EXIT_FATAL_INVALID_OPTIONS} "$opt"
;;
esac
done
export JustUseCurrentDirectoryMode
export ZANATA_RELEASE_MODE
if [[ $ZANATA_RELEASE_MODE == dryRun ]]; then
DryRunMode=1
fi
export DryRunMode
shift $((OPTIND-1))
## Get RepoName
branch_prepare RELEASING "$@"
shift $ShiftOffset
print_status " RepoName=$RepoName"
## ReleaseVersion should be exists
[[ -n "$ReleaseVersion" ]] || failed $EXIT_FATAL_INVALID_OPTIONS "ReleaseVersion missing"
## Get DevelopmentVersion
if [[ -z $DevelopmentVersion ]]; then
DevelopmentVersion="$(version_next $ReleaseVersion)-SNAPSHOT"
fi
## artifactId in maven
## We also use artifactId to form the tag
## e.g. platform-<version>
ArtifactId=$(get_artifact_id $RepoName)
if [ $JustUseCurrentDirectoryMode -eq 0 ];then
cd ${WORK_ROOT}/${RepoName}
## Merge with origin
print_status " Branch ${WorkingBranch}: merge origin/$WorkingBranch"
git merge origin/$WorkingBranch --ff-only --quiet
fi
if [ $PullRequestMode -eq 1 ];then
WorkingBranch="pr-$ArtifactId-$ReleaseVersion"
if ! branch_does_exist $WorkingBranch ;then
git branch $WorkingBranch
fi
git checkout $WorkingBranch
print_status " Working on the pull request branch: $WorkingBranch"
fi
##=== prepare Start ===
print_status -t prepare -s "Start"
## Invoke gpg-agent by signing an space string
## gpg2 is needed here, as in Fedora, gpg means gpg 1
gpg2 --clearsign <<<" "
ReleaseNotesFile=$(get_artifact_var_value $ArtifactId release_notes_file )
TagName="$ArtifactId-$ReleaseVersion"
print_status " Checking previous local tag (possibly from a failed build)"
if git ls-remote --exit-code https://github.com/zanata/$RepoName refs/tags/$TagName; then
failed $EXIT_FATAL_INVALID_OPTIONS "Tag ${tagName} is already in remote."
elif git show-ref $TagName; then
print_status " Removing local only tag $TagName"
git tag -d $TagName
fi
##==== Update Dependencies ====
if [[ $UpdateDependencies -eq 1 ]];then
print_status " Update dependencies"
set +e
run_command $ScriptDir/zanata-version-update -j
case $? in
$EXIT_OK )
;;
$EXIT_RETURN_FALSE )
;;
* )
failed $? "Failed to version update"
;;
esac
set -e
fi
##==== Update translations ====
if [[ $UpdateTranslations -eq 1 && ( -r zanata.xml || -r server/zanata.xml ) ]];then
print_status " Update Zanata translation"
set +e
run_command $ScriptDir/zanata-translate-pull -j
case $? in
$EXIT_OK )
;;
$EXIT_RETURN_FALSE )
;;
* )
failed $? "Failed to pull translation"
;;
esac
set -e
fi
##==== release-notes-prepend ====
if [[ -n $ReleaseNotesFile && $UpdateReleaseNotes -eq 1 ]]; then
print_status " release-notes-prepend"
## Remove -alpha-???
ReleaseNoteVersion=${ReleaseVersion%%-*}
set +e
run_command $ScriptDir/zanata-release-notes-prepend -j $ArtifactId $ReleaseNoteVersion
set -e
case $ExitCode in
$EXIT_OK )
;;
$EXIT_FATAL_MISSING_DEPENDENCY )
# This usually means the repo does not have docs/release-notes.md
;;
$EXIT_ERROR_UNKNOWN_VERSION )
# This usually means the <$ArtifactId-$ReleaseVersion> does not exist in Jira
;;
$EXIT_RETURN_FALSE )
# No Jira issues associates to the <$ArtifactId-$ReleaseVersion>
;;
* )
failed $ExitCode " Failed to get related jira issues"
;;
esac
fi
##=== release Start ===
## Incline to versions plugin instead of release-plugin
## zanata-assets does not work is release-plugin anyway.
print_status -t release -s "Start"
## Set pom.xml version to release version $ReleaseVersion
print_status " Set pom.xml version to release version $ReleaseVersion"
$ScriptDir/zanata-pom-set-version "$ReleaseVersion"
## Build with mvn install to get war and frontend
print_status " Build with mvn install"
run_command ./build --optimise --quick --all --install
## Build & Deploy to Nexus Staging
print_status " deploy to nexus staging"
$ScriptDir/zanata-nexus-staging
## Release staged artifacts from Nexus Staging
## after which they will be synced to Maven Central
print_status " Release staged artifacts from Nexus Staging"
$ScriptDir/zanata-nexus-release -p
## Set pom.xml version to next SNAPSHOT version $DevelopmentVersion
## e.g. 4.6.0-SNAPSHOT
print_status " Set pom.xml version to SNAPSHOT version $DevelopmentVersion"
$ScriptDir/zanata-pom-set-version "$DevelopmentVersion"
if [[ -z $ZANATA_RELEASE_MODE ]]; then
## Push the SNAPSHOT commit
run_command git push --follow-tags origin $WorkingBranch
if [[ $WorkingBranch != 'master' ]] ;then
## Merge to master
run_command git checkout master
run_commnad branch_forced_pull
run_command git merge $WorkingBranch -Xours
run_command git push
fi
fi