-
Notifications
You must be signed in to change notification settings - Fork 72
/
create-release.sh
executable file
·145 lines (112 loc) · 3.77 KB
/
create-release.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
143
144
145
#!/usr/bin/env bash
#
# (C) Copyright IBM Corp. 2015, 2016
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
function exit_with_usage {
cat << EOF
create-release - Creates a release and publish maven artifacts from HEAD.
SYNOPSIS
usage: create-release.sh [--releaseVersion] [--developmentVersion] [--dryRun]
DESCRIPTION
Use maven infrastructure to create a project release and publish maven artifacts.
OPTIONS
--releaseVersion - Release identifier used when publishing
--developmentVersion - Release identifier used for next development cyce
--dryRun - Dry run only, mostly used for testing.
A GPG passphrase is expected as an environment variable
GPG_PASSPHRASE - Passphrase for GPG key used to sign release
EXAMPLES
create-release.sh --releaseVersion="1.0.6" --developmentVersion="1.0.7-SNAPSHOT" [--dryRun]
EOF
exit 1
}
set -e
if [ $# -eq 0 ]; then
exit_with_usage
fi
# Process each provided argument configuration
while [ "${1+defined}" ]; do
IFS="=" read -ra PARTS <<< "$1"
case "${PARTS[0]}" in
--gitCommitHash)
GIT_REF="${PARTS[1]}"
shift
;;
--releaseVersion)
RELEASE_VERSION="${PARTS[1]}"
shift
;;
--developmentVersion)
DEVELOPMENT_VERSION="${PARTS[1]}"
shift
;;
--dryRun)
DRY_RUN="-DdryRun=true"
shift
;;
*help* | -h)
exit_with_usage
exit 0
;;
-*)
echo "Error: Unknown option: $1" >&2
exit 1
;;
*) # No more options
break
;;
esac
done
for env in GPG_PASSPHRASE; do
if [ -z "${!env}" ]; then
echo "ERROR: $env must be set to run this script"
exit_with_usage
fi
done
if [[ -z "$RELEASE_VERSION" ]]; then
echo "ERROR: --releaseVersion must be passed as an argument to run this script"
exit_with_usage
fi
if [[ -z "$DEVELOPMENT_VERSION" ]]; then
echo "ERROR: --developmentVersion must be passed as an argument to run this script"
exit_with_usage
fi
# Explicitly set locale in order to make `sort` output consistent across machines.
# See https://stackoverflow.com/questions/28881 for more details.
export LC_ALL=C
if [ -z "$RELEASE_TAG" ]; then
RELEASE_TAG="v$RELEASE_VERSION"
fi
echo " "
echo "-------------------------------------------------------------"
echo "------- Release preparation with the following parameters ---"
echo "-------------------------------------------------------------"
echo "release version ==> $RELEASE_VERSION"
echo "development version ==> $DEVELOPMENT_VERSION"
echo "tag ==> $RELEASE_TAG"
if [ "$DRY_RUN" ]; then
echo "dry run ? ==> true"
fi
echo " "
echo "Preparing release $RELEASE_VERSION"
# Build and prepare the release
mvn -Pdistribution clean install
mvn -Pdistribution -DaltDeploymentRepository=sonatype-nexus-staging::default::https://oss.sonatype.org/service/local/staging/deploy/maven2 clean package release:clean release:prepare $DRY_RUN -Dgpg.passphrase="$GPG_PASSPHRASE" -DskipTests -DreleaseVersion="$RELEASE_VERSION" -DdevelopmentVersion="$DEVELOPMENT_VERSION" -Dtag="$RELEASE_TAG"
if [ -z "$DRY_RUN" ]; then
git checkout $RELEASE_TAG
mvn -Pdistribution -DaltDeploymentRepository=sonatype-nexus-staging::default::https://oss.sonatype.org/service/local/staging/deploy/maven2 clean install gpg:sign install:install deploy:deploy
fi
exit 0