f8317e2a816b941122b684a0e5ac7f0c76081772
[policy/parent.git] / integration / src / release_scripts / bumpSnapshots.sh
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
29 declare -a pf_repos=(
30         "policy/parent"
31         "policy/docker"
32         "policy/common"
33         "policy/models"
34         "policy/api"
35         "policy/pap"
36         "policy/drools-pdp"
37         "policy/apex-pdp"
38         "policy/xacml-pdp"
39         "policy/distribution"
40         "policy/gui"
41         "policy/clamp"
42         "policy/drools-applications"
43 )
44
45 usage()
46 {
47     echo ""
48     echo "$SCRIPT_NAME - generate commits to bump the snapshot version and update references to snapshot references"
49     echo "               on any repos that need to be bumped or updated"
50     echo ""
51     echo "       usage:  $SCRIPT_NAME [-options]"
52     echo ""
53     echo "       options"
54     echo "         -h           - this help message"
55     echo "         -d data_file - the policy release data file to use, defaults to '$release_data_file'"
56     echo "         -l location  - the location of the policy framework repos on the file system,"
57     echo "                        defaults to '$repo_location'"
58     echo "         -i issue-id  - issue ID in the format POLICY-nnnn"
59     echo ""
60     echo " examples:"
61     echo "  $SCRIPT_NAME -l /home/user/onap -d /home/user/data/pf_release_data.csv -i POLICY-1234"
62     echo "    bump snapshots on the repos at location '/home/user/onap' using the release data"
63     echo "    in the file '/home/user/data/pf_release_data.csv'"
64     exit 255;
65 }
66
67 while getopts "hd:l:i:" opt
68 do
69     case $opt in
70     h)
71         usage
72         ;;
73     d)
74         release_data_file=$OPTARG
75         ;;
76     l)
77         repo_location=$OPTARG
78         ;;
79     i)
80         issue_id=$OPTARG
81         ;;
82     \?)
83         usage
84         exit 1
85         ;;
86     esac
87 done
88
89 if [ $OPTIND -eq 1 ]
90 then
91     echo "no arguments were specified"
92     usage
93 fi
94
95 if [[ -z "$repo_location" ]]
96 then
97     echo "policy repo location not specified on -l flag"
98     exit 1
99 fi
100
101 if ! [ -d "$repo_location" ]
102 then
103     echo "policy repo location '$repo_location' not found"
104     exit 1
105 fi
106
107 if [[ -z "$release_data_file" ]]
108 then
109     echo "policy release data file not specified on -d flag"
110     exit 1
111 fi
112
113 if ! [ -f "$release_data_file" ]
114 then
115     echo "policy release data file '$release_data_file' not found"
116     exit 1
117 fi
118
119 if [ -z "$issue_id" ]
120 then
121     echo "issue_id not specified on -i flag"
122     exit 1
123 fi
124
125 if ! echo "$issue_id" | grep -Eq '^POLICY-[0-9]*$'
126 then
127   echo "issue ID is invalid, it should be of form 'POLICY-nnnn'"
128   exit 1
129 fi
130
131 for specified_repo in "${pf_repos[@]}"
132 do
133     read    repo \
134             latest_released_tag \
135             latest_snapshot_tag \
136             changed_files docker_images \
137         <<< $( grep $specified_repo $release_data_file | tr ',' ' ' )
138
139     if [ ! "$repo" = "$specified_repo" ]
140     then
141         echo "repo '$specified_repo' not found in file 'pf_release_data.csv'"
142         continue
143     fi
144
145     next_release_version=${latest_snapshot_tag%-*}
146
147     if [ "$latest_released_tag" = "$next_release_version" ]
148     then
149         declare -i major_version=`echo $next_release_version | sed -E 's/^([0-9]*)\.[0-9]*\.[0-9]*$/\1/'`
150         declare -i minor_version=`echo $next_release_version | sed -E 's/^[0-9]*\.([0-9]*)\.[0-9]*$/\1/'`
151         declare -i patch_version=`echo $next_release_version | sed -E 's/^[0-9]*\.[0-9]*\.([0-9]*)$/\1/'`
152         declare -i new_patch_version=$(($patch_version+1))
153
154         new_snapshot_tag="$major_version"."$minor_version"."$new_patch_version"-SNAPSHOT
155
156         echo updating snapshot version and references of repo $repo to $new_snapshot_tag . . .
157         mvn -f $repo_location/$repo \
158             -DnewVersion=$new_snapshot_tag versions:set \
159             versions:update-child-modules versions:commit
160
161         temp_file=$(mktemp)
162
163         echo updating snapshot version of repo $repo in $repo_location/$repo/version.properties
164         sed -e "s/patch=$patch_version/patch=$new_patch_version/" $repo_location/$repo/version.properties > $temp_file
165         mv $temp_file $repo_location/$repo/version.properties
166     fi
167
168     updateRefs.sh -pcmos -d $release_data_file -l $repo_location -r $repo
169     git -C $repo_location/$specified_repo status | grep '^[ \t]*modified:[ \t]*pom.xml' > /dev/null 2>&1
170     references_updated=$?
171
172     if [ "$latest_released_tag" != "$next_release_version" ] && [ $references_updated -eq 0 ]
173     then
174         continue
175     fi
176
177     echo "generating commit to update snapshot version and/or references of repo $repo . . ."
178
179     generateCommit.sh \
180         -l $repo_location \
181         -r $repo \
182         -i $issue_id \
183         -e "Update snapshot and/or references of $repo to latest snapshots" \
184         -m "$repo updated to its latest own and reference snapshots"
185
186     echo "commit to update snapshot version and/or references of repo $repo generated"
187 done
188