forked from hibernate/hibernate-orm
-
Notifications
You must be signed in to change notification settings - Fork 5
/
tagRelease.sh
executable file
·111 lines (93 loc) · 3.2 KB
/
tagRelease.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
#! /bin/sh
################################################################################
# tagRelease.sh
#
# Replacement for the maven-release-plugin
################################################################################
# be defensive and stop the script
set -o nounset # when there are uninitalised variables
set -o errexit # or when statements return non true values
usage="Usage: tagRelease [-u] [-e exportDirectory] [-r releaseVersion] [-d devVersion]"
projectDir=`pwd`
releaseVersion=
devVersion=
performUpdate=''
exportDirectory=''
################################################################################
# Update all project poms and commit the changes.
#
# $1: project directory (base directory of recursve find)
# $2: new value for the pom version
################################################################################
updatePomVersionsAndCommit() {
for i in `find $1 -name "pom.xml"`; do
xmlstarlet ed -P -N x="http://maven.apache.org/POM/4.0.0" \
-u "/x:project/x:parent/x:version" -v $2 \
-u "/x:project/x:version" -v $2 \
$i > tmp
mv tmp $i
done
git commit -a -m "Updating pom versions to $2"
}
################################################################################
# Start script processing
################################################################################
while getopts ":e:r:d:u" opt; do
case $opt in
r)
releaseVersion=$OPTARG;;
d)
devVersion=$OPTARG;;
u)
performUpdate="true";;
e)
exportDirectory=$OPTARG;;
h)
echo $usage;;
\?)
echo $usage
exit 1;;
*)
echo $usage
exit 1;;
esac
done
if [ -z $releaseVersion ]; then
read -p "Enter the release version: " releaseVersion
fi
if [ -z $devVersion ]; then
read -p "Enter the development version: " devVersion
fi
projectName=`xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -v "/x:project/x:artifactId" pom.xml`
if [ -z "$projectName" ]; then
echo "Could not determine propject name (misasing/incomplete pom?)."
exit;
fi
################################################################################
# Confirm data
echo "About to tag release with following information:"
echo " tag version : $releaseVersion"
echo " dev version : $devVersion"
while true; do
read -p "Continue? " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
################################################################################
# Go, go , go
if [ -n "$performUpdate" ]; then
echo "Performing requested git pull..."
git pull
fi
updatePomVersionsAndCommit $projectDir $releaseVersion
git tag -m "Tagging $releaseVersion release" $releaseVersion
updatePomVersionsAndCommit $projectDir $devVersion
if [ $exportDirectory ]; then
git archive $releaseVersion | tar -x -C $exportDirectory
fi
# So far all changes were locally. Still need to push them to the remote repo
git push origin $releaseVersion
git push origin