Add release script, fix sed for MacOS
[policy/parent.git] / integration / src / release_scripts / releaseRepoImages.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 usage()
30 {
31     echo ""
32     echo "$SCRIPT_NAME - release the docker images for the specified repository by generating the release yaml file and"
33     echo "               the release commit"
34     echo "       usage:  $SCRIPT_NAME [-options]"
35     echo ""
36     echo "       options"
37     echo "         -h           - this help message"
38     echo "         -d data_file - the policy release data file to use, defaults to '$release_data_file'"
39     echo "         -l location  - the location of the policy framework repos on the file system,"
40     echo "                        defaults to '$repo_location'"
41     echo "         -r repo      - the policy repo to release"
42     echo "         -i issue-id  - issue ID in the format POLICY-nnnn"
43     echo ""
44     echo " examples:"
45     echo "  $SCRIPT_NAME -l /home/user/onap -d /home/user/data/pf_release_data.csv -r policy/common -i POLICY-1234"
46     echo "    release the 'policy/common' repo at location '/home/user/onap' using the release data"
47     echo "    in the file '/home/user/data/pf_release_data.csv'"
48     exit 255;
49 }
50
51 while getopts "hd:l:r:i:" opt
52 do
53     case $opt in
54     h)
55         usage
56         ;;
57     d)
58         release_data_file=$OPTARG
59         ;;
60     l)
61         repo_location=$OPTARG
62         ;;
63     r)
64         specified_repo=$OPTARG
65         ;;
66     i)
67         issue_id=$OPTARG
68         ;;
69     \?)
70         usage
71         exit 1
72         ;;
73     esac
74 done
75
76 if [ $OPTIND -eq 1 ]
77 then
78     echo "no arguments were specified"
79     usage
80 fi
81
82 if [[ -z "$repo_location" ]]
83 then
84     echo "policy repo location not specified on -l flag"
85     exit 1
86 fi
87
88 if ! [ -d "$repo_location" ]
89 then
90     echo "policy repo location '$repo_location' not found"
91     exit 1
92 fi
93
94 if [[ -z "$release_data_file" ]]
95 then
96     echo "policy release data file not specified on -d flag"
97     exit 1
98 fi
99
100 if ! [ -f "$release_data_file" ]
101 then
102     echo "policy release data file '$release_data_file' not found"
103     exit 1
104 fi
105
106 if [ -z "$specified_repo" ]
107 then
108     echo "repo not specified on -r flag"
109     exit 1
110 fi
111
112 if [ -z "$issue_id" ]
113 then
114     echo "issue_id not specified on -i flag"
115     exit 1
116 fi
117
118 if ! echo "$issue_id" | grep -Eq '^POLICY-[0-9]*$'
119 then
120   echo "issue ID is invalid, it should be of form 'POLICY-nnnn'"
121   exit 1
122 fi
123
124 read repo \
125     latest_released_tag \
126     latest_snapshot_tag \
127     changed_files \
128     docker_images \
129     <<< $( grep $specified_repo $release_data_file | tr ',' ' ' )
130
131 if [ ! "$repo" = "$specified_repo" ]
132 then
133     echo "repo '$specified_repo' not found in file 'pf_release_data.csv'"
134     exit 1
135 fi
136
137 next_release_version=${latest_snapshot_tag%-*}
138
139 while true
140 do
141    read -p "have you run 'stage_release' on the '$repo' repo? " yes_no
142    case $yes_no in
143        [Yy]* ) break
144         ;;
145
146        [Nn]* ) exit
147         ;;
148
149        * ) echo "Please answer 'yes' or 'no'"
150     ;;
151    esac
152 done
153
154 if [ "$docker_images" != "" ]
155 then
156     saved_current_dir=`pwd`
157     cd $repo_location/$repo
158     mkdock.sh `echo "$docker_images" | tr ':' " "`
159     cd $saved_current_dir
160 else
161     echo "repo '$repo' does not have any docker images"
162     exit 1
163 fi
164
165 echo "generating commit for $repo docker image release: $latest_released_tag-->$next_release_version . . ."
166
167 generateCommit.sh \
168     -l $repo_location \
169     -r $repo \
170     -i $issue_id \
171     -e "Release docker images for $repo: $next_release_version" \
172     -m "This commit releases docker images for repo $repo."
173
174 echo "commit for $repo docker image release: $latest_released_tag-->$next_release_version generated"