-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathprepare-release.sh
executable file
·135 lines (110 loc) · 3.71 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/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 --no-transfer-progress
elif [[ ${RELEASE_TYPE} == "PATCH" ]]
then
./mvnw build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion} -DgenerateBackupPoms=false --no-transfer-progress
else
./mvnw build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.0 -DgenerateBackupPoms=false --no-transfer-progress
fi
}
function setReleaseVersion() {
SET_RELEASE_VERSION=$1
./mvnw build-helper:parse-version versions:set -DnewVersion=${SET_RELEASE_VERSION} -DgenerateBackupPoms=false --no-transfer-progress
}
function getBranchVersion() {
VERSION=`./mvnw -q build-helper:parse-version -Dexec.executable="echo" -Dexec.args='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}' --no-transfer-progress --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}' --no-transfer-progress --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 --no-transfer-progress
fi
}
set +e
git diff --exit-code >/dev/null 2>&1
GIT_STATUS=$?
set -e
export JAVA_HOME=${JAVA_HOME:-$JDK_18_x64}
echo "Java version: "
echo $JAVA_HOME
export PATH=$JAVA_HOME/bin:$PATH
java -version
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}
if [ -z ${SET_VERSION} ]
then
updateReleaseVersion ${TYPE}
else
setReleaseVersion ${SET_VERSION}
fi
RELEASE_VERSION=$(getVersion)
echo Build release ${RELEASE_VERSION} without running tests
./mvnw clean install -DskipTests --no-transfer-progress
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}