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