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