This repository has been archived by the owner on Mar 10, 2021. It is now read-only.
forked from commercetools/commercetools-jvm-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-release.sh
executable file
·119 lines (96 loc) · 3.17 KB
/
prepare-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
#!/usr/bin/env bash
set -x
function updateReleaseVersion() {
RELEASE_TYPE=$1
if [[ ${RELEASE_TYPE} == "MAJOR" ]]
then
./mvnw build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.nextMajorVersion}.0.0 -DgenerateBackupPoms=false
elif [[ ${RELEASE_TYPE} == "PATCH" ]]
then
./mvnw build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion} -DgenerateBackupPoms=false
else
./mvnw build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.0 -DgenerateBackupPoms=false
fi
}
function getBranchVersion() {
VERSION=`./mvnw -q build-helper:parse-version -Dexec.executable="echo" -Dexec.args='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec | tail -n 1`
echo ${VERSION}
}
function getVersion() {
VERSION=`./mvnw -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec | tail -n 1`
echo ${VERSION}
}
function updateSnapshotVersion() {
RELEASE_TYPE=$1
updateReleaseVersion ${RELEASE_TYPE}
if [[ ${RELEASE_TYPE} == "PATCH" ]]
then
echo "Patch not allowed at this branch"
exit 1
else
./mvnw build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.nextMinorVersion}.0-SNAPSHOT -DgenerateBackupPoms=false
fi
}
set +e
git diff --exit-code >/dev/null 2>&1
GIT_STATUS=$?
set -e
if [[ ! ${GIT_STATUS} -eq 0 ]]
then
echo "Aborting due to uncommited changes"
exit 1
fi
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
TYPE=$1
if [[ ${TYPE} == "PATCH" ]]
then
RELEASE_BRANCH=$2
if [ -z ${RELEASE_BRANCH} ]
then
echo "Release branch wasn't provided and patch is not allowed on master"
exit 1
else
git fetch
if ! git checkout ${RELEASE_BRANCH}
then
echo "Provided branch does not exits!"
exit 1
fi
CURRENT_BRANCH=${RELEASE_BRANCH}
fi
fi
WORKDIR=`pwd`
TMPDIR=`mktemp -d`
echo "Copying to ${TMPDIR}"
cp -pr . ${TMPDIR}
echo "Done"
cd ${TMPDIR}
updateReleaseVersion ${TYPE}
RELEASE_VERSION=$(getVersion)
echo Build release ${RELEASE_VERSION} without running tests
./mvnw clean install -DskipTests
if [[ ${TYPE} != "PATCH" ]]
then
BRANCH_NAME=v$(getBranchVersion)
echo Branch ${BRANCH_NAME}
git checkout -b ${BRANCH_NAME}
git commit -am"TASK Prepare release ${RELEASE_VERSION}"
git push origin ${BRANCH_NAME}
git checkout ${CURRENT_BRANCH}
updateSnapshotVersion ${TYPE}
DEVELOPMENT_VERSION=$(getVersion)
echo Preparing next development version ${DEVELOPMENT_VERSION}
git commit -am"Set next development version ${DEVELOPMENT_VERSION}"
git pull -r
elif [[ ${TYPE} == "PATCH" ]]
then
if [[ ${CURRENT_BRANCH} != "master" ]]
then
git commit -am"TASK Prepare release ${RELEASE_VERSION}"
fi
fi
git push origin ${CURRENT_BRANCH}
echo Build directory ${TMPDIR}
cd ${WORKDIR}
git fetch
git checkout ${BRANCH_NAME}