blob: 0f253f977f9f3447c35e431f02010cd3537dfb4e [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
liamfallond7d9a662022-03-01 21:01:03 +000025SCRIPT_NAME=$(basename "$0")
liamfallon81c2c512021-12-16 12:56:37 +000026repo_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"
liamfallon4d071bf2022-03-16 14:27:21 +000055 echo " -x - update policy/apex-pdp references"
liamfallon81c2c512021-12-16 12:56:37 +000056 echo " -k - update docker base images in Dockerfiles"
57 echo " -s - update release references to snapshot references,"
58 echo " if omitted, snapshot references are updated to release references"
59 echo ""
60 echo " examples:"
61 echo " $SCRIPT_NAME -pcm -r policy/pap"
62 echo " update the parent, common, and models references of policy/pap"
63 echo " to the current released version"
64 echo ""
65 echo " $SCRIPT_NAME -c -m -s -r policy/api"
66 echo " update the common and models references of policy/api"
67 echo " to the current snapshot version"
68 exit 255;
69}
70
71update_parent=false
72update_common=false
73update_models=false
74update_drools_pdp=false
liamfallon4d071bf2022-03-16 14:27:21 +000075update_apex_pdp=false
liamfallon81c2c512021-12-16 12:56:37 +000076update_snapshot=false
77update_docker=false
78
liamfallon4d071bf2022-03-16 14:27:21 +000079while getopts "hd:l:r:pcmoxks" opt
liamfallon81c2c512021-12-16 12:56:37 +000080do
81 case $opt in
82 h)
83 usage
84 ;;
85 d)
86 release_data_file=$OPTARG
87 ;;
88 l)
89 repo_location=$OPTARG
90 ;;
91 r)
92 specified_repo=$OPTARG
93 ;;
94 p)
95 update_parent=true
96 ;;
97 c)
98 update_common=true
99 ;;
100 m)
101 update_models=true
102 ;;
103 o)
104 update_drools_pdp=true
105 ;;
liamfallon4d071bf2022-03-16 14:27:21 +0000106 x)
107 update_apex_pdp=true
108 ;;
liamfallon81c2c512021-12-16 12:56:37 +0000109 k)
110 update_docker=true
111 ;;
112 s)
113 update_snapshot=true
114 ;;
115 \?)
116 usage
117 exit 1
118 ;;
119 esac
120done
121
122if [ $OPTIND -eq 1 ]
123then
124 echo "no arguments were specified"
125 usage
126fi
127
128if [[ -z "$repo_location" ]]
129then
130 echo "policy repo location not specified on -l flag"
131 exit 1
132fi
133
134if ! [ -d "$repo_location" ]
135then
136 echo "policy repo location '$repo_location' not found"
137 exit 1
138fi
139
140if [[ -z "$release_data_file" ]]
141then
142 echo "policy release data file not specified on -d flag"
143 exit 1
144fi
145
146if ! [ -f "$release_data_file" ]
147then
148 echo "policy release data file '$release_data_file' not found"
149 exit 1
150fi
151
152if [ -z "$specified_repo" ]
153then
154 echo "repo not specified on -r flag"
155 exit 1
156fi
157
liamfallond7d9a662022-03-01 21:01:03 +0000158# shellcheck disable=SC2034
159# shellcheck disable=SC2046
160read -r parent_repo \
liamfallon81c2c512021-12-16 12:56:37 +0000161 parent_latest_released_tag \
162 parent_latest_snapshot_tag \
163 parent_changed_files \
164 parent_docker_images \
liamfallond7d9a662022-03-01 21:01:03 +0000165 <<< $(grep policy/parent "$release_data_file" | tr ',' ' ' )
liamfallon81c2c512021-12-16 12:56:37 +0000166
liamfallond7d9a662022-03-01 21:01:03 +0000167# shellcheck disable=SC2034
168# shellcheck disable=SC2046
169read -r common_repo \
liamfallon81c2c512021-12-16 12:56:37 +0000170 common_latest_released_tag \
171 common_latest_snapshot_tag \
172 common_changed_files \
173 common_docker_images \
liamfallond7d9a662022-03-01 21:01:03 +0000174 <<< $(grep policy/common "$release_data_file" | tr ',' ' ' )
liamfallon81c2c512021-12-16 12:56:37 +0000175
liamfallond7d9a662022-03-01 21:01:03 +0000176# shellcheck disable=SC2034
177# shellcheck disable=SC2046
178read -r docker_repo \
liamfallon81c2c512021-12-16 12:56:37 +0000179 docker_latest_released_tag \
180 docker_latest_snapshot_tag \
181 docker_changed_files \
182 docker_docker_images \
liamfallond7d9a662022-03-01 21:01:03 +0000183 <<< $(grep policy/docker "$release_data_file" | tr ',' ' ' )
liamfallon81c2c512021-12-16 12:56:37 +0000184
liamfallond7d9a662022-03-01 21:01:03 +0000185# shellcheck disable=SC2034
186# shellcheck disable=SC2046
187read -r models_repo \
liamfallon81c2c512021-12-16 12:56:37 +0000188 models_latest_released_tag \
189 models_latest_snapshot_tag \
190 models_changed_files \
191 models_docker_images \
liamfallond7d9a662022-03-01 21:01:03 +0000192 <<< $(grep policy/models "$release_data_file" | tr ',' ' ' )
liamfallon81c2c512021-12-16 12:56:37 +0000193
liamfallond7d9a662022-03-01 21:01:03 +0000194# shellcheck disable=SC2034
195# shellcheck disable=SC2046
196read -r drools_pdp_repo \
liamfallon81c2c512021-12-16 12:56:37 +0000197 drools_pdp_latest_released_tag \
198 drools_pdp_latest_snapshot_tag \
199 drools_pdp_changed_files \
200 drools_pdp_docker_images \
liamfallond7d9a662022-03-01 21:01:03 +0000201 <<< $(grep policy/drools-pdp "$release_data_file" | tr ',' ' ' )
liamfallon81c2c512021-12-16 12:56:37 +0000202
liamfallond7d9a662022-03-01 21:01:03 +0000203# shellcheck disable=SC2034
204# shellcheck disable=SC2046
liamfallon4d071bf2022-03-16 14:27:21 +0000205read -r apex_pdp_repo \
206 apex_pdp_latest_released_tag \
207 apex_pdp_latest_snapshot_tag \
208 apex_pdp_changed_files \
209 apex_pdp_docker_images \
210 <<< $(grep policy/apex-pdp "$release_data_file" | tr ',' ' ' )
211
212# shellcheck disable=SC2034
213# shellcheck disable=SC2046
liamfallond7d9a662022-03-01 21:01:03 +0000214read -r target_repo \
liamfallon81c2c512021-12-16 12:56:37 +0000215 target_latest_released_tag \
216 target_latest_snapshot_tag \
217 target_changed_files \
218 target_docker_images \
liamfallond7d9a662022-03-01 21:01:03 +0000219 <<< $(grep "$specified_repo" "$release_data_file" | tr ',' ' ' )
liamfallon81c2c512021-12-16 12:56:37 +0000220
221if [ -z "$target_repo" ]
222then
223 echo "specified repo '$specified_repo' not found in policy release data file '$release_data_file'"
224 exit 1
225fi
226
227if [ ! "$specified_repo" = "$target_repo" ]
228then
229 echo "specified repo '$specified_repo' does not match target repo '$target_repo'"
230 exit 1
231fi
232
233if [ "$update_parent" = true ]
234then
235 if [ "$specified_repo" = "policy/parent" ]
236 then
237 if [ "$update_snapshot" = true ]
238 then
liamfallond7d9a662022-03-01 21:01:03 +0000239 major_version=$(echo "$parent_latest_released_tag" | $SED -E 's/^([0-9]*)\.[0-9]*\.[0-9]*$/\1/')
240 minor_version=$(echo "$parent_latest_released_tag" | $SED -E 's/^[0-9]*\.([0-9]*)\.[0-9]*$/\1/')
241 patch_version=$(echo "$parent_latest_released_tag" | $SED -E 's/^[0-9]*\.[0-9]*\.([0-9]*)$/\1/')
242 new_patch_version=$(("$patch_version"+1))
243
244 new_snapshot_tag="$major_version"."$minor_version"."$new_patch_version"-SNAPSHOT
245
246 echo updating policy parent reference to "$new_snapshot_tag" on "$repo_location/$target_repo" . . .
liamfallonb76315a2022-01-12 13:24:54 +0000247 $SED -i \
liamfallond7d9a662022-03-01 21:01:03 +0000248 "s/<version.parent.resources>.*<\/version.parent.resources>/<version.parent.resources>$new_snapshot_tag<\/version.parent.resources>/" \
249 "$repo_location/policy/parent/integration/pom.xml"
liamfallon81c2c512021-12-16 12:56:37 +0000250 result_code=$?
251 else
252 next_release_version=${parent_latest_snapshot_tag%-*}
253
liamfallond7d9a662022-03-01 21:01:03 +0000254 echo "updating policy parent reference to $next_release_version on $repo_location/$target_repo . . ."
liamfallonb76315a2022-01-12 13:24:54 +0000255 $SED -i \
liamfallon81c2c512021-12-16 12:56:37 +0000256 "s/<version.parent.resources>.*<\/version.parent.resources>/<version.parent.resources>$next_release_version<\/version.parent.resources>/" \
liamfallond7d9a662022-03-01 21:01:03 +0000257 "$repo_location/policy/parent/integration/pom.xml"
liamfallon81c2c512021-12-16 12:56:37 +0000258 result_code=$?
259 fi
260 else
261 if [ "$update_snapshot" = true ]
262 then
liamfallond7d9a662022-03-01 21:01:03 +0000263 echo "updating policy parent reference to $parent_latest_snapshot_tag on $repo_location/$target_repo . . ."
liamfallon81c2c512021-12-16 12:56:37 +0000264 updateParentRef.sh \
liamfallond7d9a662022-03-01 21:01:03 +0000265 -f "$repo_location/$target_repo/pom.xml" \
liamfallon81c2c512021-12-16 12:56:37 +0000266 -g org.onap.policy.parent \
267 -a integration \
liamfallond7d9a662022-03-01 21:01:03 +0000268 -v "$parent_latest_snapshot_tag"
liamfallon81c2c512021-12-16 12:56:37 +0000269 result_code=$?
270 else
liamfallond7d9a662022-03-01 21:01:03 +0000271 echo "updating policy parent reference to $parent_latest_released_tag on $repo_location/$target_repo . . ."
liamfallon81c2c512021-12-16 12:56:37 +0000272 updateParentRef.sh \
liamfallond7d9a662022-03-01 21:01:03 +0000273 -f "$repo_location/$target_repo/pom.xml" \
liamfallon81c2c512021-12-16 12:56:37 +0000274 -g org.onap.policy.parent \
275 -a integration \
liamfallond7d9a662022-03-01 21:01:03 +0000276 -v "$parent_latest_released_tag"
liamfallon81c2c512021-12-16 12:56:37 +0000277 result_code=$?
278 fi
279 fi
280 if [[ "$result_code" -eq 0 ]]
281 then
liamfallond7d9a662022-03-01 21:01:03 +0000282 echo "policy parent reference updated on $repo_location/$target_repo"
liamfallon81c2c512021-12-16 12:56:37 +0000283 else
liamfallond7d9a662022-03-01 21:01:03 +0000284 echo "policy parent reference update failed on $repo_location/$target_repo"
liamfallon81c2c512021-12-16 12:56:37 +0000285 exit 1
286 fi
287fi
288
289if [ "$update_common" = true ]
290then
291 if [ "$update_snapshot" = true ]
292 then
liamfallond7d9a662022-03-01 21:01:03 +0000293 echo "updating policy common reference to $common_latest_snapshot_tag on $repo_location/$target_repo . . ."
liamfallonb76315a2022-01-12 13:24:54 +0000294 $SED -i \
liamfallon81c2c512021-12-16 12:56:37 +0000295 -e "s/<policy.common.version>.*<\/policy.common.version>/<policy.common.version>$common_latest_snapshot_tag<\/policy.common.version>/" \
296 -e "s/<version.policy.common>.*<\/version.policy.common>/<version.policy.common>$common_latest_snapshot_tag<\/version.policy.common>/" \
liamfallond7d9a662022-03-01 21:01:03 +0000297 "$repo_location/$target_repo/pom.xml"
liamfallon81c2c512021-12-16 12:56:37 +0000298 result_code=$?
299 else
liamfallond7d9a662022-03-01 21:01:03 +0000300 echo "updating policy common reference to $common_latest_released_tag on $repo_location/$target_repo . . ."
liamfallonb76315a2022-01-12 13:24:54 +0000301 $SED -i \
liamfallon81c2c512021-12-16 12:56:37 +0000302 -e "s/<policy.common.version>.*<\/policy.common.version>/<policy.common.version>$common_latest_released_tag<\/policy.common.version>/" \
303 -e "s/<version.policy.common>.*<\/version.policy.common>/<version.policy.common>$common_latest_released_tag<\/version.policy.common>/" \
liamfallond7d9a662022-03-01 21:01:03 +0000304 "$repo_location/$target_repo/pom.xml"
liamfallon81c2c512021-12-16 12:56:37 +0000305 result_code=$?
306 fi
307 if [[ "$result_code" -eq 0 ]]
308 then
liamfallond7d9a662022-03-01 21:01:03 +0000309 echo "policy common reference updated on $repo_location/$target_repo"
liamfallon81c2c512021-12-16 12:56:37 +0000310 else
liamfallond7d9a662022-03-01 21:01:03 +0000311 echo "policy common reference update failed on $repo_location/$target_repo"
liamfallon81c2c512021-12-16 12:56:37 +0000312 exit 1
313 fi
314fi
315
316if [ "$update_models" = true ]
317then
318 if [ "$update_snapshot" = true ]
319 then
liamfallond7d9a662022-03-01 21:01:03 +0000320 echo "updating policy models reference to $models_latest_snapshot_tag on $repo_location/$target_repo . . ."
liamfallonb76315a2022-01-12 13:24:54 +0000321 $SED -i \
liamfallon81c2c512021-12-16 12:56:37 +0000322 -e "s/<policy.models.version>.*<\/policy.models.version>/<policy.models.version>$models_latest_snapshot_tag<\/policy.models.version>/" \
323 -e "s/<version.policy.models>.*<\/version.policy.models>/<version.policy.models>$models_latest_snapshot_tag<\/version.policy.models>/" \
liamfallond7d9a662022-03-01 21:01:03 +0000324 "$repo_location/$target_repo/pom.xml"
liamfallon81c2c512021-12-16 12:56:37 +0000325 result_code=$?
326 else
liamfallond7d9a662022-03-01 21:01:03 +0000327 echo "updating policy models reference to $models_latest_released_tag on $repo_location/$target_repo . . ."
liamfallonb76315a2022-01-12 13:24:54 +0000328 $SED -i \
liamfallon81c2c512021-12-16 12:56:37 +0000329 -e "s/<policy.models.version>.*<\/policy.models.version>/<policy.models.version>$models_latest_released_tag<\/policy.models.version>/" \
330 -e "s/<version.policy.models>.*<\/version.policy.models>/<version.policy.models>$models_latest_released_tag<\/version.policy.models>/" \
liamfallond7d9a662022-03-01 21:01:03 +0000331 "$repo_location/$target_repo/pom.xml"
liamfallon81c2c512021-12-16 12:56:37 +0000332 result_code=$?
333 fi
334 if [[ "$result_code" -eq 0 ]]
335 then
liamfallond7d9a662022-03-01 21:01:03 +0000336 echo "policy models reference updated on $repo_location/$target_repo"
liamfallon81c2c512021-12-16 12:56:37 +0000337 else
liamfallond7d9a662022-03-01 21:01:03 +0000338 echo "policy models reference update failed on $repo_location/$target_repo"
liamfallon81c2c512021-12-16 12:56:37 +0000339 exit 1
340 fi
341fi
342
343if [ "$update_drools_pdp" = true ]
344then
345 if [ "$update_snapshot" = true ]
346 then
liamfallond7d9a662022-03-01 21:01:03 +0000347 echo "updating policy drools-pdp reference to $drools_pdp_latest_snapshot_tag on $repo_location/$target_repo . . ."
liamfallonb76315a2022-01-12 13:24:54 +0000348 $SED -i \
liamfallon81c2c512021-12-16 12:56:37 +0000349 -e "s/<policy.drools-pdp.version>.*<\/policy.drools-pdp.version>/<policy.drools-pdp.version>$drools_pdp_latest_snapshot_tag<\/policy.drools-pdp.version>/" \
350 -e "s/<version.policy.drools-pdp>.*<\/version.policy.drools-pdp>/<version.policy.drools-pdp>$drools_pdp_latest_snapshot_tag<\/version.policy.drools-pdp>/" \
liamfallond7d9a662022-03-01 21:01:03 +0000351 "$repo_location/$target_repo/pom.xml"
liamfallon81c2c512021-12-16 12:56:37 +0000352 result_code=$?
353 else
liamfallond7d9a662022-03-01 21:01:03 +0000354 echo "updating policy drools-pdp reference to $drools_pdp_latest_released_tag on $repo_location/$target_repo . . ."
liamfallonb76315a2022-01-12 13:24:54 +0000355 $SED -i \
liamfallon81c2c512021-12-16 12:56:37 +0000356 -e "s/<policy.drools-pdp.version>.*<\/policy.drools-pdp.version>/<policy.drools-pdp.version>$drools_pdp_latest_released_tag<\/policy.drools-pdp.version>/" \
357 -e "s/<version.policy.drools-pdp>.*<\/version.policy.drools-pdp>/<version.policy.drools-pdp>$drools_pdp_latest_released_tag<\/version.policy.drools-pdp>/" \
liamfallond7d9a662022-03-01 21:01:03 +0000358 "$repo_location/$target_repo/pom.xml"
liamfallon81c2c512021-12-16 12:56:37 +0000359 result_code=$?
360 fi
361 if [[ "$result_code" -eq 0 ]]
362 then
liamfallond7d9a662022-03-01 21:01:03 +0000363 echo "policy drools-pdp reference updated on $repo_location/$target_repo"
liamfallon81c2c512021-12-16 12:56:37 +0000364 else
liamfallond7d9a662022-03-01 21:01:03 +0000365 echo "policy drools-pdp reference update failed on $repo_location/$target_repo"
liamfallon81c2c512021-12-16 12:56:37 +0000366 exit 1
367 fi
368fi
369
liamfallon4d071bf2022-03-16 14:27:21 +0000370if [ "$update_apex_pdp" = true ]
371then
372 if [ "$update_snapshot" = true ]
373 then
374 echo "updating policy apex-pdp reference to $apex_pdp_latest_snapshot_tag on $repo_location/$target_repo . . ."
375 $SED -i \
376 -e "s/<policy.apex-pdp.version>.*<\/policy.apex-pdp.version>/<policy.apex-pdp.version>$apex_pdp_latest_snapshot_tag<\/policy.apex-pdp.version>/" \
377 -e "s/<version.policy.apex-pdp>.*<\/version.policy.apex-pdp>/<version.policy.apex-pdp>$apex_pdp_latest_snapshot_tag<\/version.policy.apex-pdp>/" \
378 "$repo_location/$target_repo/pom.xml"
379 result_code=$?
380 else
381 echo "updating policy apex-pdp reference to $apex_pdp_latest_released_tag on $repo_location/$target_repo . . ."
382 $SED -i \
383 -e "s/<policy.apex-pdp.version>.*<\/policy.apex-pdp.version>/<policy.apex-pdp.version>$apex_pdp_latest_released_tag<\/policy.apex-pdp.version>/" \
384 -e "s/<version.policy.apex-pdp>.*<\/version.policy.apex-pdp>/<version.policy.apex-pdp>$apex_pdp_latest_released_tag<\/version.policy.apex-pdp>/" \
385 "$repo_location/$target_repo/pom.xml"
386 result_code=$?
387 fi
388 if [[ "$result_code" -eq 0 ]]
389 then
390 echo "policy apex-pdp reference updated on $repo_location/$target_repo"
391 else
392 echo "policy apex-pdp reference update failed on $repo_location/$target_repo"
393 exit 1
394 fi
395fi
396
liamfallon81c2c512021-12-16 12:56:37 +0000397if [ "$update_docker" = true ] && [ "$target_docker_images" != "" ]
398then
liamfallond7d9a662022-03-01 21:01:03 +0000399 echo "updating docker base images to version $docker_latest_released_tag on repo $repo_location/$target_repo . . ."
400 find "$repo_location/$target_repo" \
liamfallon4d071bf2022-03-16 14:27:21 +0000401 -name '*Docker*'
402 find "$repo_location/$target_repo" \
liamfallon81c2c512021-12-16 12:56:37 +0000403 -name '*Docker*' \
liamfallon4d071bf2022-03-16 14:27:21 +0000404 -exec $SED -r -i "s/^(FROM onap\/policy-j[d|r][k|e]-alpine:)[0-9]*.[0-9]*.[0-9]*$/\1$docker_latest_released_tag/" {} \;
liamfallon81c2c512021-12-16 12:56:37 +0000405 result_code=$?
406 if [[ "$result_code" -eq 0 ]]
407 then
liamfallond7d9a662022-03-01 21:01:03 +0000408 echo "docker base images updated on $repo_location/$target_repo"
liamfallon81c2c512021-12-16 12:56:37 +0000409 else
liamfallond7d9a662022-03-01 21:01:03 +0000410 echo "docker base images update failed on $repo_location/$target_repo"
liamfallon81c2c512021-12-16 12:56:37 +0000411 exit 1
412 fi
413fi