Skip to content

Commit 9560633

Browse files
committed
Improve update_versions.sh script:
-support for "rc" (release candidate) qualifier -support for numbers in qualifiers (i.e. rc1) -support for updating individual modules only (useful for transfering modules between stages: alpha->beta->rc->ga) -readme update improvements -various fixes
1 parent 734a7c4 commit 9560633

File tree

1 file changed

+102
-22
lines changed

1 file changed

+102
-22
lines changed

utilities/update_versions.sh

Lines changed: 102 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,27 @@
44

55
# This script updates pom.xml, README.md and other relevant files to the next version number.
66
# This script is meant to be run manually (not by Travis)
7-
8-
# Arguments (optional):
7+
#
8+
# This script should be ALWAYS executed from the repo root directory: ./utilities/update_versions.sh
9+
#
10+
# Arguments (all are optional):
11+
# --modules= specifies coma separated list of modules to update (spaces are not allowed),
12+
# for example --modules=google-cloud-logging,google-cloud-vision
913
# --alpha= specifies new version for alpha modules in format
1014
# "major.minor.incremental.qualifier[-SNAPSHOT]",
1115
# for example --alpha=0.12.2-alpha-SNAPSHOT
1216
# --beta= specifies new version for beta modules in format
1317
# "major.minor.incremental.qualifier[-SNAPSHOT]",
1418
# for example --beta=0.12.2-beta
19+
# --rc= specifies new version for release candidate modules in format
20+
# "major.minor.incremental.qualifier[-SNAPSHOT]",
21+
# for example --rc=0.12.2-rc1
1522
# --ga= specifies new version for GA modules in format
1623
# "major.minor.incremental.qualifier[-SNAPSHOT]",
1724
# for example --ga=0.12.2
1825
#
1926
# If at least one argument is provided it means that all the other modules, which do not belong
20-
# to the argument's qualifier(s) ("alpha", "beta" and/or "ga"), will NOT be updated.
27+
# to the argument's qualifier(s) ("alpha", "beta", "rc" and/or "ga"), will NOT be updated.
2128
#
2229
# Providing no argument defaults to incrementing revision number in ALL modules to
2330
# major.minor.incremental+1-qualifier-SNAPSHOT if the current version is
@@ -27,6 +34,28 @@
2734
# This scripts assumes that all project modules have explicit
2835
# <version>major.minor.incremental.qualifier[-SNAPSHOT]</version> element specified in each
2936
# (parent and children) module's pom.xml
37+
#
38+
# Examples:
39+
# ~$ ./utilities/update_versions.sh --modules=google-cloud-logging,google-cloud-speech
40+
# will update only modules google-cloud-logging and google-cloud-speech, ignoring others, using
41+
# default version bumping described above;
42+
#
43+
# ~$ ./utilities/update_versions.sh --alpha=0.12.3-alpha
44+
# will update all alpha modules to the specified version, ignoring others (beta, rc and ga);
45+
#
46+
# ~$ ./utilities/update_versions.sh --alpha=0.12.3-alpha-SNAPSHOT --rc=0.12.3-rc2-SNAPSHOT
47+
# will update only all alpha and rc modules to the specified versions respectively, as result all
48+
# alpha and rc modules within the repo will be of version 0.12.3-alpha-SNAPSHOT and
49+
# 0.12.3-rc2-SNAPSHOT respectively;
50+
#
51+
# ~$ ./utilities/update_versions.sh --modules=google-cloud-logging,google-cloud-speech --beta=0.12.3-beta --ga=1.1.0
52+
# assuming on the moment of execution google-cloud-logging is in GA, and google-cloud-speech
53+
# is in beta, the above command will update google-cloud-logging to 1.1.0 and google-cloud-speech
54+
# to 0.12.3-beta, ignoring all other modules.
55+
#
56+
# ~$ ./utilities/update_versions.sh --modules=google-cloud-speech --beta=1.0.0
57+
# assuming google-cloud-speech is in beta, the above command can be executed to move it to
58+
# ga stage.
3059

3160
set -e
3261

@@ -35,14 +64,19 @@ GREEN='\033[1;32m'
3564
BOLD='\033[1m'
3665
NC='\033[0m'
3766

67+
MODULES=""
3868
ALPHA_VERSION=""
3969
BETA_VERSION=""
70+
RC_VERSION=""
4071
GA_VERSION=""
41-
SINGLE_MODULE=""
4272

4373
for i in "$@"
4474
do
4575
case $i in
76+
--modules=*)
77+
MODULES="${i#*=}"
78+
shift
79+
;;
4680
--alpha=*)
4781
ALPHA_VERSION="${i#*=}"
4882
shift
@@ -51,6 +85,10 @@ case $i in
5185
BETA_VERSION="${i#*=}"
5286
shift
5387
;;
88+
--rc=*)
89+
RC_VERSION="${i#*=}"
90+
shift
91+
;;
5492
--ga=*)
5593
GA_VERSION="${i#*=}"
5694
shift
@@ -60,13 +98,13 @@ case $i in
6098
esac
6199
done
62100

101+
echo -e "\n${BOLD}Parameters passed:${NC} --modules=${MODULES} --alpha=${ALPHA_VERSION}, --beta=${BETA_VERSION}, --rc=${RC_VERSION}, --ga=${GA_VERSION}"
102+
103+
# Necessary step for the next "mvn dependency:tree" command to complete successuflly
63104
echo -e "\n${BOLD}Executing${NC} mvn -q clean install -DskipTests -Dmaven.javadoc.skip=true"
64105
mvn -q clean install -DskipTests -Dmaven.javadoc.skip=true
65106

66-
echo -e "\n${BOLD}Parameters passed:${NC} --alpha=${ALPHA_VERSION}, --beta=${BETA_VERSION}, --ga=${GA_VERSION}"
67-
68107
echo -e "\n${BOLD}Checking modules${NC}"
69-
70108
modules=$(mvn dependency:tree | grep "\[INFO\] com\.google\." | sed -r "s/.*:(.*):(.*):(.*)/\1:\3/g")
71109
declare -A module_version_map
72110
root_module=""
@@ -79,6 +117,19 @@ do
79117
fi
80118
done
81119

120+
echo -e "\n${BOLD}Validating explicitly specified modules${NC}"
121+
declare -A specified_modules_map
122+
if [ "${MODULES}" != "" ]; then
123+
specified_modules_arr=(${MODULES//,/ })
124+
125+
for item in ${specified_modules_arr[*]}; do
126+
if [ "${module_version_map[${item}]}" != "" ]; then
127+
specified_modules_map[${item}]=${module_version_map[${item}]}
128+
else
129+
echo -e "${RED}WARNING:${NC} Module \"${item}\" module, specified in --modules parameter could not be found, ignoring \"${item}\""
130+
fi
131+
done
132+
fi
82133

83134
echo -e "\n${BOLD}Checking module folders${NC}"
84135
module_folders=($(find . -maxdepth 2 -type d | sed -E -n "/^\.\/(google-cloud-contrib\/|google-cloud-testing\/)?google-cloud(-[a-z0-9]+)+$/p") . ./google-cloud)
@@ -105,33 +156,45 @@ for item in ${modules[*]}; do
105156
folder="${module_folder_map[${module}]}"
106157
old_version="${module_version_map[${module}]}"
107158

108-
# Determine current base_version (e.g. "0.12.1"), qualifier (e.g. "-alpha") and snapshot (e.g. "-SNAPSHOT" or "")
159+
# Check if we need to update only the specified modules, and if we do, ignore the other modules
160+
if [ "${MODULES}" != "" ]; then
161+
if [ "${specified_modules_map[${module}]}" == "" ]; then
162+
echo -e "${RED}WARNING:${NC} Ignoring \"${item}\" module, as it is not specified in --modules= non-empty parameter"
163+
continue
164+
fi
165+
fi
166+
167+
# Determine current base_version (e.g. "0.12.1"), qualifier (e.g. "-alpha" or "-rc1") and snapshot (e.g. "-SNAPSHOT" or "")
109168
base_version=${old_version}
110-
snapshot=""
111169
qualifier=""
170+
snapshot=""
112171

113172
if [ "${base_version##*-}" == "SNAPSHOT" ]; then
114173
snapshot="-SNAPSHOT"
115174
base_version="${base_version%-*}"
116175
fi
117-
if [ "${base_version##*-}" == "alpha" ] || [ "${base_version##*-}" == "beta" ]; then
176+
if [[ "${base_version##*-}" =~ [a-z]+[0-9]* ]]; then
118177
qualifier="-${base_version##*-}"
119178
base_version="${base_version%-*}"
120179
fi
121180

122181
# Determine new_version value
123182
new_version=""
124-
if [ "${ALPHA_VERSION}" != "" ] && [ "${qualifier}" == "-alpha" ]; then
183+
if [ "${ALPHA_VERSION}" != "" ] && [[ "${qualifier}" =~ -alpha[0-9]* ]]; then
125184
new_version=${ALPHA_VERSION}
126185
fi
127-
if [ "${BETA_VERSION}" != "" ] && [ "${qualifier}" == "-beta" ]; then
186+
if [ "${BETA_VERSION}" != "" ] && [[ "${qualifier}" =~ -beta[0-9]* ]]; then
128187
new_version=${BETA_VERSION}
129188
fi
189+
if [ "${RC_VERSION}" != "" ] && [[ "${qualifier}" =~ -rc[0-9]* ]]; then
190+
new_version=${RC_VERSION}
191+
fi
130192
if [ "${GA_VERSION}" != "" ] && [ "${qualifier}" == "" ]; then
131193
new_version=${GA_VERSION}
132194
fi
195+
echo -e "base_version=${base_version}, qualifier=${qualifier}, snapshot=${snapshot}"
133196

134-
if [ "${ALPHA_VERSION}" == "" ] && [ "${BETA_VERSION}" == "" ] && [ "${GA_VERSION}" == "" ]; then
197+
if [ "${ALPHA_VERSION}" == "" ] && [ "${BETA_VERSION}" == "" ] && [ "${RC_VERSION}" == "" ] && [ "${GA_VERSION}" == "" ]; then
135198
if [ "${snapshot}" == "" ]; then
136199
new_snapshot="-SNAPSHOT"
137200
new_base_version="${base_version%.*}.$((${base_version##*.}+1))"
@@ -147,6 +210,21 @@ for item in ${modules[*]}; do
147210
continue
148211
fi
149212

213+
# Determine new base_version (e.g. "0.13.1"), new qualifier (e.g. "-alpha" or "-rc2") and new snapshot (e.g. "-SNAPSHOT" or "")
214+
new_base_version=${new_version}
215+
new_qualifier=""
216+
new_snapshot=""
217+
218+
if [ "${new_base_version##*-}" == "SNAPSHOT" ]; then
219+
new_snapshot="-SNAPSHOT"
220+
new_base_version="${new_base_version%-*}"
221+
fi
222+
if [[ "${new_base_version##*-}" =~ [a-z]+[0-9]* ]]; then
223+
new_qualifier="-${new_base_version##*-}"
224+
new_base_version="${new_base_version%-*}"
225+
fi
226+
echo -e "new_base_version=${new_base_version}, new_qualifier=${new_qualifier}, new_snapshot=${new_snapshot}"
227+
150228
echo -e "Updating module ${BOLD}${module}${NC} in folder ${folder} from version ${RED}${old_version}${NC} to ${GREEN}${new_version}${NC}"
151229
module_suffix=${module##*-}
152230

@@ -159,7 +237,7 @@ for item in ${modules[*]}; do
159237
# 2) Update version of the module. If the module is a parent of other modules
160238
# (like the root module or the google-cloud-contrib), then the parent secion of its child modules
161239
# will be updated too.
162-
echo -e " Updating version in ${folder}\pom.xml and the parent version in the corresponding children modules if exist"
240+
echo -e " Updating version in ${folder}/pom.xml and the parent version in the corresponding children modules if exist"
163241
mvn -q versions:set -DartifactId=${module} -DnewVersion=${new_version} -DprocessPlugins=false -DgenerateBackupPoms=false
164242

165243
# 3) Update Google App Engine application dockerfile, if it exists.
@@ -170,16 +248,18 @@ for item in ${modules[*]}; do
170248
fi
171249

172250
# 4) Update README.md
173-
if [ "${new_snapshot}" == "" ] && [ -f ${folder}/README.md ]; then
174-
echo -e " Updating ${folder}/README.md"
251+
if [ -f ${folder}/README.md ] && [ "${new_snapshot}" == "" ]; then
252+
readme_version="${new_version}"
175253
if [ "${module}" != "google-cloud-nio-examples" ]; then
176-
sed -ri "s/<version>[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+)?<\/version>/<version>${new_version}<\/version>/g" ${folder}/README.md
177-
sed -ri "s/:[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+)?'/:${new_version}'/g" ${folder}/README.md
178-
sed -ri "s/\"[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+)?\"/\"${new_version}\"/g" ${folder}/README.md
254+
echo -e " Updating ${folder}/README.md to the version ${readme_version}"
255+
sed -ri "s/<version>[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+[0-9]*)?<\/version>/<version>${readme_version}<\/version>/g" ${folder}/README.md
256+
sed -ri "s/:[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+[0-9]*)?'/:${readme_version}'/g" ${folder}/README.md
257+
sed -ri "s/\"[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+[0-9]*)?\"/\"${readme_version}\"/g" ${folder}/README.md
179258
else
180-
examples_version=${new_base_version%.*}.$((${new_base_version##*.}+1))-alpha-SNAPSHOT
181-
sed -ri "s/google-cloud-nio-[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+)?-SNAPSHOT/google-cloud-nio-${examples_version}/g" ${folder}/README.md
182-
sed -ri "s/google-cloud-nio-examples-[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+)?-SNAPSHOT/google-cloud-nio-examples-${examples_version}/g" ${folder}/README.md
259+
readme_version="${new_base_version%.*}.$((${new_base_version##*.}+1))${new_qualifier}-SNAPSHOT"
260+
echo -e " Updating ${folder}/README.md to the version ${readme_version}"
261+
sed -ri "s/google-cloud-nio-[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+[0-9]*)?-SNAPSHOT/google-cloud-nio-${readme_version}/g" ${folder}/README.md
262+
sed -ri "s/google-cloud-nio-examples-[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+[0-9]*)?-SNAPSHOT/google-cloud-nio-examples-${readme_version}/g" ${folder}/README.md
183263
fi
184264
fi
185265
done

0 commit comments

Comments
 (0)