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 " -f - update release data in policy parent"
59 echo " -t tag - 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
83 while getopts "hd:l:r:pcmoxkft:s" opt
90 release_data_file=$OPTARG
96 specified_repo=$OPTARG
108 update_drools_pdp=true
120 release_data_file_tag="$OPTARG"_
134 echo "no arguments were specified"
138 if [[ -z "$repo_location" ]]
140 echo "policy repo location not specified on -l flag"
144 if ! [ -d "$repo_location" ]
146 echo "policy repo location '$repo_location' not found"
150 if [[ -z "$release_data_file" ]]
152 echo "policy release data file not specified on -d flag"
156 if ! [ -f "$release_data_file" ]
158 echo "policy release data file '$release_data_file' not found"
162 if [ -z "$specified_repo" ]
164 echo "repo not specified on -r flag"
168 # shellcheck disable=SC2034
169 # shellcheck disable=SC2046
170 read -r parent_repo \
171 parent_latest_released_tag \
172 parent_latest_snapshot_tag \
173 parent_changed_files \
174 parent_docker_images \
175 <<< $(grep policy/parent "$release_data_file" | tr ',' ' ' )
177 # shellcheck disable=SC2034
178 # shellcheck disable=SC2046
179 read -r common_repo \
180 common_latest_released_tag \
181 common_latest_snapshot_tag \
182 common_changed_files \
183 common_docker_images \
184 <<< $(grep policy/common "$release_data_file" | tr ',' ' ' )
186 # shellcheck disable=SC2034
187 # shellcheck disable=SC2046
188 read -r docker_repo \
189 docker_latest_released_tag \
190 docker_latest_snapshot_tag \
191 docker_changed_files \
192 docker_docker_images \
193 <<< $(grep policy/docker "$release_data_file" | tr ',' ' ' )
195 # shellcheck disable=SC2034
196 # shellcheck disable=SC2046
197 read -r models_repo \
198 models_latest_released_tag \
199 models_latest_snapshot_tag \
200 models_changed_files \
201 models_docker_images \
202 <<< $(grep policy/models "$release_data_file" | tr ',' ' ' )
204 # shellcheck disable=SC2034
205 # shellcheck disable=SC2046
206 read -r drools_pdp_repo \
207 drools_pdp_latest_released_tag \
208 drools_pdp_latest_snapshot_tag \
209 drools_pdp_changed_files \
210 drools_pdp_docker_images \
211 <<< $(grep policy/drools-pdp "$release_data_file" | tr ',' ' ' )
213 # shellcheck disable=SC2034
214 # shellcheck disable=SC2046
215 read -r apex_pdp_repo \
216 apex_pdp_latest_released_tag \
217 apex_pdp_latest_snapshot_tag \
218 apex_pdp_changed_files \
219 apex_pdp_docker_images \
220 <<< $(grep policy/apex-pdp "$release_data_file" | tr ',' ' ' )
222 # shellcheck disable=SC2034
223 # shellcheck disable=SC2046
224 read -r target_repo \
225 target_latest_released_tag \
226 target_latest_snapshot_tag \
227 target_changed_files \
228 target_docker_images \
229 <<< $(grep "$specified_repo" "$release_data_file" | tr ',' ' ' )
231 if [ -z "$target_repo" ]
233 echo "specified repo '$specified_repo' not found in policy release data file '$release_data_file'"
237 if [ ! "$specified_repo" = "$target_repo" ]
239 echo "specified repo '$specified_repo' does not match target repo '$target_repo'"
243 if [ "$update_parent" = true ]
245 if [ "$specified_repo" = "policy/parent" ]
247 if [ "$update_snapshot" = true ]
249 major_version=$(echo "$parent_latest_released_tag" | $SED -E 's/^([0-9]*)\.[0-9]*\.[0-9]*$/\1/')
250 minor_version=$(echo "$parent_latest_released_tag" | $SED -E 's/^[0-9]*\.([0-9]*)\.[0-9]*$/\1/')
251 patch_version=$(echo "$parent_latest_released_tag" | $SED -E 's/^[0-9]*\.[0-9]*\.([0-9]*)$/\1/')
253 new_patch_version=$((patch_version+1))
254 new_snapshot_tag="$major_version"."$minor_version"."$new_patch_version"-SNAPSHOT
256 echo updating policy parent reference to "$new_snapshot_tag" on "$repo_location/$target_repo" . . .
258 "s/<version.parent.resources>.*<\/version.parent.resources>/<version.parent.resources>$new_snapshot_tag<\/version.parent.resources>/" \
259 "$repo_location/policy/parent/integration/pom.xml"
262 next_release_version=${parent_latest_snapshot_tag%-*}
264 echo "updating policy parent reference to $next_release_version on $repo_location/$target_repo . . ."
266 "s/<version.parent.resources>.*<\/version.parent.resources>/<version.parent.resources>$next_release_version<\/version.parent.resources>/" \
267 "$repo_location/policy/parent/integration/pom.xml"
271 if [ "$update_snapshot" = true ]
273 echo "updating policy parent reference to $parent_latest_snapshot_tag on $repo_location/$target_repo . . ."
275 -f "$repo_location/$target_repo/pom.xml" \
276 -g org.onap.policy.parent \
278 -v "$parent_latest_snapshot_tag"
281 echo "updating policy parent reference to $parent_latest_released_tag on $repo_location/$target_repo . . ."
283 -f "$repo_location/$target_repo/pom.xml" \
284 -g org.onap.policy.parent \
286 -v "$parent_latest_released_tag"
290 if [[ "$result_code" -eq 0 ]]
292 echo "policy parent reference updated on $repo_location/$target_repo"
294 echo "policy parent reference update failed on $repo_location/$target_repo"
299 if [ "$update_common" = true ]
301 if [ "$update_snapshot" = true ]
303 echo "updating policy common reference to $common_latest_snapshot_tag on $repo_location/$target_repo . . ."
305 -e "s/<policy.common.version>.*<\/policy.common.version>/<policy.common.version>$common_latest_snapshot_tag<\/policy.common.version>/" \
306 -e "s/<version.policy.common>.*<\/version.policy.common>/<version.policy.common>$common_latest_snapshot_tag<\/version.policy.common>/" \
307 "$repo_location/$target_repo/pom.xml"
310 echo "updating policy common reference to $common_latest_released_tag on $repo_location/$target_repo . . ."
312 -e "s/<policy.common.version>.*<\/policy.common.version>/<policy.common.version>$common_latest_released_tag<\/policy.common.version>/" \
313 -e "s/<version.policy.common>.*<\/version.policy.common>/<version.policy.common>$common_latest_released_tag<\/version.policy.common>/" \
314 "$repo_location/$target_repo/pom.xml"
317 if [[ "$result_code" -eq 0 ]]
319 echo "policy common reference updated on $repo_location/$target_repo"
321 echo "policy common reference update failed on $repo_location/$target_repo"
326 if [ "$update_models" = true ]
328 if [ "$update_snapshot" = true ]
330 echo "updating policy models reference to $models_latest_snapshot_tag on $repo_location/$target_repo . . ."
332 -e "s/<policy.models.version>.*<\/policy.models.version>/<policy.models.version>$models_latest_snapshot_tag<\/policy.models.version>/" \
333 -e "s/<version.policy.models>.*<\/version.policy.models>/<version.policy.models>$models_latest_snapshot_tag<\/version.policy.models>/" \
334 "$repo_location/$target_repo/pom.xml"
337 echo "updating policy models reference to $models_latest_released_tag on $repo_location/$target_repo . . ."
339 -e "s/<policy.models.version>.*<\/policy.models.version>/<policy.models.version>$models_latest_released_tag<\/policy.models.version>/" \
340 -e "s/<version.policy.models>.*<\/version.policy.models>/<version.policy.models>$models_latest_released_tag<\/version.policy.models>/" \
341 "$repo_location/$target_repo/pom.xml"
344 if [[ "$result_code" -eq 0 ]]
346 echo "policy models reference updated on $repo_location/$target_repo"
348 echo "policy models reference update failed on $repo_location/$target_repo"
353 if [ "$update_drools_pdp" = true ]
355 if [ "$update_snapshot" = true ]
357 echo "updating policy drools-pdp reference to $drools_pdp_latest_snapshot_tag on $repo_location/$target_repo . . ."
359 -e "s/<policy.drools-pdp.version>.*<\/policy.drools-pdp.version>/<policy.drools-pdp.version>$drools_pdp_latest_snapshot_tag<\/policy.drools-pdp.version>/" \
360 -e "s/<version.policy.drools-pdp>.*<\/version.policy.drools-pdp>/<version.policy.drools-pdp>$drools_pdp_latest_snapshot_tag<\/version.policy.drools-pdp>/" \
361 "$repo_location/$target_repo/pom.xml"
364 echo "updating policy drools-pdp reference to $drools_pdp_latest_released_tag on $repo_location/$target_repo . . ."
366 -e "s/<policy.drools-pdp.version>.*<\/policy.drools-pdp.version>/<policy.drools-pdp.version>$drools_pdp_latest_released_tag<\/policy.drools-pdp.version>/" \
367 -e "s/<version.policy.drools-pdp>.*<\/version.policy.drools-pdp>/<version.policy.drools-pdp>$drools_pdp_latest_released_tag<\/version.policy.drools-pdp>/" \
368 "$repo_location/$target_repo/pom.xml"
371 if [[ "$result_code" -eq 0 ]]
373 echo "policy drools-pdp reference updated on $repo_location/$target_repo"
375 echo "policy drools-pdp reference update failed on $repo_location/$target_repo"
380 if [ "$update_apex_pdp" = true ]
382 if [ "$update_snapshot" = true ]
384 echo "updating policy apex-pdp reference to $apex_pdp_latest_snapshot_tag on $repo_location/$target_repo . . ."
386 -e "s/<policy.apex-pdp.version>.*<\/policy.apex-pdp.version>/<policy.apex-pdp.version>$apex_pdp_latest_snapshot_tag<\/policy.apex-pdp.version>/" \
387 -e "s/<version.policy.apex-pdp>.*<\/version.policy.apex-pdp>/<version.policy.apex-pdp>$apex_pdp_latest_snapshot_tag<\/version.policy.apex-pdp>/" \
388 "$repo_location/$target_repo/pom.xml"
391 echo "updating policy apex-pdp reference to $apex_pdp_latest_released_tag on $repo_location/$target_repo . . ."
393 -e "s/<policy.apex-pdp.version>.*<\/policy.apex-pdp.version>/<policy.apex-pdp.version>$apex_pdp_latest_released_tag<\/policy.apex-pdp.version>/" \
394 -e "s/<version.policy.apex-pdp>.*<\/version.policy.apex-pdp>/<version.policy.apex-pdp>$apex_pdp_latest_released_tag<\/version.policy.apex-pdp>/" \
395 "$repo_location/$target_repo/pom.xml"
398 if [[ "$result_code" -eq 0 ]]
400 echo "policy apex-pdp reference updated on $repo_location/$target_repo"
402 echo "policy apex-pdp reference update failed on $repo_location/$target_repo"
407 if [ "$update_docker" = true ] && [ "$target_docker_images" != "" ]
409 if [ "$update_snapshot" == true ]
411 echo "updating docker base images to version $docker_latest_snapshot_tag on repo $repo_location/$target_repo . . ."
412 find "$repo_location/$target_repo" \
414 -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/" {} \;
417 echo "updating docker base images to version $docker_latest_released_tag on repo $repo_location/$target_repo . . ."
418 find "$repo_location/$target_repo" \
420 -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/" {} \;
424 if [[ "$result_code" -eq 0 ]]
426 echo "docker base images updated on $repo_location/$target_repo"
428 echo "docker base images update failed on $repo_location/$target_repo"
433 if [ "$update_file" = true ]
435 if [ ! "$target_repo" = "policy/parent" ]
437 echo "update of data file can only be done on the policy/parent repo"
441 release_data_file_name="$release_data_file_tag$release_data_file"
444 "updating release data at" \
445 "$repo_location/$target_repo/integration/src/main/resources/release/$release_data_file_name"
447 "$release_data_file" \
448 "$repo_location/$target_repo/integration/src/main/resources/release/$release_data_file_name"
450 "updated release data at" \
451 "$repo_location/$target_repo/integration/src/main/resources/release/$release_data_file_name"