Add script to gather data on release process
[policy/parent.git] / integration / src / release_scripts / generateCommit.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
26 usage()
27 {
28     echo ""
29     echo "$SCRIPT_NAME - generates a new commit or a patch on an existing commit for PF releases"
30     echo ""
31     echo "       usage:  $SCRIPT_NAME [-options]"
32     echo ""
33     echo "       options"
34     echo "         -h                - this help message"
35     echo "         -l location       - the location of the policy framework repos on the file system,"
36     echo "                             defaults to '$repo_location'"
37     echo "         -r repo           - the policy repo to which to commit"
38     echo "         -i issue-id       - issue ID in the format POLICY-nnnn"
39     echo "         -e commit-header  - the header for the commit"
40     echo "         -m commit-message - the message body for the commit"
41     echo ""
42     echo " example:"
43     echo "  $SCRIPT_NAME -l /home/git/onap -r policy/pap -i POLICY-1234 -e commit-header -m commit-message"
44     echo "    create a new commit or update an existing commit on policy/pap with the given details"
45     exit 255;
46 }
47
48 update_parent=false
49 update_common=false
50 update_models=false
51 update_drools_pdp=false
52 update_snapshot=false
53 update_docker=false
54
55 while getopts "hl:r:i:e:m:" opt
56 do
57     case $opt in
58     h)
59         usage
60         ;;
61     l)
62         repo_location=$OPTARG
63         ;;
64     r)
65         specified_repo=$OPTARG
66         ;;
67     i)
68         issue_id=$OPTARG
69         ;;
70     e)
71         commit_header=$OPTARG
72         ;;
73     m)
74         commit_message=$OPTARG
75         ;;
76     \?)
77         usage
78         exit 1
79         ;;
80     esac
81 done
82
83 if [ $OPTIND -eq 1 ]
84 then
85     echo "no arguments were specified"
86     usage
87 fi
88
89 if [[ -z "$repo_location" ]]
90 then
91     echo "policy repo location not specified on -l flag"
92     exit 1
93 fi
94 if ! [ -d "$repo_location" ]
95 then
96     echo "policy repo location '$repo_location' not found"
97     exit 1
98 fi
99
100 if [ -z "$specified_repo" ]
101 then
102     echo "repo not specified on -r flag"
103     exit 1
104 fi
105
106 if [ -z "$issue_id" ]
107 then
108     echo "issue_id not specified on -i flag"
109     exit 1
110 fi
111
112 if ! echo "$issue_id" | grep -Eq '^POLICY-[0-9]*$'
113 then
114   echo "issue ID is invalid, it should be of form 'POLICY-nnnn'"
115   exit 1
116 fi
117
118 if [ -z "$commit_header" ]
119 then
120     echo "commit_header not specified on -e flag"
121     exit 1
122 fi
123
124 if [ -z "$commit_message" ]
125 then
126     echo "commit_message not specified on -m flag"
127     exit 1
128 fi
129
130 git -C $repo_location/$specified_repo status | grep '^Your branch is up to date' > /dev/null 2>&1
131 return_code=$?
132
133 if [ $return_code -eq 0 ]
134 then
135     echo "generating commit '$commit_header' . . ."
136
137     commit_msg_temp_file=$(mktemp)
138     echo "$commit_header"                                           > $commit_msg_temp_file
139     echo ""                                                        >> $commit_msg_temp_file
140     echo "*** This commit is generated by a PF release script ***" >> $commit_msg_temp_file
141     echo ""                                                        >> $commit_msg_temp_file
142     echo "$commit_message"                                         >> $commit_msg_temp_file
143     echo ""                                                        >> $commit_msg_temp_file
144     echo "Issue-ID: $issue_id"                                     >> $commit_msg_temp_file
145
146     git -C $repo_location/$specified_repo add .
147     git -C $repo_location/$specified_repo commit -s -F "$commit_msg_temp_file"
148     rm $commit_msg_temp_file
149
150     echo "commit '$commit_header' generated"
151 else
152     echo "updating commit '$commit_header' . . ."
153
154     git -C $repo_location/$specified_repo add .
155     git -C $repo_location/$specified_repo commit -as --amend --no-edit
156
157     echo "commit '$commit_header' updated"
158 fi
159
160 echo "sending commit '$commit_header' to gerrit . . ."
161 git -C $repo_location/$specified_repo review
162 echo "commit '$commit_header' sent to gerrit . . ."
163
164