forked from gooddata/gooddata-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·101 lines (85 loc) · 2.95 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
#!/bin/bash
usage(){
echo "Usage: $0 -v <desired version> -g <gpg password>"
echo "Or if you want to be asked fro GPG password without printing to console: $0 -v <desired version>"
exit 1
}
while getopts ":hv:g:" opt
do
case ${opt} in
v)
VERSION=${OPTARG}
;;
g)
GPG_PASS=${OPTARG}
;;
h)
usage
exit 0
;;
\?)
echo -e "Invalid option: -${OPTARG}"
exit 1
;;
:)
echo -e "Option -${OPTARG} require argument."
exit 2
;;
esac
done
shift $(( ${OPTIND} - 1 ))
if [[ $# -ne 0 ]]; then
echo "There are unexpected parameters!" 1>&2
usage
exit 1
fi
if [[ -z "${VERSION}" ]]; then
echo "No version given!"
usage
exit 1
fi
if ! [[ ${VERSION} =~ ^[0-9]+\.[0-9]+\.[0-9]+(-RC\.[0-9]+)?$ ]]; then
echo "Version has to match regex ^[0-9]+\.[0-9]+\.[0-9]+(-RC\.[0-9]+)?$"
exit 1
fi
if [ -z "${GPG_PASS}" ]; then
echo "Enter gpg password: "
read -s GPG_PASS
if [[ -z "${GPG_PASS}" ]]; then
echo "No gpg password given!"
usage
exit 1
fi
fi
if [[ $(git log -1 --pretty="%s") =~ ^\[maven-release-plugin\].+$ ]]; then
echo "Latest commit in your branch is from maven-release-plugin. You're either on wrong branch or your previous release trial failed and you haven't removed commits created in this trial."
exit 1
fi
if [[ $(git log -1 --pretty="%s") =~ "^bump version$" ]]; then
echo "Latest commit in your branch is \"bump version\". You're either on wrong branch or your previous release trial failed and you haven't removed commits created in this trial."
exit 1
fi
API_VERSION=$(cat gooddata-java-model/src/main/resources/GoodDataApiVersion)
FULL_VERSION=${VERSION}+api${API_VERSION}
DEV_VERSION=$(echo ${VERSION} | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')-SNAPSHOT
sed -i.bak "s/\(<version>\)[0-9]*\.[0-9]*\.[0-9]*[^<]*\(<\/version>\)/\1${FULL_VERSION}\2/" README.md && rm -f README.md.bak
git commit -a -m "bump version"
mvn --batch-mode release:prepare -DreleaseVersion=${FULL_VERSION} -DdevelopmentVersion=${DEV_VERSION}
MVN_RET_VAL=$?
if [[ ${MVN_RET_VAL} -ne 0 ]]; then
echo
echo "ERROR: Maven build failed during release:prepare phase - please fix it and try to release again."
echo "WARN: You may need to remove up to 3 commits depending on what was done before the failure. Use e.g.: git reset --hard origin/HEAD"
echo
exit ${MVN_RET_VAL}
fi
mvn --batch-mode release:perform -Darguments="-Dgpg.passphrase=${GPG_PASS} -Dmaven.test.skip=true -Dfindbugs.skip=true"
MVN_RET_VAL=$?
if [[ ${MVN_RET_VAL} -ne 0 ]]; then
echo
echo "ERROR: Maven build failed during release:perform phase - please fix it and try to release again."
echo "WARN: You may need to remove up to 3 commits depending on what was done before the failure. Use e.g.: git reset --hard origin/HEAD"
echo
exit ${MVN_RET_VAL}
fi
git push origin --tags HEAD