4 # ============LICENSE_START================================================
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
13 # http://www.apache.org/licenses/LICENSE-2.0
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==================================================
25 SCRIPT_NAME=$(basename "$0")
27 release_data_file="pf_release_data.csv"
28 release_data_file_tag=""
30 # Use the bash internal OSTYPE variable to check for MacOS
31 if [[ "$OSTYPE" == "darwin"* ]]
41 echo "$SCRIPT_NAME - updates the inter-repo references in Policy Framework POM files"
43 echo " usage: $SCRIPT_NAME [-options]"
46 echo " -h - this help message"
47 echo " -d data_file - the policy release data file to use, generated by the 'getReleaseData.sh' script,"
48 echo " defaults to '$release_data_file'"
49 echo " -l location - the location of the policy framework repos on the file system,"
50 echo " defaults to '$repo_location'"
51 echo " -r repo - the policy repo to update"
52 echo " -p - update policy/parent references"
53 echo " -c - update policy/common references"
54 echo " -m - update policy/model references"
55 echo " -o - update policy/drools-pdp references"
56 echo " -x - update policy/apex-pdp references"
57 echo " -k - update docker base images in Dockerfiles"
58 echo " -t tag - update release data in policy parent and"
59 echo " tag the release data file with the given tag"
60 echo " -s - update release references to snapshot references,"
61 echo " if omitted, snapshot references are updated to release references"
64 echo " $SCRIPT_NAME -pcm -r policy/pap"
65 echo " update the parent, common, and models references of policy/pap"
66 echo " to the current released version"
68 echo " $SCRIPT_NAME -c -m -s -r policy/api"
69 echo " update the common and models references of policy/api"
70 echo " to the current snapshot version"
77 update_drools_pdp=false
81 update_release_file=false
83 while getopts "hd:l:r:pcmoxkt:s" opt
90 release_data_file=$OPTARG
96 specified_repo=$OPTARG
108 update_drools_pdp=true
117 update_release_file=true
118 release_data_file_tag="$OPTARG"
132 echo "no arguments were specified"
136 if [[ -z "$repo_location" ]]
138 echo "policy repo location not specified on -l flag"
142 if ! [ -d "$repo_location" ]
144 echo "policy repo location '$repo_location' not found"
148 if [[ -z "$release_data_file" ]]
150 echo "policy release data file not specified on -d flag"
154 if ! [ -f "$release_data_file" ]
156 echo "policy release data file '$release_data_file' not found"
160 if [ -z "$specified_repo" ]
162 echo "repo not specified on -r flag"
166 if [ "$update_release_file" = true ] && [ -z "$release_data_file_tag" ]
168 echo "tag not specified on -t flag"
172 # shellcheck disable=SC2034
173 # shellcheck disable=SC2046
174 read -r parent_repo \
175 parent_latest_released_tag \
176 parent_latest_snapshot_tag \
177 parent_changed_files \
178 parent_docker_images \
179 <<< $(grep policy/parent "$release_data_file" | tr ',' ' ' )
181 # shellcheck disable=SC2034
182 # shellcheck disable=SC2046
183 read -r common_repo \
184 common_latest_released_tag \
185 common_latest_snapshot_tag \
186 common_changed_files \
187 common_docker_images \
188 <<< $(grep policy/common "$release_data_file" | tr ',' ' ' )
190 # shellcheck disable=SC2034
191 # shellcheck disable=SC2046
192 read -r docker_repo \
193 docker_latest_released_tag \
194 docker_latest_snapshot_tag \
195 docker_changed_files \
196 docker_docker_images \
197 <<< $(grep policy/docker "$release_data_file" | tr ',' ' ' )
199 # shellcheck disable=SC2034
200 # shellcheck disable=SC2046
201 read -r models_repo \
202 models_latest_released_tag \
203 models_latest_snapshot_tag \
204 models_changed_files \
205 models_docker_images \
206 <<< $(grep policy/models "$release_data_file" | tr ',' ' ' )
208 # shellcheck disable=SC2034
209 # shellcheck disable=SC2046
210 read -r drools_pdp_repo \
211 drools_pdp_latest_released_tag \
212 drools_pdp_latest_snapshot_tag \
213 drools_pdp_changed_files \
214 drools_pdp_docker_images \
215 <<< $(grep policy/drools-pdp "$release_data_file" | tr ',' ' ' )
217 # shellcheck disable=SC2034
218 # shellcheck disable=SC2046
219 read -r apex_pdp_repo \
220 apex_pdp_latest_released_tag \
221 apex_pdp_latest_snapshot_tag \
222 apex_pdp_changed_files \
223 apex_pdp_docker_images \
224 <<< $(grep policy/apex-pdp "$release_data_file" | tr ',' ' ' )
226 # shellcheck disable=SC2034
227 # shellcheck disable=SC2046
228 read -r target_repo \
229 target_latest_released_tag \
230 target_latest_snapshot_tag \
231 target_changed_files \
232 target_docker_images \
233 <<< $(grep "$specified_repo" "$release_data_file" | tr ',' ' ' )
235 if [ -z "$target_repo" ]
237 echo "specified repo '$specified_repo' not found in policy release data file '$release_data_file'"
241 if [ ! "$specified_repo" = "$target_repo" ]
243 echo "specified repo '$specified_repo' does not match target repo '$target_repo'"
247 if [ "$update_parent" = true ]
249 if [ "$specified_repo" = "policy/parent" ]
251 if [ "$update_snapshot" = true ]
253 major_version=$(echo "$parent_latest_released_tag" | $SED -E 's/^([0-9]*)\.[0-9]*\.[0-9]*$/\1/')
254 minor_version=$(echo "$parent_latest_released_tag" | $SED -E 's/^[0-9]*\.([0-9]*)\.[0-9]*$/\1/')
255 patch_version=$(echo "$parent_latest_released_tag" | $SED -E 's/^[0-9]*\.[0-9]*\.([0-9]*)$/\1/')
257 new_patch_version=$((patch_version+1))
258 new_snapshot_tag="$major_version"."$minor_version"."$new_patch_version"-SNAPSHOT
260 echo updating policy parent reference to "$new_snapshot_tag" on "$repo_location/$target_repo" . . .
262 "s/<version.parent.resources>.*<\/version.parent.resources>/<version.parent.resources>$new_snapshot_tag<\/version.parent.resources>/" \
263 "$repo_location/policy/parent/integration/pom.xml"
266 next_release_version=${parent_latest_snapshot_tag%-*}
268 echo "updating policy parent reference to $next_release_version on $repo_location/$target_repo . . ."
270 "s/<version.parent.resources>.*<\/version.parent.resources>/<version.parent.resources>$next_release_version<\/version.parent.resources>/" \
271 "$repo_location/policy/parent/integration/pom.xml"
275 if [ "$update_snapshot" = true ]
277 echo "updating policy parent reference to $parent_latest_snapshot_tag on $repo_location/$target_repo . . ."
279 -f "$repo_location/$target_repo/pom.xml" \
280 -g org.onap.policy.parent \
282 -v "$parent_latest_snapshot_tag"
285 echo "updating policy parent reference to $parent_latest_released_tag on $repo_location/$target_repo . . ."
287 -f "$repo_location/$target_repo/pom.xml" \
288 -g org.onap.policy.parent \
290 -v "$parent_latest_released_tag"
294 if [[ "$result_code" -eq 0 ]]
296 echo "policy parent reference updated on $repo_location/$target_repo"
298 echo "policy parent reference update failed on $repo_location/$target_repo"
303 if [ "$update_common" = true ]
305 if [ "$update_snapshot" = true ]
307 echo "updating policy common reference to $common_latest_snapshot_tag on $repo_location/$target_repo . . ."
309 -e "s/<policy.common.version>.*<\/policy.common.version>/<policy.common.version>$common_latest_snapshot_tag<\/policy.common.version>/" \
310 -e "s/<version.policy.common>.*<\/version.policy.common>/<version.policy.common>$common_latest_snapshot_tag<\/version.policy.common>/" \
311 "$repo_location/$target_repo/pom.xml"
314 echo "updating policy common reference to $common_latest_released_tag on $repo_location/$target_repo . . ."
316 -e "s/<policy.common.version>.*<\/policy.common.version>/<policy.common.version>$common_latest_released_tag<\/policy.common.version>/" \
317 -e "s/<version.policy.common>.*<\/version.policy.common>/<version.policy.common>$common_latest_released_tag<\/version.policy.common>/" \
318 "$repo_location/$target_repo/pom.xml"
321 if [[ "$result_code" -eq 0 ]]
323 echo "policy common reference updated on $repo_location/$target_repo"
325 echo "policy common reference update failed on $repo_location/$target_repo"
330 if [ "$update_models" = true ]
332 if [ "$update_snapshot" = true ]
334 echo "updating policy models reference to $models_latest_snapshot_tag on $repo_location/$target_repo . . ."
336 -e "s/<policy.models.version>.*<\/policy.models.version>/<policy.models.version>$models_latest_snapshot_tag<\/policy.models.version>/" \
337 -e "s/<version.policy.models>.*<\/version.policy.models>/<version.policy.models>$models_latest_snapshot_tag<\/version.policy.models>/" \
338 "$repo_location/$target_repo/pom.xml"
341 echo "updating policy models reference to $models_latest_released_tag on $repo_location/$target_repo . . ."
343 -e "s/<policy.models.version>.*<\/policy.models.version>/<policy.models.version>$models_latest_released_tag<\/policy.models.version>/" \
344 -e "s/<version.policy.models>.*<\/version.policy.models>/<version.policy.models>$models_latest_released_tag<\/version.policy.models>/" \
345 "$repo_location/$target_repo/pom.xml"
348 if [[ "$result_code" -eq 0 ]]
350 echo "policy models reference updated on $repo_location/$target_repo"
352 echo "policy models reference update failed on $repo_location/$target_repo"
357 if [ "$update_drools_pdp" = true ]
359 if [ "$update_snapshot" = true ]
361 echo "updating policy drools-pdp reference to $drools_pdp_latest_snapshot_tag on $repo_location/$target_repo . . ."
363 -e "s/<policy.drools-pdp.version>.*<\/policy.drools-pdp.version>/<policy.drools-pdp.version>$drools_pdp_latest_snapshot_tag<\/policy.drools-pdp.version>/" \
364 -e "s/<version.policy.drools-pdp>.*<\/version.policy.drools-pdp>/<version.policy.drools-pdp>$drools_pdp_latest_snapshot_tag<\/version.policy.drools-pdp>/" \
365 "$repo_location/$target_repo/pom.xml"
368 echo "updating policy drools-pdp reference to $drools_pdp_latest_released_tag on $repo_location/$target_repo . . ."
370 -e "s/<policy.drools-pdp.version>.*<\/policy.drools-pdp.version>/<policy.drools-pdp.version>$drools_pdp_latest_released_tag<\/policy.drools-pdp.version>/" \
371 -e "s/<version.policy.drools-pdp>.*<\/version.policy.drools-pdp>/<version.policy.drools-pdp>$drools_pdp_latest_released_tag<\/version.policy.drools-pdp>/" \
372 "$repo_location/$target_repo/pom.xml"
375 if [[ "$result_code" -eq 0 ]]
377 echo "policy drools-pdp reference updated on $repo_location/$target_repo"
379 echo "policy drools-pdp reference update failed on $repo_location/$target_repo"
384 if [ "$update_apex_pdp" = true ]
386 if [ "$update_snapshot" = true ]
388 echo "updating policy apex-pdp reference to $apex_pdp_latest_snapshot_tag on $repo_location/$target_repo . . ."
390 -e "s/<policy.apex-pdp.version>.*<\/policy.apex-pdp.version>/<policy.apex-pdp.version>$apex_pdp_latest_snapshot_tag<\/policy.apex-pdp.version>/" \
391 -e "s/<version.policy.apex-pdp>.*<\/version.policy.apex-pdp>/<version.policy.apex-pdp>$apex_pdp_latest_snapshot_tag<\/version.policy.apex-pdp>/" \
392 "$repo_location/$target_repo/pom.xml"
395 echo "updating policy apex-pdp reference to $apex_pdp_latest_released_tag on $repo_location/$target_repo . . ."
397 -e "s/<policy.apex-pdp.version>.*<\/policy.apex-pdp.version>/<policy.apex-pdp.version>$apex_pdp_latest_released_tag<\/policy.apex-pdp.version>/" \
398 -e "s/<version.policy.apex-pdp>.*<\/version.policy.apex-pdp>/<version.policy.apex-pdp>$apex_pdp_latest_released_tag<\/version.policy.apex-pdp>/" \
399 "$repo_location/$target_repo/pom.xml"
402 if [[ "$result_code" -eq 0 ]]
404 echo "policy apex-pdp reference updated on $repo_location/$target_repo"
406 echo "policy apex-pdp reference update failed on $repo_location/$target_repo"
411 if [ "$update_docker" = true ] && [ "$target_docker_images" != "" ]
413 if [ "$specified_repo" = "policy/docker" ]
415 if [ "$update_snapshot" = true ]
417 major_version=$(echo "$docker_latest_released_tag" | $SED -E 's/^([0-9]*)\.[0-9]*\.[0-9]*$/\1/')
418 minor_version=$(echo "$docker_latest_released_tag" | $SED -E 's/^[0-9]*\.([0-9]*)\.[0-9]*$/\1/')
419 patch_version=$(echo "$docker_latest_released_tag" | $SED -E 's/^[0-9]*\.[0-9]*\.([0-9]*)$/\1/')
421 new_patch_version=$((patch_version+1))
422 new_snapshot_tag="$major_version"."$minor_version"."$new_patch_version"-SNAPSHOT
424 echo "updating docker base images to version $new_snapshot_tag on repo $repo_location/$target_repo . . ."
425 find "$repo_location/$target_repo" \
427 -exec $SED -r -i "s/^(FROM onap\/policy-j[d|r][k|e]-alpine:)[0-9]*.[0-9]*.[0-9].*$/\1$new_snapshot_tag/" {} \;
430 next_release_version=${docker_latest_snapshot_tag%-*}
432 echo "updating docker base images to version $next_release_version on repo $repo_location/$target_repo . . ."
433 find "$repo_location/$target_repo" \
435 -exec $SED -r -i "s/^(FROM onap\/policy-j[d|r][k|e]-alpine:)[0-9]*.[0-9]*.[0-9].*$/\1$next_release_version/" {} \;
439 if [ "$update_snapshot" == true ]
441 echo "updating docker base images to version $docker_latest_snapshot_tag on repo $repo_location/$target_repo . . ."
442 find "$repo_location/$target_repo" \
444 -exec $SED -r -i "s/^(FROM onap\/policy-j[d|r][k|e]-alpine:)[0-9]*.[0-9]*.[0-9].*$/\1$docker_latest_snapshot_tag/" {} \;
447 echo "updating docker base images to version $docker_latest_released_tag on repo $repo_location/$target_repo . . ."
448 find "$repo_location/$target_repo" \
450 -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/" {} \;
455 if [[ "$result_code" -eq 0 ]]
457 echo "docker base images updated on $repo_location/$target_repo"
459 echo "docker base images update failed on $repo_location/$target_repo"
464 if [ "$update_release_file" = true ]
466 if [ ! "$target_repo" = "policy/parent" ]
468 echo "update of data file can only be done on the policy/parent repo"
472 release_data_file_name="$release_data_file_tag"_"$release_data_file"
475 "updating release data at" \
476 "$repo_location/$target_repo/integration/src/main/resources/release/$release_data_file_name"
477 # Update the latest release file
479 "$release_data_file" \
480 "$repo_location/$target_repo/integration/src/main/resources/release/$release_data_file"
481 # Update the tagged release file
483 "$release_data_file" \
484 "$repo_location/$target_repo/integration/src/main/resources/release/$release_data_file_name"
486 "updated release data at" \
487 "$repo_location/$target_repo/integration/src/main/resources/release/$release_data_file_name"