Skip to content

Commit 973124d

Browse files
authored
Autom8 release (#283)
* add automated-release targets * automate eks-charts pr
1 parent 6e2744e commit 973124d

File tree

6 files changed

+598
-2
lines changed

6 files changed

+598
-2
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,7 @@ jobs:
7575
os: windows
7676
install: choco install make && choco install zip
7777
script: RefreshEnv.cmd && make release-windows
78-
78+
- stage: EKS Charts Sync
79+
if: type = push AND tag =~ /^v\d+\.\d+(\.\d+)?(-\S*)?$/ AND env(GITHUB_TOKEN) IS present
80+
script: make ekscharts-sync-release
81+
name: Sync to EKS Charts

Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
VERSION = $(shell git describe --tags --always --dirty)
2+
LATEST_RELEASE_TAG=$(shell git describe --tags --abbrev=0)
3+
PREVIOUS_RELEASE_TAG=$(shell git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`)
4+
REPO_FULL_NAME=aws/aws-node-termination-handler
25
IMG ?= amazon/aws-node-termination-handler
36
IMG_TAG ?= ${VERSION}
47
IMG_W_TAG = ${IMG}:${IMG_TAG}
@@ -52,6 +55,15 @@ push-docker-images-windows:
5255
version:
5356
@echo ${VERSION}
5457

58+
latest-release-tag:
59+
@echo ${LATEST_RELEASE_TAG}
60+
61+
previous-release-tag:
62+
@echo ${PREVIOUS_RELEASE_TAG}
63+
64+
repo-full-name:
65+
@echo ${REPO_FULL_NAME}
66+
5567
image:
5668
@echo ${IMG_W_TAG}
5769

@@ -97,6 +109,12 @@ generate-k8s-yaml:
97109
sync-readme-to-dockerhub:
98110
${MAKEFILE_PATH}/scripts/sync-readme-to-dockerhub
99111

112+
ekscharts-sync:
113+
${MAKEFILE_PATH}/scripts/sync-to-aws-eks-charts -b ${BINARY_NAME} -r ${REPO_FULL_NAME}
114+
115+
ekscharts-sync-release:
116+
${MAKEFILE_PATH}/scripts/sync-to-aws-eks-charts -b ${BINARY_NAME} -r ${REPO_FULL_NAME} -n
117+
100118
unit-test:
101119
go test -bench=. ${MAKEFILE_PATH}/... -v -coverprofile=coverage.txt -covermode=atomic -outputdir=${BUILD_DIR_PATH}
102120

@@ -124,3 +142,30 @@ test: spellcheck shellcheck unit-test e2e-test compatibility-test license-test g
124142

125143
help:
126144
@grep -E '^[a-zA-Z_-]+:.*$$' $(MAKEFILE_LIST) | sort
145+
146+
## Targets intended to be run in preparation for a new release
147+
create-local-release-tag-major:
148+
${MAKEFILE_PATH}/scripts/create-local-tag-for-release -m
149+
150+
create-local-release-tag-minor:
151+
${MAKEFILE_PATH}/scripts/create-local-tag-for-release -i
152+
153+
create-local-release-tag-patch:
154+
${MAKEFILE_PATH}/scripts/create-local-tag-for-release -p
155+
156+
create-release-prep-pr:
157+
${MAKEFILE_PATH}/scripts/prepare-for-release
158+
159+
create-release-prep-pr-draft:
160+
${MAKEFILE_PATH}/scripts/prepare-for-release -d
161+
162+
release-prep-major: create-local-release-tag-major create-release-prep-pr
163+
164+
release-prep-minor: create-local-release-tag-minor create-release-prep-pr
165+
166+
release-prep-patch: create-local-release-tag-patch create-release-prep-pr
167+
168+
release-prep-custom: # Run make NEW_VERSION=v1.2.3 release-prep-custom to prep for a custom release version
169+
ifdef NEW_VERSION
170+
$(shell echo "${MAKEFILE_PATH}/scripts/create-local-tag-for-release -v $(NEW_VERSION) && echo && make create-release-prep-pr")
171+
endif

scripts/create-local-tag-for-release

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#!/bin/bash
2+
3+
# Script to create a new local tag in preparation for a release
4+
# This script is idempotent i.e. it always fetches remote tags to create the new tag.
5+
# E.g. If the current remote release tag is v1.0.0,
6+
## 1) running `create-local-tag-for-release -p` will create a new tag v1.0.1
7+
## 2) immediately running `create-local-tag-for-release -m` will create a new tag v2.0.0
8+
9+
set -euo pipefail
10+
11+
REPO_ROOT_PATH="$( cd "$(dirname "$0")"; cd ../; pwd -P )"
12+
MAKEFILE_PATH=$REPO_ROOT_PATH/Makefile
13+
TAG_REGEX="^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z]*)?$"
14+
15+
HELP=$(cat << 'EOM'
16+
Create a new local tag in preparation for a release. This script is idempotent i.e. it always fetches remote tags to create the new tag.
17+
18+
Usage: create-local-tag-for-release [options]
19+
20+
Options:
21+
-v new tag / version number. The script relies on the user to specify a valid and accurately incremented tag.
22+
-m increment major version
23+
-i increment minor version
24+
-p increment patch version
25+
-h help
26+
27+
Examples:
28+
create-local-tag-for-release -v v1.0.0 Create local tag for new version v1.0.0
29+
create-local-tag-for-release -i Create local tag for new version by incrementing minor version only (previous tag=v1.0.0, new tag=v1.1.0)
30+
EOM
31+
)
32+
33+
MAJOR_INC=false
34+
MINOR_INC=false
35+
PATCH_INC=false
36+
NEW_TAG=""
37+
CURR_REMOTE_RELEASE_TAG=""
38+
39+
process_args() {
40+
while getopts "hmipv:" opt; do
41+
case ${opt} in
42+
h )
43+
echo -e "$HELP" 1>&2
44+
exit 0
45+
;;
46+
m )
47+
MAJOR_INC=true
48+
;;
49+
i )
50+
MINOR_INC=true
51+
;;
52+
p )
53+
PATCH_INC=true
54+
;;
55+
v )
56+
NEW_TAG="${OPTARG}"
57+
;;
58+
\? )
59+
echo "$HELP" 1>&2
60+
exit 0
61+
;;
62+
esac
63+
done
64+
}
65+
66+
validate_args() {
67+
if [[ ! -z $NEW_TAG ]]; then
68+
if ! [[ $NEW_TAG =~ $TAG_REGEX ]]; then
69+
echo "❌ Invalid new tag specified $NEW_TAG. Examples: v1.2.3, v1.2.3-dirty"
70+
exit 1
71+
fi
72+
73+
echo "🥑 Using the new tag specified with -v flag. All other flags, if specified, will be ignored."
74+
echo " NOTE:The script relies on the user to specify a valid and accurately incremented tag."
75+
return
76+
fi
77+
78+
if ($MAJOR_INC && $MINOR_INC) || ($MAJOR_INC && $PATCH_INC) || ($MINOR_INC && $PATCH_INC); then
79+
echo "❌ Invalid arguments passed. Specify only one of 3 tag parts to increment for the new tag: -m (major) or -i (minor) or -p (patch)."
80+
exit 1
81+
fi
82+
83+
if $MAJOR_INC || $MINOR_INC || $PATCH_INC; then
84+
return
85+
fi
86+
87+
echo -e "❌ Invalid arguments passed. Specify atleast one argument.\n$HELP"
88+
exit 1
89+
}
90+
91+
sync_local_tags_from_remote() {
92+
# setup remote upstream tracking to fetch tags
93+
git remote add the-real-upstream https://github.com/aws/aws-node-termination-handler.git &> /dev/null || true
94+
git fetch the-real-upstream
95+
96+
# delete all local tags
97+
git tag -l | xargs git tag -d
98+
99+
# fetch remote tags
100+
git fetch the-real-upstream --tags
101+
102+
# record the latest release tag in remote, before creating a new tag
103+
CURR_REMOTE_RELEASE_TAG=$(get_latest_tag)
104+
105+
# clean up tracking
106+
git remote remove the-real-upstream
107+
}
108+
109+
create_tag() {
110+
git tag $NEW_TAG
111+
echo -e "\n✅ Created new tag $NEW_TAG (Current latest release tag in remote: v$CURR_REMOTE_RELEASE_TAG)\n"
112+
exit 0
113+
}
114+
115+
get_latest_tag() {
116+
make -s -f $MAKEFILE_PATH latest-release-tag | cut -b 2-
117+
}
118+
119+
main() {
120+
process_args "$@"
121+
validate_args
122+
123+
sync_local_tags_from_remote
124+
125+
# if new tag is specified, create it
126+
if [[ ! -z $NEW_TAG ]]; then
127+
create_tag
128+
fi
129+
130+
# increment version
131+
if $MAJOR_INC || $MINOR_INC || $PATCH_INC; then
132+
curr_major_v=$(echo $CURR_REMOTE_RELEASE_TAG | tr '.' '\n' | head -1)
133+
curr_minor_v=$(echo $CURR_REMOTE_RELEASE_TAG | tr '.' '\n' | head -2 | tail -1)
134+
curr_patch_v=$(echo $CURR_REMOTE_RELEASE_TAG | tr '.' '\n' | tail -1)
135+
136+
if [[ $MAJOR_INC == true ]]; then
137+
new_major_v=$(echo $(($curr_major_v + 1)))
138+
NEW_TAG=$(echo v$new_major_v.0.0)
139+
elif [[ $MINOR_INC == true ]]; then
140+
new_minor_v=$(echo $(($curr_minor_v + 1)))
141+
NEW_TAG=$(echo v$curr_major_v.$new_minor_v.0)
142+
elif [[ $PATCH_INC == true ]]; then
143+
new_patch_v=$(echo $(($curr_patch_v + 1)))
144+
NEW_TAG=$(echo v$curr_major_v.$curr_minor_v.$new_patch_v)
145+
fi
146+
create_tag
147+
fi
148+
}
149+
150+
main "$@"

0 commit comments

Comments
 (0)