forked from jbrisbin/rabbit_common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbump_version
executable file
·237 lines (205 loc) · 5.84 KB
/
bump_version
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/bin/bash
set -euo pipefail
ORIG_LIB_DIR=".build/rabbitmq"
ORIG_RMQ_DIR=".build/rabbitmq-server"
ORIG_CODEGEN_DIR=".build/rabbitmq-codegen"
# Clones the client when it is not present yet
# Params: None
function get_rmq_client {
echo "* Checking if rabbitmq source exists..."
if [ ! -d "${ORIG_LIB_DIR}" ]; then
echo "* It doesn't. Cloning..."
git clone https://github.com/rabbitmq/rabbitmq-erlang-client.git ${ORIG_LIB_DIR}
fi
}
# Gets the latest version of the RMQ client.
# Params: None
function update_rmq_client {
echo "* Updating client source..."
(cd ${ORIG_LIB_DIR} && git checkout master)
(cd ${ORIG_LIB_DIR} && git fetch origin)
(cd ${ORIG_LIB_DIR} && git pull origin master)
}
# Clones the rmq server sources when it is not present yet
# Params: None
function get_rmq_server {
echo "* Checking if rabbitmq server source exists..."
if [ ! -d "${ORIG_RMQ_DIR}" ]; then
echo "* It doesn't. Cloning..."
git clone https://github.com/rabbitmq/rabbitmq-server.git ${ORIG_RMQ_DIR}
fi
}
# Updates the rmq server sources to the latest version.
# Params: None
function update_rmq_server {
(cd ${ORIG_RMQ_DIR} && git checkout master)
(cd ${ORIG_RMQ_DIR} && git fetch origin)
(cd ${ORIG_RMQ_DIR} && git pull origin master)
}
# Clones the rmq code generation tools when they are not present yet.
# Params: None
function get_rmq_codegen {
echo "* Checking the rabbitmq codegen sources..."
if [ ! -d "${ORIG_CODEGEN_DIR}" ]; then
git clone https://github.com/rabbitmq/rabbitmq-codegen.git ${ORIG_CODEGEN_DIR}
fi
}
# Updates the code gen tools to the latest version
# Params: None
function update_rmq_codegen {
(cd ${ORIG_CODEGEN_DIR} && git checkout master)
(cd ${ORIG_CODEGEN_DIR} && git fetch origin)
(cd ${ORIG_CODEGEN_DIR} && git pull origin master)
}
# Checks out the specified tag
# Params: The tag to check out
function client_checkout_tag {
echo "Checking out client tag $1"
(cd $ORIG_LIB_DIR && git checkout $1)
}
# Checks out the specified tag
# Params: The tag to check out
function server_checkout_tag {
echo "Checking out server tag $1"
(cd $ORIG_RMQ_DIR && git checkout $1)
}
# Checks out the specified tag
# Params: The tag to check out
function codegen_checkout_tag {
echo "Checking out codegen tag $1"
(cd $ORIG_CODEGEN_DIR && git checkout $1)
}
# Builds the rmq server in order to get the generated files.
# Params: None
function build_rmq_server {
echo "* Building server files. (This can take a few minutes...)"
local failed=0
local log=""
log=$(make -C ${ORIG_RMQ_DIR} | tail -10) || failed=1
if [ ${failed} -eq 1 ]; then
echo "Build failed.. Last 10 lines of the log: "
echo "${log}"
exit 1
fi
echo "OK!"
}
# Cleans up the files from the target directories. This ensures that deprecated files are removed.
# Params: None
function remove_old_files {
echo "* Cleaning old files."
# Use -f as these files might not exist.
rm -f src/*.erl
rm -f include/*
}
# Reads the required modules from the app definition and copies those files
# Params: None
function copy_common_files {
echo "* Parsing dependencies."
local files=( $(tools/read_common_deps.escript "${ORIG_LIB_DIR}/rabbit_common.app.in") )
if [ ${#files[@]} -eq 0 ]; then
echo "No dependencies found."
exit 1
fi
echo "Got ${#files[@]} files."
for file in "${files[@]}"; do
echo "Copying ${file}"
cp "${ORIG_RMQ_DIR}/src/${file}" "src/${file}"
done
}
# Copies all files from the server include dir to the common include dir
# Params: None
function copy_include_files {
echo "Copying include files."
cp -r ${ORIG_RMQ_DIR}/include .
}
# Cleans up the rmq server build results in order to waste less diskspace
# Params: None
function cleanup {
echo "* Cleaning up..."
(make clean -C ${ORIG_RMQ_DIR} &> /dev/null )
}
# Updates the app.src file.
# Params: The tag to use
function update_app_src {
local latest_tag=$1
echo "* Updating app.src file."
sed "s/%%VERSION%%/${latest_tag}/g" src/rabbit_common.app.src.in > src/rabbit_common.app.src
}
# Shows the modified files before committing.
# Params: None
function review {
echo "* Please review the following changes:"
git add .
git status
echo "OK? (y/n)"
read -n 1 OK
printf "\n"
if [ "${OK}" != "y" ]; then
exit 1
fi
}
# Creates a commit
# Params: None
function commit {
git commit -m "NEW Bumped RabbitMQ version to ${latest_tag}"
}
# Creates a tag
# Params: Current rabbitmq client version
function tag {
local latest_tag=$1
git tag ${latest_tag}
}
# Pushes the changes to master.
# Params: None
function push {
git push origin master
git push origin --tags
}
# Determines whether to create a commit/tag or not.
# Params: Latest rmq client tag
function create_tag {
local latest_tag=$1
local current_tag=$(git describe --abbrev=0 --tags)
if [ ${current_tag}=${latest_tag} ]; then
echo "A commit with the current RMQ version already exists. Create new tag anyway?"
read -n 1 new_tag
printf "\n"
if [ "${new_tag}" != "y" ]; then
push
else
commit
git tag -f ${latest_tag}
git push origin master
git push origin --tags -f
fi
else
commit
tag ${latest_tag}
push
fi
}
function main {
get_rmq_client
update_rmq_client
get_rmq_server
update_rmq_server
get_rmq_codegen
update_rmq_codegen
# Determine the latest client tag
local latest_tag=$(cd ${ORIG_LIB_DIR} && git describe --abbrev=0 --tags)
# Checkout that tag
client_checkout_tag ${latest_tag}
server_checkout_tag ${latest_tag}
codegen_checkout_tag ${latest_tag}
# Build server files
build_rmq_server
remove_old_files
# Copy the common src and include files
copy_common_files
copy_include_files
cleanup
update_app_src ${latest_tag}
review
create_tag ${latest_tag}
}
main