This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
release.sh
executable file
·100 lines (88 loc) · 2.9 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
#!/bin/bash
set -e
#-----------------------------------------------------------------------
# Helper functions (miscellaneous)
#-----------------------------------------------------------------------
CONSOLE_CYAN="\033[1m\033[36m"; CONSOLE_NORMAL="\033[0m"; CONSOLE_RED="\033[1m\033[31m"
printMsg() {
printf "${CONSOLE_CYAN}${1}${CONSOLE_NORMAL}\n"
}
printError() {
printf "${CONSOLE_RED}${1}${CONSOLE_NORMAL}\n"
exit 0
}
#-----------------------------------------------------------------------
# MAIN
#-----------------------------------------------------------------------
DEV=false
PROMPT=true
BRANCH_TO_CHECK="master"
while test $# -gt 0
do
case "$1" in
--dev)
DEV=true
BRANCH_TO_CHECK="develop"
;;
-y)
PROMPT=false
;;
*) echo "Bad option $1"
exit 1
;;
esac
shift
done
POM_VERSION=$(grep version pom.xml | grep -v -e '<?xml|~'| head -n 1 | sed 's/[[:space:]]//g' | sed -E 's/<.{0,1}version>//g' | awk '{print $1}')
printMsg "Welcome to javaClay release script"
if [ "$PROMPT" = true ]; then
read -p "Version defined is $POM_VERSION. Is this ok? (y/n) " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
printError "Please modify pom.xml version"
fi
printf "${CONSOLE_RED} IMPORTANT: you're about to build and officially release javaClay $VERSION ${CONSOLE_NORMAL}\n"
read -rsn1 -p" Press any key to continue (CTRL-C for quitting this script)";echo
fi
if [ "$DEV" = true ] ; then
mvn -DskipTests=true -P publish deploy -s settings.xml
else
printMsg "Pre-processing files in master"
VERSION="${POM_VERSION//-SNAPSHOT/}"
VERSION=$(echo "$VERSION" | cut -d '.' -f1,2)
PREV_VERSION=$(echo "$VERSION - 0.1" | bc)
NEW_VERSION=$(echo "$VERSION + 0.1" | bc)
GIT_TAG=$VERSION
read -p "Version is $VERSION. Previous Version defined is $PREV_VERSION. New version will be $NEW_VERSION. Is this ok? (y/n) " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
printError "Please modify pom.xml version"
fi
# Modify README.md
sed -i "s/$VERSION/$NEW_VERSION/g" README.md
sed -i "s/$PREV_VERSION/$VERSION/g" README.md
git add README.md
git commit -m "Modified README.md"
git push
# NOTE: maven will tag Git repository
mvn -DskipTests=true -P publish release:clean release:prepare release:perform -s settings.xml
# once released maven push pom.xml without SNAPSHOT tag in master
cp pom.xml develop.pom.xml
sed -i "s/$NEW_VERSION-SNAPSHOT/$VERSION/g" pom.xml
git add pom.xml
git commit -m "Released $VERSION"
git push
printMsg "Preparing develop branch"
## update develop branch also ##
git checkout develop
git merge master
mv develop.pom.xml pom.xml
git add pom.xml
git commit -m "New development version"
git push
# back to master
git checkout master
fi
printMsg " == Everything seems to be ok! Bye"