-
Notifications
You must be signed in to change notification settings - Fork 3
/
zanata-nexus-release
executable file
·151 lines (134 loc) · 4.57 KB
/
zanata-nexus-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
#!/bin/bash
### NAME
### zanata-nexus-release - Release maven artifacts in nexus-staging
###
### SYNOPSIS
### zanata-nexus-release [options] [Projects]
###
### DESCRIPTION
### This script releases artifacts that already in nexus staging.
###
### Note that this script assume you are already in correct directory and
### checkout correct branch.
###
### plugin docs:
### https://github.com/sonatype/nexus-maven-plugins/tree/master/staging/maven-plugin
###
### OPTIONS
### -p: Push commits and tag to Git
### Push when nexus staging repository is successfully closed
###
###
### 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, and nor does it close the nexus staging repo
### dryRun : Only show command to be run.
: ${ZANATA_RELEASE_MODE:=}
: ${DryRunMode:=0}
export LC_ALL=C
set -eu
ScriptDir=$(dirname $(readlink -q -f $0))
FunctionScriptFile=${ScriptDir}/zanata-functions
source "$FunctionScriptFile"
trap exit_print_error EXIT
PushMode=0
NexusStagingRepositoryPrefix=orgzanata
###
### OPTIONS
while getopts "hps:" opt;do
case $opt in
### -h: Show detail help
h )
zanata_script_help $0
exit ${EXIT_OK}
;;
p )
PushMode=1
;;
s )
NexusStagingRepositoryPrefix=$OPTARG
;;
* )
failed ${EXIT_FATAL_INVALID_OPTIONS} "$opt"
;;
esac
done
shift $((OPTIND-1))
case $ZANATA_RELEASE_MODE in
dryRun )
DryRunMode=1
;;
testBuild )
DryRunMode=0
;;
* )
;;
esac
export DryRunMode
Projects="${1-}"
if [[ -n $Projects && $Projects != 'null' ]]; then
ProjectOpts="-pl $Projects"
else
ProjectOpts=""
fi
## This function runs the staging plugin to fetch the repository id and state into these variables:
## StagingRepositoryId
## StagingRepositoryState
get_StagingRepository(){
## We only query the "root" project, which only takes 10 secs
## Querying on all projects takes 1:09 minutes.
local StagingRepositoryBuffer=$(run_command ./mvnw $MAVEN_NEXUS_STAGING_OPTIONS ${MAVEN_NEXUS_STAGING_PLUGIN}:rc-list -pl . | sed -r -n -e '/'$NexusStagingRepositoryPrefix'-.* / s/^\[INFO\] ('$NexusStagingRepositoryPrefix'-[0-9]+)\s*([A-Z]+)/\1 \2/ p' )
if [[ $DryRunMode -eq 0 ]]; then
if [[ -n $StagingRepositoryBuffer ]]; then
StagingRepositoryId=$( awk '{print $1}' <<<"$StagingRepositoryBuffer" | tail -n 1 )
StagingRepositoryState=$( awk '{print $2}' <<<"$StagingRepositoryBuffer" | tail -n 1 )
elif [[ $ZANATA_RELEASE_MODE = testBuild ]]; then
print_status " [testBuild] StagingRepositoryId is not necessary available"
StagingRepositoryId=StagingRepositoryId
StagingRepositoryState=OPEN
else
failed $EXIT_FATAL_FAIL " Failed to find artifacts in ${MAVEN_NEXUS_STAGING_PLUGIN}:rc-list"
fi
else
print_status " [Dry-Run] No StagingRepositoryId available in DryRunMode, use pseudo Id instead"
## Provide pseudo Id and state for display
StagingRepositoryId=StagingRepositoryId
StagingRepositoryState=OPEN
fi
}
print_status -t nexus-release -s "Start"
get_StagingRepository
## TODO: Try -DautoReleaseAfterClose (and skip the release goal below)
if [ "$StagingRepositoryState" = "OPEN" ];then
print_status " nexus-staging:close"
## No closing in testBuild mode
if [[ $ZANATA_RELEASE_MODE = testBuild ]]; then
export DryRunMode=1
fi
set +e
run_command ./mvnw $MAVEN_NEXUS_STAGING_OPTIONS ${MAVEN_NEXUS_STAGING_PLUGIN}:close \
-DstagingRepositoryId=${StagingRepositoryId} ${ProjectOpts}
set -e
if [[ $ExitCode -eq 0 ]]; then
if [[ $PushMode -eq 1 ]]; then
## Push when success
run_command git push --follow-tags origin $(get_current_branch)
fi
fi
if [[ $ZANATA_RELEASE_MODE = testBuild ]]; then
export DryRunMode=0
fi
fi
print_status " nexus-staging:release"
if [[ $ZANATA_RELEASE_MODE = testBuild ]]; then
export DryRunMode=1
fi
get_StagingRepository
if [ "$StagingRepositoryState" = "CLOSED" ];then
run_command ./mvnw $MAVEN_NEXUS_STAGING_OPTIONS ${MAVEN_NEXUS_STAGING_PLUGIN}:release \
-DstagingRepositoryId=${StagingRepositoryId} ${ProjectOpts}
fi
## No need to restore DryRunMode in end of the script