blob: c2aa95a441dbf6a53b4001a562a42c994c1a982b [file] [log] [blame]
liamfallon81c2c512021-12-16 12:56:37 +00001#!/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
23set -e
24
25SCRIPT_NAME=`basename $0`
26repo_location="./"
27release_data_file="./pf_release_data.csv"
28
29usage()
30{
31 echo ""
32 echo "$SCRIPT_NAME - release the specified repository by generating the release yaml file and the release commit"
33 echo ""
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
51while getopts "hd:l:r:i:" opt
52do
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
74done
75
76if [ $OPTIND -eq 1 ]
77then
78 echo "no arguments were specified"
79 usage
80fi
81
82if [[ -z "$repo_location" ]]
83then
84 echo "policy repo location not specified on -l flag"
85 exit 1
86fi
87
88if ! [ -d "$repo_location" ]
89then
90 echo "policy repo location '$repo_location' not found"
91 exit 1
92fi
93
94if [[ -z "$release_data_file" ]]
95then
96 echo "policy release data file not specified on -d flag"
97 exit 1
98fi
99
100if ! [ -f "$release_data_file" ]
101then
102 echo "policy release data file '$release_data_file' not found"
103 exit 1
104fi
105
106if [ -z "$specified_repo" ]
107then
108 echo "repo not specified on -r flag"
109 exit 1
110fi
111
112if [ -z "$issue_id" ]
113then
114 echo "issue_id not specified on -i flag"
115 exit 1
116fi
117
118if ! echo "$issue_id" | grep -Eq '^POLICY-[0-9]*$'
119then
120 echo "issue ID is invalid, it should be of form 'POLICY-nnnn'"
121 exit 1
122fi
123
124read repo \
125 latest_released_tag \
126 latest_snapshot_tag \
127 changed_files docker_images \
128 <<< $( grep $specified_repo $release_data_file | tr ',' ' ' )
129
130if [ ! "$repo" = "$specified_repo" ]
131then
132 echo "repo '$specified_repo' not found in file 'pf_release_data.csv'"
133 exit 1
134fi
135
136next_release_version=${latest_snapshot_tag%-*}
137
138while true
139do
140 read -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
151done
152
153saved_current_dir=`pwd`
154cd $repo_location/$repo
155if [ "$docker_images" != "" ]
156then
157 mkart.sh -d
158else
159 mkart.sh
160fi
161cd $saved_current_dir
162
163echo "generating commit for $repo release: $latest_released_tag-->$next_release_version . . ."
164
165generateCommit.sh \
166 -l $repo_location \
167 -r $repo \
168 -i $issue_id \
169 -e "Release $repo: $next_release_version" \
170 -m "This commit releases repo $repo."
171
172echo "commit for $repo release: $latest_released_tag-->$next_release_version generated"