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"
29 # Use the bash internal OSTYPE variable to check for MacOS
30 if [[ "$OSTYPE" == "darwin"* ]]
40 echo "$SCRIPT_NAME - updates the inter-repo references in Policy Framework POM files"
42 echo " usage: $SCRIPT_NAME [-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"
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"
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"
73 update_drools_pdp=false
77 while getopts "hd:l:r:pcmoks" opt
84 release_data_file=$OPTARG
90 specified_repo=$OPTARG
102 update_drools_pdp=true
119 echo "no arguments were specified"
123 if [[ -z "$repo_location" ]]
125 echo "policy repo location not specified on -l flag"
129 if ! [ -d "$repo_location" ]
131 echo "policy repo location '$repo_location' not found"
135 if [[ -z "$release_data_file" ]]
137 echo "policy release data file not specified on -d flag"
141 if ! [ -f "$release_data_file" ]
143 echo "policy release data file '$release_data_file' not found"
147 if [ -z "$specified_repo" ]
149 echo "repo not specified on -r flag"
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 ',' ' ' )
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 ',' ' ' )
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 ',' ' ' )
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 ',' ' ' )
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 ',' ' ' )
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 ',' ' ' )
195 if [ -z "$target_repo" ]
197 echo "specified repo '$specified_repo' not found in policy release data file '$release_data_file'"
201 if [ ! "$specified_repo" = "$target_repo" ]
203 echo "specified repo '$specified_repo' does not match target repo '$target_repo'"
207 if [ "$update_parent" = true ]
209 if [ "$specified_repo" = "policy/parent" ]
211 if [ "$update_snapshot" = true ]
213 echo updating policy parent reference to $parent_latest_snapshot_tag on $repo_location/$target_repo . . .
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
219 next_release_version=${parent_latest_snapshot_tag%-*}
221 echo updating policy parent reference to $next_release_version on $repo_location/$target_repo . . .
223 "s/<version.parent.resources>.*<\/version.parent.resources>/<version.parent.resources>$next_release_version<\/version.parent.resources>/" \
224 $repo_location/policy/parent/integration/pom.xml
228 if [ "$update_snapshot" = true ]
230 echo updating policy parent reference to $parent_latest_snapshot_tag on $repo_location/$target_repo . . .
232 -f $repo_location/$target_repo/pom.xml \
233 -g org.onap.policy.parent \
235 -v $parent_latest_snapshot_tag
238 echo updating policy parent reference to $parent_latest_released_tag on $repo_location/$target_repo . . .
240 -f $repo_location/$target_repo/pom.xml \
241 -g org.onap.policy.parent \
243 -v $parent_latest_released_tag
247 if [[ "$result_code" -eq 0 ]]
249 echo policy parent reference updated on $repo_location/$target_repo
251 echo policy parent reference update failed on $repo_location/$target_repo
256 if [ "$update_common" = true ]
258 if [ "$update_snapshot" = true ]
260 echo updating policy common reference to $common_latest_snapshot_tag on $repo_location/$target_repo . . .
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
267 echo updating policy common reference to $common_latest_released_tag on $repo_location/$target_repo . . .
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
274 if [[ "$result_code" -eq 0 ]]
276 echo policy common reference updated on $repo_location/$target_repo
278 echo policy common reference update failed on $repo_location/$target_repo
283 if [ "$update_models" = true ]
285 if [ "$update_snapshot" = true ]
287 echo updating policy models reference to $models_latest_snapshot_tag on $repo_location/$target_repo . . .
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
294 echo updating policy models reference to $models_latest_released_tag on $repo_location/$target_repo . . .
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
301 if [[ "$result_code" -eq 0 ]]
303 echo policy models reference updated on $repo_location/$target_repo
305 echo policy models reference update failed on $repo_location/$target_repo
310 if [ "$update_drools_pdp" = true ]
312 if [ "$update_snapshot" = true ]
314 echo updating policy drools-pdp reference to $drools_pdp_latest_snapshot_tag on $repo_location/$target_repo . . .
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
321 echo updating policy drools-pdp reference to $drools_pdp_latest_released_tag on $repo_location/$target_repo . . .
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
328 if [[ "$result_code" -eq 0 ]]
330 echo policy drools-pdp reference updated on $repo_location/$target_repo
332 echo policy drools-pdp reference update failed on $repo_location/$target_repo
337 if [ "$update_docker" = true ] && [ "$target_docker_images" != "" ]
339 echo updating docker base images to version $docker_latest_released_tag on repo $repo_location/$target_repo
340 find $repo_location/$target_repo \
342 -exec $SED -r -i "s/^(FROM onap\/policy-j[d|r][k|e]-alpine:)2.3.1$/\1$docker_latest_released_tag/" {} \;
344 if [[ "$result_code" -eq 0 ]]
346 echo docker base images updated on $repo_location/$target_repo
348 echo docker base images update failed on $repo_location/$target_repo