Skip to content

Commit e7fab60

Browse files
authored
fix release prep for gh actions (#343)
* fix release prep for gh actions * increment AEMM to latest ecr image
1 parent 2fc3b75 commit e7fab60

File tree

4 files changed

+121
-14
lines changed

4 files changed

+121
-14
lines changed

scripts/draft-release-notes

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ fi
1919
echo "## Changes" | tee -a "${RELEASE_NOTES}"
2020
for change in $(git rev-list $LAST_RELEASE_HASH..HEAD); do
2121
one_line_msg=$(git --no-pager log --pretty='%s (thanks to %an)' "${change}" -n1 | sed 's/^\[.*\]//' | xargs)
22-
echo " - ${one_line_msg}" | tee -a "${RELEASE_NOTES}"
22+
# render markdown links for cross-posting release notes
23+
pr_num=$(echo $one_line_msg | grep -Eo '(#[0-9]*)' || [[ $? == 1 ]])
24+
md_link="[$pr_num](https://github.com/aws/aws-node-termination-handler/pull/${pr_num:1})"
25+
echo " - ${one_line_msg/\($pr_num\)/$md_link}" | tee -a "${RELEASE_NOTES}"
2326
done
2427

2528
>&2 echo -e "\n\nRelease notes file: ${RELEASE_NOTES}"

scripts/prepare-for-release

Lines changed: 115 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ REPO_ROOT_PATH="$( cd "$(dirname "$0")"; cd ../; pwd -P )"
1212
MAKEFILE_PATH=$REPO_ROOT_PATH/Makefile
1313
LATEST_VERSION=$(make -s -f $MAKEFILE_PATH latest-release-tag | cut -b 2- )
1414
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)
1519

1620
# files with versions, to update
1721
REPO_README=$REPO_ROOT_PATH/README.md
1822
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=""
1925
CHART_VALUES=$REPO_ROOT_PATH/config/helm/aws-node-termination-handler/values.yaml
2026
# ReadMe will be updated post-release due to long NTH release time
2127
FILES=("$CHART" "$CHART_VALUES")
@@ -25,6 +31,7 @@ FILES_CHANGED=()
2531
LATEST_TAG="v$LATEST_VERSION"
2632
NEW_BRANCH="pr/$LATEST_TAG-release"
2733
COMMIT_MESSAGE="🥑🤖 $LATEST_TAG release prep 🤖🥑"
34+
RELEASE_PREP=true
2835

2936
# PR details
3037
DEFAULT_REPO_FULL_NAME=$(make -s -f $MAKEFILE_PATH repo-full-name)
@@ -33,6 +40,9 @@ PR_TITLE="🥑🤖 $LATEST_TAG release prep"
3340
PR_BODY="🥑🤖 Auto-generated PR for $LATEST_TAG release. Updating release versions in repo."
3441
PR_LABEL_1="release-prep"
3542
PR_LABEL_2="🤖 auto-generated🤖"
43+
EC2_BOT_USER="ec2-bot 🤖"
44+
EC2_BOT_EMAIL="[email protected]"
45+
EC2_BOT_SET=false
3646

3747
HELP=$(cat << 'EOM'
3848
Update repo with the new release version and create a pr from a new release prep branch.
@@ -73,6 +83,7 @@ process_args() {
7383
# release should be completed, so no longer prep
7484
COMMIT_MESSAGE="🥑🤖 $LATEST_TAG release 🤖🥑"
7585
PR_TITLE="🥑🤖 $LATEST_TAG release"
86+
RELEASE_PREP=false
7687
;;
7788
r )
7889
# todo: validate $REPO_FULL_NAME
@@ -98,6 +109,47 @@ MAGENTA=$(tput setaf 5)
98109
RESET_FMT=$(tput sgr 0)
99110
BOLD=$(tput bold)
100111

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+
101153
# verify origin tracking before creating and pushing new branches
102154
verify_origin_tracking() {
103155
origin=$(git remote get-url origin 2>&1) || true
@@ -123,18 +175,30 @@ create_release_branch() {
123175
update_versions() {
124176
# update release version for release prep
125177
echo -e "🥑 Attempting to update NTH release version in preparation for a new release."
178+
UPDATED_CHART_VERSION=$(increment_chart $CURR_CHART_VERSION)
126179

127180
for f in "${FILES[@]}"; do
128181
# do not exit if grep doesn't find $PREVIOUS_VERSION; continue to exit on all other exit codes
129182
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
132195
FILES_CHANGED+=("$f")
133196
fi
134197
done
135198

136199
if [[ ${#FILES_CHANGED[@]} -eq 0 ]]; then
137200
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
138202
else
139203
echo -e "✅✅ ${BOLD}Updated versions from $PREVIOUS_VERSION to $LATEST_VERSION in files: \n$(echo "${FILES_CHANGED[@]}" | tr ' ' '\n')"
140204
echo -e "To see changes, run \`git diff HEAD^ HEAD\`${RESET_FMT}"
@@ -144,8 +208,11 @@ update_versions() {
144208

145209
commit_changes() {
146210
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
147214
git add "${FILES_CHANGED[@]}"
148-
git commit -m"$COMMIT_MESSAGE"
215+
git commit -m "$COMMIT_MESSAGE"
149216
echo -e "✅✅✅ ${BOLD}Committed release prep changes to new branch $NEW_BRANCH with commit message '$COMMIT_MESSAGE'\n\n${RESET_FMT}"
150217
}
151218

@@ -164,14 +231,20 @@ confirm_with_user_and_create_pr(){
164231
Changes in $NEW_BRANCH:
165232
${MAGENTA}$(git diff HEAD^ HEAD)${RESET_FMT}
166233
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
175248
echo "${RESET_FMT}"
176249
}
177250

@@ -215,6 +288,14 @@ rollback() {
215288
# delete local and remote release branch only if current execution of the script created them
216289
git branch -D $NEW_BRANCH
217290
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+
218299
fi
219300
echo "${RESET_FMT}"
220301
}
@@ -230,11 +311,34 @@ handle_errors() {
230311
exit $1
231312
}
232313

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+
233329
main() {
234330
process_args "$@"
235331
trap 'handle_errors $? $BASH_COMMAND' EXIT
236332

237333
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
238342

239343
echo -e "🥑 Attempting to create a release prep branch and PR with release version updates.\n Previous version: $PREVIOUS_VERSION ---> Latest version: $LATEST_VERSION"
240344
create_release_branch

test/eks-cluster-test/run-test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
66
PRESERVE=true
77

88
export TEST_WINDOWS="false"
9-
export AEMM_VERSION="1.7.0"
9+
export AEMM_VERSION="1.8.1"
1010
export AEMM_DL_URL="https://github.com/aws/amazon-ec2-metadata-mock/releases/download/v$AEMM_VERSION/amazon-ec2-metadata-mock-$AEMM_VERSION.tgz"
1111
export CLUSTER_CONFIG_FILE=$SCRIPTPATH/cluster-spec.yaml
1212

test/k8s-local-cluster-test/run-test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ WEBHOOK_DOCKER_IMG=""
1818
OVERRIDE_PATH=0
1919
K8S_VERSION="1.16"
2020
AEMM_URL="amazon-ec2-metadata-mock-service.default.svc.cluster.local"
21-
AEMM_VERSION="1.7.0"
21+
AEMM_VERSION="1.8.1"
2222
AEMM_DL_URL="https://github.com/aws/amazon-ec2-metadata-mock/releases/download/v$AEMM_VERSION/amazon-ec2-metadata-mock-$AEMM_VERSION.tgz"
2323
WEBHOOK_URL=${WEBHOOK_URL:="http://webhook-test-proxy.default.svc.cluster.local"}
2424

0 commit comments

Comments
 (0)