@@ -12,10 +12,16 @@ REPO_ROOT_PATH="$( cd "$(dirname "$0")"; cd ../; pwd -P )"
12
12
MAKEFILE_PATH=$REPO_ROOT_PATH /Makefile
13
13
LATEST_VERSION=$( make -s -f $MAKEFILE_PATH latest-release-tag | cut -b 2- )
14
14
PREVIOUS_VERSION=$( make -s -f $MAKEFILE_PATH previous-release-tag | cut -b 2- )
15
+ MAJOR_INC=false
16
+ MINOR_INC=false
17
+ PATCH_INC=false
18
+ os=$( uname)
15
19
16
20
# files with versions, to update
17
21
REPO_README=$REPO_ROOT_PATH /README.md
18
22
CHART=$REPO_ROOT_PATH /config/helm/aws-node-termination-handler/Chart.yaml
23
+ CURR_CHART_VERSION=$( cat $CHART | grep ' version:' | xargs | cut -d' ' -f2 | tr -d ' [:space:]' )
24
+ UPDATED_CHART_VERSION=" "
19
25
CHART_VALUES=$REPO_ROOT_PATH /config/helm/aws-node-termination-handler/values.yaml
20
26
# ReadMe will be updated post-release due to long NTH release time
21
27
FILES=(" $CHART " " $CHART_VALUES " )
@@ -25,6 +31,7 @@ FILES_CHANGED=()
25
31
LATEST_TAG=" v$LATEST_VERSION "
26
32
NEW_BRANCH=" pr/$LATEST_TAG -release"
27
33
COMMIT_MESSAGE=" 🥑🤖 $LATEST_TAG release prep 🤖🥑"
34
+ RELEASE_PREP=true
28
35
29
36
# PR details
30
37
DEFAULT_REPO_FULL_NAME=$( make -s -f $MAKEFILE_PATH repo-full-name)
@@ -33,6 +40,9 @@ PR_TITLE="🥑🤖 $LATEST_TAG release prep"
33
40
PR_BODY=" 🥑🤖 Auto-generated PR for $LATEST_TAG release. Updating release versions in repo."
34
41
PR_LABEL_1=" release-prep"
35
42
PR_LABEL_2=" 🤖 auto-generated🤖"
43
+ EC2_BOT_USER=" ec2-bot 🤖"
44
+
45
+ EC2_BOT_SET=false
36
46
37
47
HELP=$( cat << 'EOM '
38
48
Update repo with the new release version and create a pr from a new release prep branch.
@@ -73,6 +83,7 @@ process_args() {
73
83
# release should be completed, so no longer prep
74
84
COMMIT_MESSAGE=" 🥑🤖 $LATEST_TAG release 🤖🥑"
75
85
PR_TITLE=" 🥑🤖 $LATEST_TAG release"
86
+ RELEASE_PREP=false
76
87
;;
77
88
r )
78
89
# todo: validate $REPO_FULL_NAME
@@ -98,6 +109,47 @@ MAGENTA=$(tput setaf 5)
98
109
RESET_FMT=$( tput sgr 0)
99
110
BOLD=$( tput bold)
100
111
112
+
113
+ determine_increment () {
114
+ prev=$1
115
+ updated=$2
116
+
117
+ prev_major_v=$( echo $prev | tr ' .' ' \n' | head -1)
118
+ prev_minor_v=$( echo $prev | tr ' .' ' \n' | head -2 | tail -1)
119
+ prev_patch_v=$( echo $prev | tr ' .' ' \n' | tail -1)
120
+ curr_major_v=$( echo $updated | tr ' .' ' \n' | head -1)
121
+ curr_minor_v=$( echo $updated | tr ' .' ' \n' | head -2 | tail -1)
122
+ curr_patch_v=$( echo $updated | tr ' .' ' \n' | tail -1)
123
+
124
+ if [[ " $prev_major_v " -ne " $curr_major_v " ]]; then
125
+ MAJOR_INC=true
126
+ elif [[ " $prev_minor_v " -ne " $curr_minor_v " ]]; then
127
+ MINOR_INC=true
128
+ elif [[ " $prev_patch_v " -ne " $curr_patch_v " ]]; then
129
+ PATCH_INC=true
130
+ fi
131
+ }
132
+
133
+ increment_chart () {
134
+ curr_chart_version=$1
135
+ curr_major_v=$( echo $curr_chart_version | tr ' .' ' \n' | head -1)
136
+ curr_minor_v=$( echo $curr_chart_version | tr ' .' ' \n' | head -2 | tail -1)
137
+ curr_patch_v=$( echo $curr_chart_version | tr ' .' ' \n' | tail -1)
138
+
139
+ if [[ $MAJOR_INC == true ]]; then
140
+ new_major_v=$( echo $(( $curr_major_v + 1 )) )
141
+ UPDATED_CHART_VERSION=$( echo $new_major_v .0.0)
142
+ elif [[ $MINOR_INC == true ]]; then
143
+ new_minor_v=$( echo $(( $curr_minor_v + 1 )) )
144
+ UPDATED_CHART_VERSION=$( echo $curr_major_v .$new_minor_v .0)
145
+ elif [[ $PATCH_INC == true ]]; then
146
+ new_patch_v=$( echo $(( $curr_patch_v + 1 )) )
147
+ UPDATED_CHART_VERSION=$( echo $curr_major_v .$curr_minor_v .$new_patch_v )
148
+ fi
149
+
150
+ echo $UPDATED_CHART_VERSION
151
+ }
152
+
101
153
# verify origin tracking before creating and pushing new branches
102
154
verify_origin_tracking () {
103
155
origin=$( git remote get-url origin 2>&1 ) || true
@@ -123,18 +175,30 @@ create_release_branch() {
123
175
update_versions () {
124
176
# update release version for release prep
125
177
echo -e " 🥑 Attempting to update NTH release version in preparation for a new release."
178
+ UPDATED_CHART_VERSION=$( increment_chart $CURR_CHART_VERSION )
126
179
127
180
for f in " ${FILES[@]} " ; do
128
181
# do not exit if grep doesn't find $PREVIOUS_VERSION; continue to exit on all other exit codes
129
182
has_incorrect_version=$( cat $f | grep $PREVIOUS_VERSION || [[ $? == 1 ]])
130
- if [[ ! -z $has_incorrect_version ]]; then
131
- sed -i ' ' " s/$PREVIOUS_VERSION /$LATEST_VERSION /g" $f
183
+ chart_should_increment=$( cat $f | grep $CURR_CHART_VERSION || [[ $? == 1 ]])
184
+ if [[ ! -z $has_incorrect_version ]] || [[ ! -z $chart_should_increment ]]; then
185
+ if [[ " ${os} " = " Linux" ]]; then
186
+ sed -i " s/$PREVIOUS_VERSION /$LATEST_VERSION /g" $f
187
+ sed -i " s/$CURR_CHART_VERSION /$UPDATED_CHART_VERSION /g" $f
188
+ elif [[ " ${os} " = " Darwin" ]]; then
189
+ sed -i ' ' " s/$PREVIOUS_VERSION /$LATEST_VERSION /g" $f
190
+ sed -i ' ' " s/$CURR_CHART_VERSION /$UPDATED_CHART_VERSION /g" $f
191
+ else
192
+ echo -e " ❌ ${RED} Platform ${os} does not support NTH release. Please use: Linux or macOS ${RESET_FMT} "
193
+ exit 1
194
+ fi
132
195
FILES_CHANGED+=(" $f " )
133
196
fi
134
197
done
135
198
136
199
if [[ ${# FILES_CHANGED[@]} -eq 0 ]]; then
137
200
echo -e " \nNo files were modified. Either all files already use git the latest release version $LATEST_VERSION or the files don't currently have the previous version $PREVIOUS_VERSION ."
201
+ exit 0
138
202
else
139
203
echo -e " ✅✅ ${BOLD} Updated versions from $PREVIOUS_VERSION to $LATEST_VERSION in files: \n$( echo " ${FILES_CHANGED[@]} " | tr ' ' ' \n' ) "
140
204
echo -e " To see changes, run \` git diff HEAD^ HEAD\` ${RESET_FMT} "
@@ -144,8 +208,11 @@ update_versions() {
144
208
145
209
commit_changes () {
146
210
echo -e " \n🥑 Adding and committing release version changes."
211
+ git config user.name " $EC2_BOT_USER "
212
+ git config user.email " $EC2_BOT_EMAIL "
213
+ EC2_BOT_SET=true
147
214
git add " ${FILES_CHANGED[@]} "
148
- git commit -m" $COMMIT_MESSAGE "
215
+ git commit -m " $COMMIT_MESSAGE "
149
216
echo -e " ✅✅✅ ${BOLD} Committed release prep changes to new branch $NEW_BRANCH with commit message '$COMMIT_MESSAGE '\n\n${RESET_FMT} "
150
217
}
151
218
@@ -164,14 +231,20 @@ confirm_with_user_and_create_pr(){
164
231
Changes in $NEW_BRANCH :
165
232
${MAGENTA} $( git diff HEAD^ HEAD) ${RESET_FMT}
166
233
EOM
167
- while true ; do
168
- read -p " 🥑${BOLD} Do you wish to create the release prep PR? Enter y/n " yn
169
- case $yn in
170
- [Yy]* ) create_pr; break ;;
171
- [Nn]* ) rollback; exit ;;
172
- * ) echo " 🥑Please answer yes or no." ;;
173
- esac
174
- done
234
+
235
+ # gh actions cannot respond to prompts
236
+ if [[ $RELEASE_PREP == true ]]; then
237
+ while true ; do
238
+ read -p " 🥑${BOLD} Do you wish to create the release prep PR? Enter y/n " yn
239
+ case $yn in
240
+ [Yy]* ) create_pr; break ;;
241
+ [Nn]* ) rollback; exit ;;
242
+ * ) echo " 🥑Please answer yes or no." ;;
243
+ esac
244
+ done
245
+ else
246
+ create_pr
247
+ fi
175
248
echo " ${RESET_FMT} "
176
249
}
177
250
@@ -215,6 +288,14 @@ rollback() {
215
288
# delete local and remote release branch only if current execution of the script created them
216
289
git branch -D $NEW_BRANCH
217
290
git push origin --delete $NEW_BRANCH
291
+
292
+ # if multiple user.name are set, then only the latest(ec2-bot) will be removed
293
+ if [[ $EC2_BOT_SET == true ]]; then
294
+ echo " 🥑${BOLD} Rolling back ec2-bot git config"
295
+ git config --unset user.name
296
+ git config --unset user.email
297
+ fi
298
+
218
299
fi
219
300
echo " ${RESET_FMT} "
220
301
}
@@ -230,11 +311,34 @@ handle_errors() {
230
311
exit $1
231
312
}
232
313
314
+ sync_local_tags_from_remote () {
315
+ # setup remote upstream tracking to fetch tags
316
+ git remote add the-real-upstream https://github.com/aws/aws-node-termination-handler.git & > /dev/null || true
317
+ git fetch the-real-upstream
318
+
319
+ # delete all local tags
320
+ git tag -l | xargs git tag -d
321
+
322
+ # fetch remote tags
323
+ git fetch the-real-upstream --tags
324
+
325
+ # clean up tracking
326
+ git remote remove the-real-upstream
327
+ }
328
+
233
329
main () {
234
330
process_args " $@ "
235
331
trap ' handle_errors $? $BASH_COMMAND' EXIT
236
332
237
333
verify_origin_tracking
334
+ sync_local_tags_from_remote
335
+
336
+ # if previous and latest version are equal, then the previous previous release versions may be present
337
+ if [[ $PREVIOUS_VERSION == " $LATEST_VERSION " ]]; then
338
+ PREVIOUS_VERSION=$( git tag -l --sort=-v:refname | sed -n ' 2 p' | cut -b 2-)
339
+ fi
340
+
341
+ determine_increment $PREVIOUS_VERSION $LATEST_VERSION
238
342
239
343
echo -e " 🥑 Attempting to create a release prep branch and PR with release version updates.\n Previous version: $PREVIOUS_VERSION ---> Latest version: $LATEST_VERSION "
240
344
create_release_branch
0 commit comments