This repository has been archived by the owner on Oct 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrelease.sh
executable file
·183 lines (156 loc) · 6.66 KB
/
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
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
#!/usr/bin/env bash
#
# Copyright 2018 Bull S.A.S. Atos Technologies - Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois, France.
#
# 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.
#
set -x
set -e
scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd ${scriptDir}
python -c "import semantic_version" > /dev/null 2>&1 || {
echo -e "Python library semantic_version is required.\nPlease install it using:\n\tpip install semantic_version" >&2
exit 1
}
dryRun=false
version=
PUSH_URL=
while getopts ":dv:p:" opt; do
case $opt in
v)
version=${OPTARG}
;;
d)
dryRun=true
;;
p)
PUSH_URL=${OPTARG}
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
if [[ -z "${version}" ]]; then
echo "Parameter -v is required to indicate the version to build and tag" >&2
exit 1
fi
if [[ "$(python -c "import semantic_version; print semantic_version.validate('${version}')" )" != "True" ]]; then
echo "Parameter -v should be a semver 2.0 compatible version (http://semver.org/)" >&2
exit 1
fi
# read version
read -r major minor patch prerelease build <<< $(python -c "import semantic_version; v = semantic_version.Version('${version}'); print v.major, v.minor, v.patch, '.'.join(v.prerelease), '.'.join(v.build);")
# Detect correct supporting branch
branch=$(git branch --list -r "*/release/${major}.${minor}")
if [[ -z "${branch}" ]]; then
branch="develop"
fi
branch=$(echo ${branch} | sed -e "s@^.*/\(release/.*\)@\1@")
echo "Switching to branch ${branch}..."
releaseBranch=${branch}
git checkout ${branch}
currentVersion=$(python -c "import xml.etree.ElementTree as ET; print(ET.parse(open('pom.xml')).getroot().find('{http://maven.apache.org/POM/4.0.0}version').text)")
checkVers=$(echo ${currentVersion} | sed -e "s/-SNAPSHOT/-0/")
if [[ "True" != "$(python -c "import semantic_version; print semantic_version.Version('${version}') >= semantic_version.Version('${checkVers}')" )" ]]; then
echo "Can't release version ${version} on top of branch ${branch} as its current version is ${currentVersion}" >&2
exit 1
fi
# Check branch tags
branchTag=$(git describe --abbrev=0 --tags ${branch}) || {
branchTag="v0.0.0"
}
branchTag=$(echo $branchTag | sed -e 's/^janus-a4c-plugin-\(.*\)$/\1/' -e 's/^v\(.*\)$/\1/')
if [[ "True" != "$(python -c "import semantic_version; print semantic_version.Version('${version}') > semantic_version.Version('${branchTag}')" )" ]]; then
echo "Can't release version ${version} on top of branch ${branch} as it contains a newer tag: v${branchTag}" >&2
exit 1
fi
if [[ "develop" == "${branch}" ]] && [[ -z "${prerelease}" ]]; then
# create release branch
releaseBranch="release/${major}.${minor}"
git checkout -b "${releaseBranch}"
sed -i -e "s@svg?branch=[^)]*@svg?branch=${releaseBranch}@g" README.md
git commit -m "Update travis links in readme for release ${version}" README.md
fi
# Now checks are passed then tag, build, release and cleanup :)
# Update changelog Release date
sed -i -e "s/^## UNRELEASED.*$/## ${version} ($(LC_ALL=C date +'%B %d, %Y'))/g" CHANGELOG.md
# Update readme for Release number
sed -i -e "[email protected]?version=[^)]*@download.svg?version=${version}@g" -e "s@distributions/[^/]*/link@distributions/${version}/link@g" README.md
git commit -m "Update changelog and readme for release ${version}" CHANGELOG.md README.md
if [[ -n "${prerelease}" ]]; then
# in prerelease revert to version minus prerelease plus -SNAPSHOT
nextDevelopmentVersion="${major}.${minor}.${patch}-SNAPSHOT"
else
nextDevelopmentVersion=$(python -c "import semantic_version; v=semantic_version.Version('${version}'); print v.next_patch()" )
nextDevelopmentVersion="${nextDevelopmentVersion}-SNAPSHOT"
fi
if [[ -n "$PUSH_URL" ]]; then
mvnOpts="$(echo $PUSH_URL | sed -e "s~.*://\([^:@]*\):\([^@]*\)@.*~-Dusername=\1 -Dpassword=\2~g")"
fi
if [ "${dryRun}" = false ] ; then
mvnOpts="${mvnOpts} -DpushChanges=true"
else
mvnOpts="${mvnOpts} -DpushChanges=false"
fi
####################################################
# Make our build
####################################################
echo "Prepare release v${version}"
set +x
mvn release:clean release:prepare ${mvnOpts} --batch-mode -Dtag=v${version} -DreleaseVersion=${version} -DdevelopmentVersion=${nextDevelopmentVersion}
echo "Tag done."
set -x
# Update changelog for future release
sed -i -e "2a## UNRELEASED\n" CHANGELOG.md
git commit -m "Update changelog for future release" CHANGELOG.md
if [[ "develop" == "${branch}" ]] && [[ -z "${prerelease}" ]]; then
# merge back to develop and update version
git checkout develop
git merge --no-ff "v${version}" -m "merging latest tag v${version} into develop"
# Update changelog for future versions
if [[ -e CHANGELOG.md ]]; then
sed -i -e "2a## UNRELEASED\n" CHANGELOG.md
git commit -m "Update changelog for future release" CHANGELOG.md
fi
nextDevelopmentVersion=$(python -c "import semantic_version; v=semantic_version.Version('${version}'); print v.next_minor()" )
nextDevelopmentVersion="${nextDevelopmentVersion}-SNAPSHOT"
mvn --batch-mode release:update-versions -DdevelopmentVersion=${nextDevelopmentVersion}
find . -name pom.xml | grep -v "/target/" | xargs git commit -m "Prepare next development version"
fi
if [[ -z "${prerelease}" ]]; then
# Merge on master only final version
masterTag=$(git describe --abbrev=0 --tags master) || {
masterTag="v0.0.0"
}
masterTag=$(echo ${masterTag} | sed -e 's/^v\(.*\)$/\1/')
if [[ "True" == "$(python -c "import semantic_version; print semantic_version.Version('${version}') > semantic_version.Version('${masterTag}')" )" ]]; then
# We should merge the tag to master as it is our highest release
git checkout master
git merge --no-ff "v${version}" -X theirs -m "merging latest tag v${version} into master" || {
git merge --abort || true
git reset --hard "v${version}"
}
fi
fi
# Push changes
if [ "${dryRun}" = false ] ; then
set +x
git push ${PUSH_URL} --all
git push ${PUSH_URL} --tags
fi