liamfallon | 81c2c51 | 2021-12-16 12:56:37 +0000 | [diff] [blame] | 1 | #!/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 | |
| 23 | set -e |
| 24 | |
| 25 | SCRIPT_NAME=`basename $0` |
| 26 | repo_location="./" |
| 27 | release_data_file="./pf_release_data.csv" |
| 28 | |
liamfallon | b76315a | 2022-01-12 13:24:54 +0000 | [diff] [blame] | 29 | # Use the bash internal OSTYPE variable to check for MacOS |
| 30 | if [[ "$OSTYPE" == "darwin"* ]] |
| 31 | then |
| 32 | SED="gsed" |
| 33 | else |
| 34 | SED="sed" |
| 35 | fi |
| 36 | |
liamfallon | 81c2c51 | 2021-12-16 12:56:37 +0000 | [diff] [blame] | 37 | usage() |
| 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 | |
| 70 | update_parent=false |
| 71 | update_common=false |
| 72 | update_models=false |
| 73 | update_drools_pdp=false |
| 74 | update_snapshot=false |
| 75 | update_docker=false |
| 76 | |
| 77 | while getopts "hd:l:r:pcmoks" opt |
| 78 | do |
| 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 |
| 115 | done |
| 116 | |
| 117 | if [ $OPTIND -eq 1 ] |
| 118 | then |
| 119 | echo "no arguments were specified" |
| 120 | usage |
| 121 | fi |
| 122 | |
| 123 | if [[ -z "$repo_location" ]] |
| 124 | then |
| 125 | echo "policy repo location not specified on -l flag" |
| 126 | exit 1 |
| 127 | fi |
| 128 | |
| 129 | if ! [ -d "$repo_location" ] |
| 130 | then |
| 131 | echo "policy repo location '$repo_location' not found" |
| 132 | exit 1 |
| 133 | fi |
| 134 | |
| 135 | if [[ -z "$release_data_file" ]] |
| 136 | then |
| 137 | echo "policy release data file not specified on -d flag" |
| 138 | exit 1 |
| 139 | fi |
| 140 | |
| 141 | if ! [ -f "$release_data_file" ] |
| 142 | then |
| 143 | echo "policy release data file '$release_data_file' not found" |
| 144 | exit 1 |
| 145 | fi |
| 146 | |
| 147 | if [ -z "$specified_repo" ] |
| 148 | then |
| 149 | echo "repo not specified on -r flag" |
| 150 | exit 1 |
| 151 | fi |
| 152 | |
| 153 | read 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 | |
| 160 | read 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 | |
| 167 | read 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 | |
| 174 | read 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 | |
| 181 | read 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 | |
| 188 | read 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 | |
| 195 | if [ -z "$target_repo" ] |
| 196 | then |
| 197 | echo "specified repo '$specified_repo' not found in policy release data file '$release_data_file'" |
| 198 | exit 1 |
| 199 | fi |
| 200 | |
| 201 | if [ ! "$specified_repo" = "$target_repo" ] |
| 202 | then |
| 203 | echo "specified repo '$specified_repo' does not match target repo '$target_repo'" |
| 204 | exit 1 |
| 205 | fi |
| 206 | |
| 207 | if [ "$update_parent" = true ] |
| 208 | then |
| 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 . . . |
liamfallon | b76315a | 2022-01-12 13:24:54 +0000 | [diff] [blame] | 214 | $SED -i \ |
liamfallon | 81c2c51 | 2021-12-16 12:56:37 +0000 | [diff] [blame] | 215 | "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 . . . |
liamfallon | b76315a | 2022-01-12 13:24:54 +0000 | [diff] [blame] | 222 | $SED -i \ |
liamfallon | 81c2c51 | 2021-12-16 12:56:37 +0000 | [diff] [blame] | 223 | "s/<version.parent.resources>.*<\/version.parent.resources>/<version.parent.resources>$next_release_version<\/version.parent.resources>/" \ |
liamfallon | b76315a | 2022-01-12 13:24:54 +0000 | [diff] [blame] | 224 | $repo_location/policy/parent/integration/pom.xml |
liamfallon | 81c2c51 | 2021-12-16 12:56:37 +0000 | [diff] [blame] | 225 | 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 |
| 254 | fi |
| 255 | |
| 256 | if [ "$update_common" = true ] |
| 257 | then |
| 258 | if [ "$update_snapshot" = true ] |
| 259 | then |
| 260 | echo updating policy common reference to $common_latest_snapshot_tag on $repo_location/$target_repo . . . |
liamfallon | b76315a | 2022-01-12 13:24:54 +0000 | [diff] [blame] | 261 | $SED -i \ |
liamfallon | 81c2c51 | 2021-12-16 12:56:37 +0000 | [diff] [blame] | 262 | -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 . . . |
liamfallon | b76315a | 2022-01-12 13:24:54 +0000 | [diff] [blame] | 268 | $SED -i \ |
liamfallon | 81c2c51 | 2021-12-16 12:56:37 +0000 | [diff] [blame] | 269 | -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 |
| 281 | fi |
| 282 | |
| 283 | if [ "$update_models" = true ] |
| 284 | then |
| 285 | if [ "$update_snapshot" = true ] |
| 286 | then |
| 287 | echo updating policy models reference to $models_latest_snapshot_tag on $repo_location/$target_repo . . . |
liamfallon | b76315a | 2022-01-12 13:24:54 +0000 | [diff] [blame] | 288 | $SED -i \ |
liamfallon | 81c2c51 | 2021-12-16 12:56:37 +0000 | [diff] [blame] | 289 | -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 . . . |
liamfallon | b76315a | 2022-01-12 13:24:54 +0000 | [diff] [blame] | 295 | $SED -i \ |
liamfallon | 81c2c51 | 2021-12-16 12:56:37 +0000 | [diff] [blame] | 296 | -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 |
| 308 | fi |
| 309 | |
| 310 | if [ "$update_drools_pdp" = true ] |
| 311 | then |
| 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 . . . |
liamfallon | b76315a | 2022-01-12 13:24:54 +0000 | [diff] [blame] | 315 | $SED -i \ |
liamfallon | 81c2c51 | 2021-12-16 12:56:37 +0000 | [diff] [blame] | 316 | -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 . . . |
liamfallon | b76315a | 2022-01-12 13:24:54 +0000 | [diff] [blame] | 322 | $SED -i \ |
liamfallon | 81c2c51 | 2021-12-16 12:56:37 +0000 | [diff] [blame] | 323 | -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 |
| 335 | fi |
| 336 | |
| 337 | if [ "$update_docker" = true ] && [ "$target_docker_images" != "" ] |
| 338 | then |
| 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*' \ |
liamfallon | b76315a | 2022-01-12 13:24:54 +0000 | [diff] [blame] | 342 | -exec $SED -r -i "s/^(FROM onap\/policy-j[d|r][k|e]-alpine:)2.3.1$/\1$docker_latest_released_tag/" {} \; |
liamfallon | 81c2c51 | 2021-12-16 12:56:37 +0000 | [diff] [blame] | 343 | 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 |
| 351 | fi |