forked from strolch-li/strolch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·147 lines (121 loc) · 3.71 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
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
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
# usage
if [ $# != 2 ] ; then
echo -e "Usage: ${0} <source_branch> <version>"
exit 1
fi
# Confirm
sourceBranch=${1}
releaseVersion=${2}
echo -e "INFO: Do you want to release version ${releaseVersion} from branch ${sourceBranch}? y/n"
read a
if [[ "${a}" != "y" && "${a}" != "Y" ]] ; then
exit 0;
fi
# validate tag and release branch do not exist
echo -e "INFO: Fetching tags and branches and validating they do not exist..."
if ! git fetch --all --tags > /dev/null ; then
echo -e "ERROR: Tags and branches could not be fetched!"
exit 1
fi
if git tag | grep "${releaseVersion}" > /dev/null ; then
echo -e "ERROR: Tag already exists!"
exit 1
fi
if git branch --all | grep "release/${releaseVersion}" > /dev/null ; then
echo -e "ERROR: Tag already exists!"
exit 1
fi
# validate tag does not exist
if git tag | grep "${releaseVersion}" > /dev/null ; then
echo -e "ERROR: Tag already exists!"
exit 1
fi
# make sure gpg-agent is available and loaded
echo -e "\nINFO: Searching for gpg-agent..."
if ! which gpg-agent ; then
echo -e "ERROR: gpg-agent missing!"
fi
if ! gpg-agent 2>&1 | grep "running and available" ; then
echo -e "WARN: gpg-agent not running, trying to start..."
if ! gpg-agent --daemon ; then
echo -e "ERROR: Failed to initialize gpg-agent, please make sure it is up and running before continuing!"
exit 1
fi
if ! gpg-agent 2>&1 | grep "running and available" ; then
echo -e "ERROR: Failed to initialize gpg-agent, please make sure it is up and running before continuing!"
exit 1
fi
fi
# Checkout source branch
echo -e "\nINFO: Checking out source branch ${sourceBranch}"
if ! git checkout ${sourceBranch} ; then
echo -e "ERROR: Failed to checkout branch ${sourceBranch}"
exit 1
fi
# create new release branch, and temp tag
echo -e "\nINFO: Creating release and temp branches..."
if ! git checkout -b release/${releaseVersion} ; then
echo -e "ERROR: Failed to create release branch!"
exit 1
fi
if ! git checkout -b temp ; then
echo -e "ERROR: Failed to create temp branch!"
exit 1
fi
# set release version
echo -e "\nINFO: Setting version..."
if ! mvn versions:set -DgenerateBackupPoms=false -DnewVersion=${releaseVersion} > /dev/null ; then
echo -e "ERROR: Failed to set new version!"
exit 1
fi
# build
echo -e "\nINFO: Doing a build with new version..."
if ! mvn clean package -DskipTests > /dev/null ; then
echo -e "ERROR: Failed to build with new version!"
exit 1
fi
# commit to tag
echo -e "\nINFO: Creating tag..."
if ! git add . ; then
echo -e "ERROR: Failed to git add"
exit 1
fi
if ! git commit -m "[Project] Set new version ${releaseVersion}" ; then
echo -e "ERROR: Failed to git commit"
exit 1
fi
if ! git tag --sign --message "[Project] New Version ${releaseVersion}" ${releaseVersion} ; then
echo -e "ERROR: Failed to git tag"
exit 1
fi
# cleanup
echo -e "\nINFO: Cleaning up..."
if ! git checkout release/${releaseVersion} ; then
echo -e "ERROR: Failed to checkout release branch"
exit 1
fi
if ! git branch -D temp ; then
echo -e "ERROR: Failed to delete temp branch"
exit 1
fi
# git push
echo -e "\nINFO: Release ${releaseVersion} created. Do you want to push to origin? y/n"
read a
if [[ "${a}" == "y" || "${a}" == "Y" ]] ; then
echo -e "INFO: Pushing to origin..."
if ! git push origin release/${releaseVersion} ; then
echo -e "ERROR: Failed to push release branch"
exit 1
fi
if ! git push origin ${releaseVersion} ; then
echo -e "ERROR: Failed to push tag"
exit 1
fi
echo -e "\nINFO: Pushed release branch and tag for release version ${releaseVersion}"
else
echo -e "WARN: Release not pushed!"
fi
echo -e "\nINFO: Release ${releaseVersion} created."
echo -e "INFO: Don't forget to update snapshot version!"
exit 0