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"
32 echo "$SCRIPT_NAME - updates the inter-repo references in Policy Framework POM files"
34 echo " usage: $SCRIPT_NAME [-options]"
37 echo " -h - this help message"
38 echo " -d data_file - the policy release data file to use, generated by the 'getReleaseData.sh' script,"
39 echo " defaults to '$release_data_file'"
40 echo " -l location - the location of the policy framework repos on the file system,"
41 echo " defaults to '$repo_location'"
42 echo " -r repo - the policy repo to update"
43 echo " -p - update policy/parent references"
44 echo " -c - update policy/common references"
45 echo " -m - update policy/model references"
46 echo " -o - update policy/drools-pdp references"
47 echo " -k - update docker base images in Dockerfiles"
48 echo " -s - update release references to snapshot references,"
49 echo " if omitted, snapshot references are updated to release references"
52 echo " $SCRIPT_NAME -pcm -r policy/pap"
53 echo " update the parent, common, and models references of policy/pap"
54 echo " to the current released version"
56 echo " $SCRIPT_NAME -c -m -s -r policy/api"
57 echo " update the common and models references of policy/api"
58 echo " to the current snapshot version"
65 update_drools_pdp=false
69 while getopts "hd:l:r:pcmoks" opt
76 release_data_file=$OPTARG
82 specified_repo=$OPTARG
94 update_drools_pdp=true
111 echo "no arguments were specified"
115 if [[ -z "$repo_location" ]]
117 echo "policy repo location not specified on -l flag"
121 if ! [ -d "$repo_location" ]
123 echo "policy repo location '$repo_location' not found"
127 if [[ -z "$release_data_file" ]]
129 echo "policy release data file not specified on -d flag"
133 if ! [ -f "$release_data_file" ]
135 echo "policy release data file '$release_data_file' not found"
139 if [ -z "$specified_repo" ]
141 echo "repo not specified on -r flag"
146 parent_latest_released_tag \
147 parent_latest_snapshot_tag \
148 parent_changed_files \
149 parent_docker_images \
150 <<< $( grep policy/parent $release_data_file | tr ',' ' ' )
153 common_latest_released_tag \
154 common_latest_snapshot_tag \
155 common_changed_files \
156 common_docker_images \
157 <<< $( grep policy/common $release_data_file | tr ',' ' ' )
160 docker_latest_released_tag \
161 docker_latest_snapshot_tag \
162 docker_changed_files \
163 docker_docker_images \
164 <<< $( grep policy/docker $release_data_file | tr ',' ' ' )
167 models_latest_released_tag \
168 models_latest_snapshot_tag \
169 models_changed_files \
170 models_docker_images \
171 <<< $( grep policy/models $release_data_file | tr ',' ' ' )
173 read drools_pdp_repo \
174 drools_pdp_latest_released_tag \
175 drools_pdp_latest_snapshot_tag \
176 drools_pdp_changed_files \
177 drools_pdp_docker_images \
178 <<< $( grep policy/drools-pdp $release_data_file | tr ',' ' ' )
181 target_latest_released_tag \
182 target_latest_snapshot_tag \
183 target_changed_files \
184 target_docker_images \
185 <<< $( grep $specified_repo $release_data_file | tr ',' ' ' )
187 if [ -z "$target_repo" ]
189 echo "specified repo '$specified_repo' not found in policy release data file '$release_data_file'"
193 if [ ! "$specified_repo" = "$target_repo" ]
195 echo "specified repo '$specified_repo' does not match target repo '$target_repo'"
199 if [ "$update_parent" = true ]
201 if [ "$specified_repo" = "policy/parent" ]
203 if [ "$update_snapshot" = true ]
205 echo updating policy parent reference to $parent_latest_snapshot_tag on $repo_location/$target_repo . . .
207 "s/<version.parent.resources>.*<\/version.parent.resources>/<version.parent.resources>$parent_latest_snapshot_tag<\/version.parent.resources>/" \
208 $repo_location/policy/parent/integration/pom.xml
211 next_release_version=${parent_latest_snapshot_tag%-*}
213 echo updating policy parent reference to $next_release_version on $repo_location/$target_repo . . .
215 "s/<version.parent.resources>.*<\/version.parent.resources>/<version.parent.resources>$next_release_version<\/version.parent.resources>/" \
216 $repo_location/policy/parent/integration/pom.xml
221 if [ "$update_snapshot" = true ]
223 echo updating policy parent reference to $parent_latest_snapshot_tag on $repo_location/$target_repo . . .
225 -f $repo_location/$target_repo/pom.xml \
226 -g org.onap.policy.parent \
228 -v $parent_latest_snapshot_tag
231 echo updating policy parent reference to $parent_latest_released_tag on $repo_location/$target_repo . . .
233 -f $repo_location/$target_repo/pom.xml \
234 -g org.onap.policy.parent \
236 -v $parent_latest_released_tag
240 if [[ "$result_code" -eq 0 ]]
242 echo policy parent reference updated on $repo_location/$target_repo
244 echo policy parent reference update failed on $repo_location/$target_repo
249 if [ "$update_common" = true ]
251 if [ "$update_snapshot" = true ]
253 echo updating policy common reference to $common_latest_snapshot_tag on $repo_location/$target_repo . . .
255 -e "s/<policy.common.version>.*<\/policy.common.version>/<policy.common.version>$common_latest_snapshot_tag<\/policy.common.version>/" \
256 -e "s/<version.policy.common>.*<\/version.policy.common>/<version.policy.common>$common_latest_snapshot_tag<\/version.policy.common>/" \
257 $repo_location/$target_repo/pom.xml
260 echo updating policy common reference to $common_latest_released_tag on $repo_location/$target_repo . . .
262 -e "s/<policy.common.version>.*<\/policy.common.version>/<policy.common.version>$common_latest_released_tag<\/policy.common.version>/" \
263 -e "s/<version.policy.common>.*<\/version.policy.common>/<version.policy.common>$common_latest_released_tag<\/version.policy.common>/" \
264 $repo_location/$target_repo/pom.xml
267 if [[ "$result_code" -eq 0 ]]
269 echo policy common reference updated on $repo_location/$target_repo
271 echo policy common reference update failed on $repo_location/$target_repo
276 if [ "$update_models" = true ]
278 if [ "$update_snapshot" = true ]
280 echo updating policy models reference to $models_latest_snapshot_tag on $repo_location/$target_repo . . .
282 -e "s/<policy.models.version>.*<\/policy.models.version>/<policy.models.version>$models_latest_snapshot_tag<\/policy.models.version>/" \
283 -e "s/<version.policy.models>.*<\/version.policy.models>/<version.policy.models>$models_latest_snapshot_tag<\/version.policy.models>/" \
284 $repo_location/$target_repo/pom.xml
287 echo updating policy models reference to $models_latest_released_tag on $repo_location/$target_repo . . .
289 -e "s/<policy.models.version>.*<\/policy.models.version>/<policy.models.version>$models_latest_released_tag<\/policy.models.version>/" \
290 -e "s/<version.policy.models>.*<\/version.policy.models>/<version.policy.models>$models_latest_released_tag<\/version.policy.models>/" \
291 $repo_location/$target_repo/pom.xml
294 if [[ "$result_code" -eq 0 ]]
296 echo policy models reference updated on $repo_location/$target_repo
298 echo policy models reference update failed on $repo_location/$target_repo
303 if [ "$update_drools_pdp" = true ]
305 if [ "$update_snapshot" = true ]
307 echo updating policy drools-pdp reference to $drools_pdp_latest_snapshot_tag on $repo_location/$target_repo . . .
309 -e "s/<policy.drools-pdp.version>.*<\/policy.drools-pdp.version>/<policy.drools-pdp.version>$drools_pdp_latest_snapshot_tag<\/policy.drools-pdp.version>/" \
310 -e "s/<version.policy.drools-pdp>.*<\/version.policy.drools-pdp>/<version.policy.drools-pdp>$drools_pdp_latest_snapshot_tag<\/version.policy.drools-pdp>/" \
311 $repo_location/$target_repo/pom.xml
314 echo updating policy drools-pdp reference to $drools_pdp_latest_released_tag on $repo_location/$target_repo . . .
316 -e "s/<policy.drools-pdp.version>.*<\/policy.drools-pdp.version>/<policy.drools-pdp.version>$drools_pdp_latest_released_tag<\/policy.drools-pdp.version>/" \
317 -e "s/<version.policy.drools-pdp>.*<\/version.policy.drools-pdp>/<version.policy.drools-pdp>$drools_pdp_latest_released_tag<\/version.policy.drools-pdp>/" \
318 $repo_location/$target_repo/pom.xml
321 if [[ "$result_code" -eq 0 ]]
323 echo policy drools-pdp reference updated on $repo_location/$target_repo
325 echo policy drools-pdp reference update failed on $repo_location/$target_repo
330 if [ "$update_docker" = true ] && [ "$target_docker_images" != "" ]
332 echo updating docker base images to version $docker_latest_released_tag on repo $repo_location/$target_repo
333 find $repo_location/$target_repo \
335 -exec sed -r -i "s/^(FROM onap\/policy-j[d|r][k|e]-alpine:)2.3.1$/\1$docker_latest_released_tag/" {} \;
337 if [[ "$result_code" -eq 0 ]]
339 echo docker base images updated on $repo_location/$target_repo
341 echo docker base images update failed on $repo_location/$target_repo