blob: a0c48efec95a3f5c1947c19942fbf401a6658259 [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
liamfallond7d9a662022-03-01 21:01:03 +000023SCRIPT_NAME=$(basename "$0")
liamfallon81c2c512021-12-16 12:56:37 +000024repo_location="./"
25release_data_file="./pf_release_data.csv"
26
27usage()
28{
29 echo ""
30 echo "$SCRIPT_NAME - release the specified repository by generating the release yaml file and the release commit"
31 echo ""
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
49while getopts "hd:l:r:i:" opt
50do
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
72done
73
74if [ $OPTIND -eq 1 ]
75then
76 echo "no arguments were specified"
77 usage
78fi
79
80if [[ -z "$repo_location" ]]
81then
82 echo "policy repo location not specified on -l flag"
83 exit 1
84fi
85
86if ! [ -d "$repo_location" ]
87then
88 echo "policy repo location '$repo_location' not found"
89 exit 1
90fi
91
92if [[ -z "$release_data_file" ]]
93then
94 echo "policy release data file not specified on -d flag"
95 exit 1
96fi
97
98if ! [ -f "$release_data_file" ]
99then
100 echo "policy release data file '$release_data_file' not found"
101 exit 1
102fi
103
104if [ -z "$specified_repo" ]
105then
106 echo "repo not specified on -r flag"
107 exit 1
108fi
109
110if [ -z "$issue_id" ]
111then
112 echo "issue_id not specified on -i flag"
113 exit 1
114fi
115
116if ! echo "$issue_id" | grep -Eq '^POLICY-[0-9]*$'
117then
118 echo "issue ID is invalid, it should be of form 'POLICY-nnnn'"
119 exit 1
120fi
121
liamfallond7d9a662022-03-01 21:01:03 +0000122# shellcheck disable=SC2034
123# shellcheck disable=SC2046
124read -r repo \
liamfallon81c2c512021-12-16 12:56:37 +0000125 latest_released_tag \
126 latest_snapshot_tag \
liamfallond7d9a662022-03-01 21:01:03 +0000127 changed_files \
128 docker_images \
129 <<< $(grep "$specified_repo" "$release_data_file" | tr ',' ' ' )
liamfallon81c2c512021-12-16 12:56:37 +0000130
131if [ ! "$repo" = "$specified_repo" ]
132then
133 echo "repo '$specified_repo' not found in file 'pf_release_data.csv'"
134 exit 1
135fi
136
137next_release_version=${latest_snapshot_tag%-*}
138
139while true
140do
liamfallon41fc7252022-04-13 18:23:43 +0100141 read -r -p "have you run 'stage-release' on the '$repo' repo? " yes_no
liamfallon81c2c512021-12-16 12:56:37 +0000142 case $yes_no in
143 [Yy]* ) break
144 ;;
145
146 [Nn]* ) exit
147 ;;
148
149 * ) echo "Please answer 'yes' or 'no'"
150 ;;
151 esac
152done
153
liamfallond7d9a662022-03-01 21:01:03 +0000154saved_current_dir=$(pwd)
155cd "$repo_location/$repo" || exit 1
liamfallon81c2c512021-12-16 12:56:37 +0000156if [ "$docker_images" != "" ]
157then
liamfallond7d9a662022-03-01 21:01:03 +0000158 mkart_flag="-d"
liamfallon81c2c512021-12-16 12:56:37 +0000159else
liamfallond7d9a662022-03-01 21:01:03 +0000160 mkart_flag=""
liamfallon81c2c512021-12-16 12:56:37 +0000161fi
liamfallond7d9a662022-03-01 21:01:03 +0000162
163if ! mkart.sh "$mkart_flag"
164then
165 echo "generation of artifact release yaml file failed"
166 cd "$saved_current_dir" || exit 1
167 exit 1
168fi
169
170cd "$saved_current_dir" || exit 1
liamfallon81c2c512021-12-16 12:56:37 +0000171
172echo "generating commit for $repo release: $latest_released_tag-->$next_release_version . . ."
173
174generateCommit.sh \
liamfallond7d9a662022-03-01 21:01:03 +0000175 -l "$repo_location" \
176 -r "$repo" \
177 -i "$issue_id" \
liamfallon81c2c512021-12-16 12:56:37 +0000178 -e "Release $repo: $next_release_version" \
179 -m "This commit releases repo $repo."
180
181echo "commit for $repo release: $latest_released_tag-->$next_release_version generated"