6eefdd148b1a3139726d5e813b1219357832d33d
[policy/parent.git] / integration / src / release_scripts / getReleaseData.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/apex-pdp"
37     "policy/drools-pdp"
38     "policy/xacml-pdp"
39     "policy/distribution"
40     "policy/clamp"
41     "policy/gui"
42     "policy/drools-applications"
43 )
44
45 usage()
46 {
47     echo ""
48     echo "$SCRIPT_NAME - gets information from the checked out Policy Framework repos for the release process"
49     echo ""
50     echo "       usage:  $SCRIPT_NAME [-options]"
51     echo ""
52     echo "       options"
53     echo "         -h           - this help message"
54     echo "         -d data_file - the policy release data file to create, defaults to '$release_data_file'"
55     echo "         -l location  - the location of the policy framework repos on the file system,"
56     echo "                        defaults to '$repo_location'"
57     exit 255;
58 }
59
60 while getopts "hd:l:" opt
61 do
62     case $opt in
63     h)
64         usage
65         ;;
66     d)
67         release_data_file=$OPTARG
68         ;;
69     l)
70         repo_location=$OPTARG
71         ;;
72     \?)
73         usage
74         exit 1
75         ;;
76     esac
77 done
78
79 if [ $OPTIND -eq 1 ]
80 then
81     echo "no arguments were specified"
82     usage
83 fi
84
85 if [[ -z "$repo_location" ]]
86 then
87     echo "policy repo location not specified on -l flag"
88     exit 1
89 fi
90
91 if ! [ -d "$repo_location" ]
92 then
93     echo "policy repo location '$repo_location' not found"
94     exit 1
95 fi
96
97 if [[ -z "$release_data_file" ]]
98 then
99     echo "policy release data file not specified on -d flag"
100     exit 1
101 fi
102
103 update_repos() {
104     echo "updating the policy framework data from '$repo_location' to data file '$release_data_file' . . ."
105
106     for repo in "${pf_repos[@]}"
107     do
108         echo "updating data from repo $repo to data file '$release_data_file' . . ."
109
110         if [ -d $repo_location/$repo ]
111         then
112             echo "updating repository '$repo' . . ."
113             git -C $repo_location/$repo checkout master
114             git -C $repo_location/$repo pull
115             git -C $repo_location/$repo rebase
116             git -C $repo_location/$repo fetch --tags
117         else
118             echo "repo $repo does not exist"
119             exit 1
120         fi
121         echo "data from repo $repo updated to data file '$release_data_file' . . ."
122     done
123
124     echo "policy framework data from '$repo_location' updated to data file '$release_data_file' . . ."
125 }
126
127
128 get_tags() {
129     echo "Last Tag version,Master Snapshot Version,Changed Files,Docker images"
130     echo "Last Tag version,Master Snapshot Version,Changed Files,Docker images" > $release_data_file
131     for repo in "${pf_repos[@]}"
132     do
133         latest_released_tag=`git -C $repo_location/$repo tag | \
134             grep '^[0-9]*\.[0-9]*\.[0-9]*$' | \
135             sort -V | \
136             tail -1`
137
138         latest_snapshot_tag=`mvn -f $repo_location/$repo clean | \
139             grep "SNAPSHOT" | \
140             tail -1 | \
141             sed -r 's/^.* ([0-9]*\.[0-9]*\.[0-9]*-SNAPSHOT).*$/\1/'`
142
143         changed_files=`git -C $repo_location/$repo diff --name-only $latest_released_tag origin/master | \
144             grep -v 'pom.xml$' | \
145             grep -v '^version.properties$' | \
146             grep -v "^releases/$latest_released_tag.yaml$" | \
147             grep -v "^releases/$latest_released_tag-container.yaml$" | \
148             wc -l | \
149             sed 's/^[[:space:]]*//g'`
150
151         if [ -f $repo_location/$repo/releases/$latest_released_tag-container.yaml ]
152         then
153             docker_images=`grep '\- name:' $repo_location/$repo/releases/$latest_released_tag-container.yaml | \
154             sed -e 's/\- //g' -e 's/\://g' -e "s/\'//g" -e 's/^[[:space:]]*//g' -e 's/^name //' | \
155             tr '\n' ':' | \
156             sed 's/:$//'`
157         else
158             docker_images=""
159         fi
160
161         echo "$repo,$latest_released_tag,$latest_snapshot_tag,$changed_files,$docker_images"
162         echo "$repo,$latest_released_tag,$latest_snapshot_tag,$changed_files,$docker_images" >> $release_data_file
163     done
164 }
165
166 update_repos
167 get_tags
168