blob: ea67748734c74c3970f0f4e61e2f80c377a8e011 [file] [log] [blame]
liamfallon81c2c512021-12-16 12:56:37 +00001#!/bin/bash
2
3#
4# ============LICENSE_START================================================
5# ONAP
6# =========================================================================
7# Copyright (C) 2021-2022 Nordix Foundation.
8# =========================================================================
9# Licensed under the Apache License, Version 2.0 (the "License");
10# you may not use this file except in compliance with the License.
11# You may obtain a copy of the License at
12#
13# http://www.apache.org/licenses/LICENSE-2.0
14#
15# Unless required by applicable law or agreed to in writing, software
16# distributed under the License is distributed on an "AS IS" BASIS,
17# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18# See the License for the specific language governing permissions and
19# limitations under the License.
20# ============LICENSE_END==================================================
21#
22
23set -e
24
25SCRIPT_NAME=`basename $0`
26repo_location="./"
27release_data_file="./pf_release_data.csv"
28
liamfallonb76315a2022-01-12 13:24:54 +000029# Use the bash internal OSTYPE variable to check for MacOS
30if [[ "$OSTYPE" == "darwin"* ]]
31then
32 SED="gsed"
33else
34 SED="sed"
35fi
36
liamfallon81c2c512021-12-16 12:56:37 +000037usage()
38{
39 echo ""
40 echo "$SCRIPT_NAME - updates the inter-repo references in Policy Framework POM files"
41 echo ""
42 echo " usage: $SCRIPT_NAME [-options]"
43 echo ""
44 echo " options"
45 echo " -h - this help message"
46 echo " -d data_file - the policy release data file to use, generated by the 'getReleaseData.sh' script,"
47 echo " defaults to '$release_data_file'"
48 echo " -l location - the location of the policy framework repos on the file system,"
49 echo " defaults to '$repo_location'"
50 echo " -r repo - the policy repo to update"
51 echo " -p - update policy/parent references"
52 echo " -c - update policy/common references"
53 echo " -m - update policy/model references"
54 echo " -o - update policy/drools-pdp references"
55 echo " -k - update docker base images in Dockerfiles"
56 echo " -s - update release references to snapshot references,"
57 echo " if omitted, snapshot references are updated to release references"
58 echo ""
59 echo " examples:"
60 echo " $SCRIPT_NAME -pcm -r policy/pap"
61 echo " update the parent, common, and models references of policy/pap"
62 echo " to the current released version"
63 echo ""
64 echo " $SCRIPT_NAME -c -m -s -r policy/api"
65 echo " update the common and models references of policy/api"
66 echo " to the current snapshot version"
67 exit 255;
68}
69
70update_parent=false
71update_common=false
72update_models=false
73update_drools_pdp=false
74update_snapshot=false
75update_docker=false
76
77while getopts "hd:l:r:pcmoks" opt
78do
79 case $opt in
80 h)
81 usage
82 ;;
83 d)
84 release_data_file=$OPTARG
85 ;;
86 l)
87 repo_location=$OPTARG
88 ;;
89 r)
90 specified_repo=$OPTARG
91 ;;
92 p)
93 update_parent=true
94 ;;
95 c)
96 update_common=true
97 ;;
98 m)
99 update_models=true
100 ;;
101 o)
102 update_drools_pdp=true
103 ;;
104 k)
105 update_docker=true
106 ;;
107 s)
108 update_snapshot=true
109 ;;
110 \?)
111 usage
112 exit 1
113 ;;
114 esac
115done
116
117if [ $OPTIND -eq 1 ]
118then
119 echo "no arguments were specified"
120 usage
121fi
122
123if [[ -z "$repo_location" ]]
124then
125 echo "policy repo location not specified on -l flag"
126 exit 1
127fi
128
129if ! [ -d "$repo_location" ]
130then
131 echo "policy repo location '$repo_location' not found"
132 exit 1
133fi
134
135if [[ -z "$release_data_file" ]]
136then
137 echo "policy release data file not specified on -d flag"
138 exit 1
139fi
140
141if ! [ -f "$release_data_file" ]
142then
143 echo "policy release data file '$release_data_file' not found"
144 exit 1
145fi
146
147if [ -z "$specified_repo" ]
148then
149 echo "repo not specified on -r flag"
150 exit 1
151fi
152
153read parent_repo \
154 parent_latest_released_tag \
155 parent_latest_snapshot_tag \
156 parent_changed_files \
157 parent_docker_images \
158 <<< $( grep policy/parent $release_data_file | tr ',' ' ' )
159
160read common_repo \
161 common_latest_released_tag \
162 common_latest_snapshot_tag \
163 common_changed_files \
164 common_docker_images \
165 <<< $( grep policy/common $release_data_file | tr ',' ' ' )
166
167read docker_repo \
168 docker_latest_released_tag \
169 docker_latest_snapshot_tag \
170 docker_changed_files \
171 docker_docker_images \
172 <<< $( grep policy/docker $release_data_file | tr ',' ' ' )
173
174read models_repo \
175 models_latest_released_tag \
176 models_latest_snapshot_tag \
177 models_changed_files \
178 models_docker_images \
179 <<< $( grep policy/models $release_data_file | tr ',' ' ' )
180
181read drools_pdp_repo \
182 drools_pdp_latest_released_tag \
183 drools_pdp_latest_snapshot_tag \
184 drools_pdp_changed_files \
185 drools_pdp_docker_images \
186 <<< $( grep policy/drools-pdp $release_data_file | tr ',' ' ' )
187
188read target_repo \
189 target_latest_released_tag \
190 target_latest_snapshot_tag \
191 target_changed_files \
192 target_docker_images \
193 <<< $( grep $specified_repo $release_data_file | tr ',' ' ' )
194
195if [ -z "$target_repo" ]
196then
197 echo "specified repo '$specified_repo' not found in policy release data file '$release_data_file'"
198 exit 1
199fi
200
201if [ ! "$specified_repo" = "$target_repo" ]
202then
203 echo "specified repo '$specified_repo' does not match target repo '$target_repo'"
204 exit 1
205fi
206
207if [ "$update_parent" = true ]
208then
209 if [ "$specified_repo" = "policy/parent" ]
210 then
211 if [ "$update_snapshot" = true ]
212 then
213 echo updating policy parent reference to $parent_latest_snapshot_tag on $repo_location/$target_repo . . .
liamfallonb76315a2022-01-12 13:24:54 +0000214 $SED -i \
liamfallon81c2c512021-12-16 12:56:37 +0000215 "s/<version.parent.resources>.*<\/version.parent.resources>/<version.parent.resources>$parent_latest_snapshot_tag<\/version.parent.resources>/" \
216 $repo_location/policy/parent/integration/pom.xml
217 result_code=$?
218 else
219 next_release_version=${parent_latest_snapshot_tag%-*}
220
221 echo updating policy parent reference to $next_release_version on $repo_location/$target_repo . . .
liamfallonb76315a2022-01-12 13:24:54 +0000222 $SED -i \
liamfallon81c2c512021-12-16 12:56:37 +0000223 "s/<version.parent.resources>.*<\/version.parent.resources>/<version.parent.resources>$next_release_version<\/version.parent.resources>/" \
liamfallonb76315a2022-01-12 13:24:54 +0000224 $repo_location/policy/parent/integration/pom.xml
liamfallon81c2c512021-12-16 12:56:37 +0000225 result_code=$?
226 fi
227 else
228 if [ "$update_snapshot" = true ]
229 then
230 echo updating policy parent reference to $parent_latest_snapshot_tag on $repo_location/$target_repo . . .
231 updateParentRef.sh \
232 -f $repo_location/$target_repo/pom.xml \
233 -g org.onap.policy.parent \
234 -a integration \
235 -v $parent_latest_snapshot_tag
236 result_code=$?
237 else
238 echo updating policy parent reference to $parent_latest_released_tag on $repo_location/$target_repo . . .
239 updateParentRef.sh \
240 -f $repo_location/$target_repo/pom.xml \
241 -g org.onap.policy.parent \
242 -a integration \
243 -v $parent_latest_released_tag
244 result_code=$?
245 fi
246 fi
247 if [[ "$result_code" -eq 0 ]]
248 then
249 echo policy parent reference updated on $repo_location/$target_repo
250 else
251 echo policy parent reference update failed on $repo_location/$target_repo
252 exit 1
253 fi
254fi
255
256if [ "$update_common" = true ]
257then
258 if [ "$update_snapshot" = true ]
259 then
260 echo updating policy common reference to $common_latest_snapshot_tag on $repo_location/$target_repo . . .
liamfallonb76315a2022-01-12 13:24:54 +0000261 $SED -i \
liamfallon81c2c512021-12-16 12:56:37 +0000262 -e "s/<policy.common.version>.*<\/policy.common.version>/<policy.common.version>$common_latest_snapshot_tag<\/policy.common.version>/" \
263 -e "s/<version.policy.common>.*<\/version.policy.common>/<version.policy.common>$common_latest_snapshot_tag<\/version.policy.common>/" \
264 $repo_location/$target_repo/pom.xml
265 result_code=$?
266 else
267 echo updating policy common reference to $common_latest_released_tag on $repo_location/$target_repo . . .
liamfallonb76315a2022-01-12 13:24:54 +0000268 $SED -i \
liamfallon81c2c512021-12-16 12:56:37 +0000269 -e "s/<policy.common.version>.*<\/policy.common.version>/<policy.common.version>$common_latest_released_tag<\/policy.common.version>/" \
270 -e "s/<version.policy.common>.*<\/version.policy.common>/<version.policy.common>$common_latest_released_tag<\/version.policy.common>/" \
271 $repo_location/$target_repo/pom.xml
272 result_code=$?
273 fi
274 if [[ "$result_code" -eq 0 ]]
275 then
276 echo policy common reference updated on $repo_location/$target_repo
277 else
278 echo policy common reference update failed on $repo_location/$target_repo
279 exit 1
280 fi
281fi
282
283if [ "$update_models" = true ]
284then
285 if [ "$update_snapshot" = true ]
286 then
287 echo updating policy models reference to $models_latest_snapshot_tag on $repo_location/$target_repo . . .
liamfallonb76315a2022-01-12 13:24:54 +0000288 $SED -i \
liamfallon81c2c512021-12-16 12:56:37 +0000289 -e "s/<policy.models.version>.*<\/policy.models.version>/<policy.models.version>$models_latest_snapshot_tag<\/policy.models.version>/" \
290 -e "s/<version.policy.models>.*<\/version.policy.models>/<version.policy.models>$models_latest_snapshot_tag<\/version.policy.models>/" \
291 $repo_location/$target_repo/pom.xml
292 result_code=$?
293 else
294 echo updating policy models reference to $models_latest_released_tag on $repo_location/$target_repo . . .
liamfallonb76315a2022-01-12 13:24:54 +0000295 $SED -i \
liamfallon81c2c512021-12-16 12:56:37 +0000296 -e "s/<policy.models.version>.*<\/policy.models.version>/<policy.models.version>$models_latest_released_tag<\/policy.models.version>/" \
297 -e "s/<version.policy.models>.*<\/version.policy.models>/<version.policy.models>$models_latest_released_tag<\/version.policy.models>/" \
298 $repo_location/$target_repo/pom.xml
299 result_code=$?
300 fi
301 if [[ "$result_code" -eq 0 ]]
302 then
303 echo policy models reference updated on $repo_location/$target_repo
304 else
305 echo policy models reference update failed on $repo_location/$target_repo
306 exit 1
307 fi
308fi
309
310if [ "$update_drools_pdp" = true ]
311then
312 if [ "$update_snapshot" = true ]
313 then
314 echo updating policy drools-pdp reference to $drools_pdp_latest_snapshot_tag on $repo_location/$target_repo . . .
liamfallonb76315a2022-01-12 13:24:54 +0000315 $SED -i \
liamfallon81c2c512021-12-16 12:56:37 +0000316 -e "s/<policy.drools-pdp.version>.*<\/policy.drools-pdp.version>/<policy.drools-pdp.version>$drools_pdp_latest_snapshot_tag<\/policy.drools-pdp.version>/" \
317 -e "s/<version.policy.drools-pdp>.*<\/version.policy.drools-pdp>/<version.policy.drools-pdp>$drools_pdp_latest_snapshot_tag<\/version.policy.drools-pdp>/" \
318 $repo_location/$target_repo/pom.xml
319 result_code=$?
320 else
321 echo updating policy drools-pdp reference to $drools_pdp_latest_released_tag on $repo_location/$target_repo . . .
liamfallonb76315a2022-01-12 13:24:54 +0000322 $SED -i \
liamfallon81c2c512021-12-16 12:56:37 +0000323 -e "s/<policy.drools-pdp.version>.*<\/policy.drools-pdp.version>/<policy.drools-pdp.version>$drools_pdp_latest_released_tag<\/policy.drools-pdp.version>/" \
324 -e "s/<version.policy.drools-pdp>.*<\/version.policy.drools-pdp>/<version.policy.drools-pdp>$drools_pdp_latest_released_tag<\/version.policy.drools-pdp>/" \
325 $repo_location/$target_repo/pom.xml
326 result_code=$?
327 fi
328 if [[ "$result_code" -eq 0 ]]
329 then
330 echo policy drools-pdp reference updated on $repo_location/$target_repo
331 else
332 echo policy drools-pdp reference update failed on $repo_location/$target_repo
333 exit 1
334 fi
335fi
336
337if [ "$update_docker" = true ] && [ "$target_docker_images" != "" ]
338then
339 echo updating docker base images to version $docker_latest_released_tag on repo $repo_location/$target_repo
340 find $repo_location/$target_repo \
341 -name '*Docker*' \
liamfallonb76315a2022-01-12 13:24:54 +0000342 -exec $SED -r -i "s/^(FROM onap\/policy-j[d|r][k|e]-alpine:)2.3.1$/\1$docker_latest_released_tag/" {} \;
liamfallon81c2c512021-12-16 12:56:37 +0000343 result_code=$?
344 if [[ "$result_code" -eq 0 ]]
345 then
346 echo docker base images updated on $repo_location/$target_repo
347 else
348 echo docker base images update failed on $repo_location/$target_repo
349 exit 1
350 fi
351fi