-
Notifications
You must be signed in to change notification settings - Fork 1
/
release.sh
executable file
·108 lines (88 loc) · 2.64 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
102
103
104
105
106
107
#!/bin/bash
if [ "x$1" == "x--help" ]; then
echo "Release and version bump script for Maven based projects"
echo " with X.Y[-SNAPSHOT] versioning scheme."
echo "Usage: $0 [--major]"
echo
echo " --major This is a major release. Bump the X version"
echo " and reset Y to 0 prior to release."
echo " example: 1.5-SNAPSHOT -> 2.0 -> 2.1-SNAPSHOT"
exit 0
fi
function relhook_failed() {
echo "Release hook $1 failed."
exit 2
}
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "Current branch is $BRANCH"
echo "Verifying git status"
GIT_STATUS=$(git status --porcelain | grep -v '^?? ')
if [[ $GIT_STATUS ]]; then
git status
echo
echo "Your git tree is not clean, aborting."
exit 1
fi
CURRENT=$(mvn help:evaluate -Dexpression=project.version | grep -v '\[')
if [ "x$1" == "x--major" ]; then
echo "Performing MAJOR release version bump!"
BUMP_MAJOR="+1"
BUMP_MINOR="-\$2"
elif [[ "$CURRENT" != *SNAPSHOT ]]; then
echo "Performing full minor release version bump"
BUMP_MAJOR="+0"
BUMP_MINOR="+1"
else
echo "Performing minor release version bump"
BUMP_MAJOR="+0"
BUMP_MINOR="+0"
fi
CURRENT_RELEASE=$(echo $CURRENT | awk -F'[.-]' "{print (\$1$BUMP_MAJOR)\".\"(\$2$BUMP_MINOR)}")
NEXT_VERSION=$(echo $CURRENT | awk -F'[.-]' "{print (\$1$BUMP_MAJOR)\".\"(\$2$BUMP_MINOR+1)\"-SNAPSHOT\"}")
TAG="v$CURRENT_RELEASE"
echo
echo "Verify the following:"
echo "Current version: $CURRENT"
echo
echo "Release: $CURRENT_RELEASE"
echo "Tag: $TAG"
echo
echo "Next development version: $NEXT_VERSION"
echo
echo -n "Is everything correct? [yes/no]: "
read ok
if [ "x$ok" != "xyes" ]; then
echo "Negative answer. Aborting."
exit 1
fi
echo "Preparing release"
mvn versions:set -DnewVersion=$CURRENT_RELEASE | grep -v '\['
echo "Executing custom release scripts for $TAG"
if [ -d release.d ]; then
for SCRIPT in release.d/*
do
if [ -f $SCRIPT -a -x $SCRIPT ]; then
$SCRIPT $CURRENT_RELEASE $TAG || relhook_failed $SCRIPT
fi
done
fi
NAME=$(git config user.name)
EMAIL=$(git config user.email)
git commit -a -m "Releasing new version $CURRENT_RELEASE
Signed-off-by: $NAME <$EMAIL>"
git tag "$TAG"
echo "Preparing development version"
mvn versions:set -DnewVersion=$NEXT_VERSION | grep -v '\['
echo "Executing custom release scripts for $NEXT_VERSION"
if [ -d release.d ]; then
for SCRIPT in release.d/*
do
if [ -f $SCRIPT -a -x $SCRIPT ]; then
$SCRIPT $NEXT_VERSION latest || relhook_failed $SCRIPT
fi
done
fi
git commit -a -m "Preparing for next development iteration
Signed-off-by: $NAME <$EMAIL>"
echo "Perform the following command to push everything to the server:"
echo "git push origin $BRANCH $TAG"