-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathset-version.sh
More file actions
executable file
·304 lines (241 loc) · 10.6 KB
/
set-version.sh
File metadata and controls
executable file
·304 lines (241 loc) · 10.6 KB
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#! /usr/bin/env bash
#
# Copyright contributors to the Galasa project
#
# SPDX-License-Identifier: EPL-2.0
#
#-----------------------------------------------------------------------------------------
#
# Objectives: Sets the version number of this component.
#
# Environment variable over-rides:
# None
#
#-----------------------------------------------------------------------------------------
# Where is this script executing from ?
BASEDIR=$(dirname "$0");pushd $BASEDIR 2>&1 >> /dev/null ;BASEDIR=$(pwd);popd 2>&1 >> /dev/null
# echo "Running from directory ${BASEDIR}"
export ORIGINAL_DIR=$(pwd)
# cd "${BASEDIR}"
cd "${BASEDIR}/.."
WORKSPACE_DIR=$(pwd)
#-----------------------------------------------------------------------------------------
#
# Set Colors
#
#-----------------------------------------------------------------------------------------
bold=$(tput bold)
underline=$(tput sgr 0 1)
reset=$(tput sgr0)
red=$(tput setaf 1)
green=$(tput setaf 76)
white=$(tput setaf 7)
tan=$(tput setaf 202)
blue=$(tput setaf 25)
#-----------------------------------------------------------------------------------------
#
# Headers and Logging
#
#-----------------------------------------------------------------------------------------
underline() { printf "${underline}${bold}%s${reset}\n" "$@" ;}
h1() { printf "\n${underline}${bold}${blue}%s${reset}\n" "$@" ;}
h2() { printf "\n${underline}${bold}${white}%s${reset}\n" "$@" ;}
debug() { printf "${white}%s${reset}\n" "$@" ;}
info() { printf "${white}➜ %s${reset}\n" "$@" ;}
success() { printf "${green}✔ %s${reset}\n" "$@" ;}
error() { printf "${red}✖ %s${reset}\n" "$@" ;}
warn() { printf "${tan}➜ %s${reset}\n" "$@" ;}
bold() { printf "${bold}%s${reset}\n" "$@" ;}
note() { printf "\n${underline}${bold}${blue}Note:${reset} ${blue}%s${reset}\n" "$@" ;}
#-----------------------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------------------
function usage {
h1 "Syntax"
cat << EOF
set-version.sh [OPTIONS]
Options are:
-v | --version xxx : Mandatory. Set the version number to something explicitly.
Re-builds the release.yaml based on the contents of sub-projects.
For example '--version 0.29.0'
EOF
}
#-----------------------------------------------------------------------------------------
# Process parameters
#-----------------------------------------------------------------------------------------
component_version=""
while [ "$1" != "" ]; do
case $1 in
-v | --version ) shift
export component_version=$1
;;
-h | --help ) usage
exit
;;
* ) error "Unexpected argument $1"
usage
exit 1
esac
shift
done
if [[ -z $component_version ]]; then
error "Missing mandatory '--version' argument."
usage
exit 1
fi
function update_all_pom_version_tags {
source_file=$1
h1 "Updating the version in $source_file "
temp_dir=$2
set -o pipefail
temp_file="$temp_dir/temp-pom.xml"
rm -f $temp_file
touch $temp_file
info "Using temporary file $temp_file"
info "Updating file $source_file"
while IFS="" read -r line ; do
if [[ $line =~ "<version>" ]]; then
info "version line found. $line"
transformed_line=$(echo -n "$line" | sed "s/<version>.*<\/version>$/<version>$component_version<\/version>/")
rc=$?; if [[ "${rc}" != "0" ]]; then error "Failed to substitute $source_file file."; exit 1; fi
info "changing that to $transformed_line"
line=$transformed_line
fi
echo "$line" >> $temp_file
done < $source_file
cp $temp_file ${source_file}
rc=$?; if [[ "${rc}" != "0" ]]; then error "Failed to overwrite new version of $source_file file."; exit 1; fi
success "$source_file updated OK."
}
function update_pom_platform_version_tag {
source_file=$1
h1 "Updating the version in $source_file "
temp_dir=$2
set -o pipefail
temp_file="$temp_dir/temp-pom.xml"
rm -f $temp_file
touch $temp_file
info "Using temporary file $temp_file"
info "Updating file $source_file"
done="false"
platform_line_found="false"
while IFS="" read -r line; do
if [[ "$done" == "false" ]]; then
if [[ $line =~ "<artifactId>dev.galasa.platform</artifactId>" ]]; then
info "platform line found. $line"
platform_line_found="true"
elif [[ $line =~ "<version>" ]] && [[ $platform_line_found == true ]]; then
info "platform version line found. $line"
transformed_line=$(echo -n "$line" | sed "s/<version>.*<\/version>/<version>$component_version<\/version>/")
rc=$?; if [[ "${rc}" != "0" ]]; then error "Failed to substitute $source_file file."; exit 1; fi
info "changing that to $transformed_line"
line=$transformed_line
info "No more version substitutions needed."
done="true"
fi
fi
# Write the line to the temporary file
echo "$line" >> "$temp_file"
done < "$source_file"
cp $temp_file ${source_file}
rc=$?; if [[ "${rc}" != "0" ]]; then error "Failed to overwrite new version of $source_file file."; exit 1; fi
success "$source_file updated OK."
}
function update_pom_first_version_tag {
source_file=$1
h1 "Updating the version in $source_file "
temp_dir=$2
set -o pipefail
temp_file="$temp_dir/temp-pom.xml"
rm -f $temp_file
touch $temp_file
info "Using temporary file $temp_file"
info "Updating file $source_file"
done="false"
while IFS="" read -r line ; do
if [[ "$done" == "false" ]]; then
if [[ $line =~ "<version>" ]]; then
info "version line found. $line"
transformed_line=$(echo -n "$line" | sed "s/<version>.*<\/version>$/<version>$component_version<\/version>/")
rc=$?; if [[ "${rc}" != "0" ]]; then error "Failed to substitute $source_file file."; exit 1; fi
info "changing that to $transformed_line"
line=$transformed_line
info "No more version substitutions done. Only the first occurrance changed."
done="true"
fi
fi
echo "$line" >> $temp_file
done < $source_file
cp $temp_file ${source_file}
rc=$?; if [[ "${rc}" != "0" ]]; then error "Failed to overwrite new version of $source_file file."; exit 1; fi
success "$source_file updated OK."
}
function update_simbank_version_in_script {
source_file=$1
h1 "Updating the version in $source_file "
temp_dir=$2
set -o pipefail
temp_file="$temp_dir/temp-script.sh"
rm -f $temp_file
touch $temp_file
info "Using temporary file $temp_file"
info "Updating file $source_file"
done="false"
while IFS="" read -r line ; do
if [[ "$done" == "false" ]]; then
if [[ $line =~ "SIMBANK_VERSION" ]]; then
info "simbank version line found. $line"
transformed_line=$(echo -n "$line" | sed "s/SIMBANK_VERSION=\".*\"/SIMBANK_VERSION=\"$component_version\"/")
rc=$?; if [[ "${rc}" != "0" ]]; then error "Failed to substitute $source_file file."; exit 1; fi
info "changing that to $transformed_line"
line=$transformed_line
info "No more version substitutions needed."
done="true"
fi
fi
echo "$line" >> $temp_file
done < $source_file
cp $temp_file ${source_file}
rc=$?; if [[ "${rc}" != "0" ]]; then error "Failed to overwrite new version of $source_file file."; exit 1; fi
success "$source_file updated OK."
}
temp_dir=$BASEDIR/temp/versions
rm -fr $temp_dir
mkdir -p $temp_dir
# These files need to be bumped...
# a. full/pom2.xml - the first version tag and the version of the platform needs replacing.
# b. full/pom3.xml - only the first version tag needs replacing.
# c. full/pom4.xml - only the first version tag needs replacing.
# d. full/pom5.xml - the first version tag and the version of the platform needs replacing.
# e. full/pom6.xml - only the first version tag needs replacing.
# f. full/pomZip.xml - only the first version tag needs replacing.
# g. full/pomGalasactl.xml
# h. full/resources/run-simplatform.sh - the SIMBANK_VERSION needs replacing.
# i. mvp/pom2.xml - the first version tag and the version of the platform needs replacing.
# j. mvp/pom3.xml - only the first version tag needs replacing.
# k. mvp/pom4.xml - only the first version tag needs replacing.
# l. mvp/pom5.xml - the first version tag and the version of the platform needs replacing.
# m. mvp/pom6.xml - only the first version tag needs replacing.
# n. mvp/pomZip.xml
# o. mvp/pomGalasactl.xml
# p. mvp/resources/run-simplatform.sh - the SIMBANK_VERSION needs replacing.
update_pom_first_version_tag $BASEDIR/full/pom2.xml $temp_dir
update_pom_platform_version_tag $BASEDIR/full/pom2.xml $temp_dir
update_pom_first_version_tag $BASEDIR/full/pom3.xml $temp_dir
update_pom_first_version_tag $BASEDIR/full/pom4.xml $temp_dir
update_pom_first_version_tag $BASEDIR/full/pom5.xml $temp_dir
update_pom_platform_version_tag $BASEDIR/full/pom5.xml $temp_dir
update_pom_first_version_tag $BASEDIR/full/pom6.xml $temp_dir
update_pom_first_version_tag $BASEDIR/full/pomZip.xml $temp_dir
update_pom_first_version_tag $BASEDIR/full/pomGalasactl.xml $temp_dir
update_simbank_version_in_script $BASEDIR/full/resources/run-simplatform.sh $temp_dir
update_pom_first_version_tag $BASEDIR/mvp/pom2.xml $temp_dir
update_pom_platform_version_tag $BASEDIR/mvp/pom2.xml $temp_dir
update_pom_first_version_tag $BASEDIR/mvp/pom3.xml $temp_dir
update_pom_first_version_tag $BASEDIR/mvp/pom4.xml $temp_dir
update_pom_first_version_tag $BASEDIR/mvp/pom5.xml $temp_dir
update_pom_platform_version_tag $BASEDIR/mvp/pom5.xml $temp_dir
update_pom_first_version_tag $BASEDIR/mvp/pom6.xml $temp_dir
update_pom_first_version_tag $BASEDIR/mvp/pomZip.xml $temp_dir
update_pom_first_version_tag $BASEDIR/mvp/pomGalasactl.xml $temp_dir
update_simbank_version_in_script $BASEDIR/mvp/resources/run-simplatform.sh $temp_dir