Skip to content

Commit 9090c17

Browse files
committed
Add a script to tag and push k0s releases
The script encapsulates the instructions in RELEASE.md and helps to create and push release tags in the way described. Signed-off-by: Tom Wieczorek <[email protected]>
1 parent c777ddc commit 9090c17

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed

RELEASE.md

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Once the release notes are done we can publish the release.
2525

2626
If for some reason there is an error triggering the action, it is safe to delete the tag remotely with `git push --delete origin <tag>` and push it again.
2727

28+
The above steps are encapsulated in the [`hack/release.sh`](hack/release.sh)
29+
shell script for convenience.
30+
2831
## Semver
2932

3033
We're following [semantic versioning](https://semver.org/) for version numbering. Currently we're working on 0.y.z series so the rules are interpreted in bit more relaxed way.

hack/release.sh

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/usr/bin/env sh
2+
3+
set -eu
4+
5+
print_usage() {
6+
cat <<EOF
7+
Usage: $0
8+
9+
Creates and pushes a k0s release tag by performing the following steps:
10+
11+
- Determine the Kubernetes version
12+
- Ask about RC and hotfix numbers
13+
- Construct the tag name from the above information
14+
- Create the tag and push it to the remote repository
15+
16+
OPTIONS:
17+
-h Show this message
18+
19+
ENVIRONMENT:
20+
K0S_SIGNED_TAG Used to optionally disable tag signing if set to
21+
'no'.
22+
EOF
23+
}
24+
25+
confirm_action() {
26+
printf '%s (Y/n) ' "$1"
27+
28+
while :; do
29+
read -r yn
30+
if [ -n "$yn" ]; then
31+
case "$yn" in
32+
y | Y) return 0 ;;
33+
n | N) return 1 ;;
34+
*) printf "To confirm, enter 'y', 'Y' or nothing at all, to decline, enter 'n' or 'N': " ;;
35+
esac
36+
else
37+
return 0
38+
fi
39+
done
40+
}
41+
42+
git_get_upstream_remote_for_local_branch() {
43+
baseBranchFullRef=$(git rev-parse --symbolic-full-name "$1")
44+
upstreamRemoteRef=$(git for-each-ref --format='%(upstream)' "$baseBranchFullRef")
45+
46+
case "$upstreamRemoteRef" in
47+
refs/remotes/*)
48+
upstreamRemoteBranch=${upstreamRemoteRef##"refs/remotes/"}
49+
echo "${upstreamRemoteBranch%/*}"
50+
;;
51+
esac
52+
}
53+
54+
git_get_current_branch_name() {
55+
git rev-parse --symbolic-full-name --abbrev-ref HEAD
56+
}
57+
58+
determine_k8s_version() {
59+
printf %s 'Kubernetes version: '
60+
set -- ./vars.sh kubernetes_version
61+
k8sVersion=$("$@" 2>/dev/null) || {
62+
retVal=$?
63+
echo Failed to determine Kuberntes version! 1>&2
64+
"$@"
65+
return $retVal
66+
}
67+
68+
echo "$k8sVersion"
69+
}
70+
71+
determine_git_base_branch() {
72+
printf %s 'Base git branch: '
73+
baseBranchName=$(git_get_current_branch_name)
74+
echo "$baseBranchName"
75+
}
76+
77+
determine_upstream_git_remote() {
78+
printf %s 'Upstream git remote: '
79+
upstreamRemote=$(git_get_upstream_remote_for_local_branch "$baseBranchName")
80+
if [ -n "$upstreamRemote" ]; then
81+
echo "$upstreamRemote"
82+
else
83+
echo N/A
84+
fi
85+
}
86+
87+
read_k0s_rc_version() {
88+
if confirm_action 'Is the next version a release candidate?'; then
89+
while :; do
90+
printf %s 'Please enter the release candidate number (e.g. 0, 1, 2, ...): '
91+
read -r k0sRc
92+
! [ "$k0sRc" -ge 0 ] 2>/dev/null || return 0
93+
done
94+
else
95+
k0sRc=''
96+
fi
97+
}
98+
99+
read_k0s_hotfix_version() {
100+
while :; do
101+
printf %s 'Please enter the k0s hotfix number (e.g. 0, 1, 2, ...): '
102+
read -r k0sHotfix
103+
! [ "$k0sHotfix" -ge 0 ] 2>/dev/null || return 0
104+
done
105+
}
106+
107+
construct_tag_name() {
108+
k0sTag="v$k8sVersion"
109+
[ -z "${k0sRc-}" ] || k0sTag="$k0sTag-rc.$k0sRc"
110+
k0sTag="$k0sTag+k0s.$k0sHotfix"
111+
}
112+
113+
create_tag() {
114+
set -- git tag -a -m "release $k0sTag"
115+
if [ "${K0S_SIGNED_TAG-}" != no ]; then
116+
set -- "$@" --sign
117+
confirm_action "About to create signed tag '$k0sTag' (disable with K0S_SIGNED_TAG=no). Okay?"
118+
else
119+
set -- "$@" --no-sign
120+
confirm_action "About to create unsigned tag '$k0sTag'. Okay?"
121+
fi
122+
123+
"$@" -- "$k0sTag"
124+
}
125+
126+
push_tag_to_upstream_remote() {
127+
git show "$k0sTag"
128+
if [ -n "$upstreamRemote" ]; then
129+
if confirm_action "Push the above tag '$k0sTag' to remote '$upstreamRemote'?"; then
130+
git push "$upstreamRemote" "$k0sTag"
131+
fi
132+
fi
133+
}
134+
135+
do_release() {
136+
determine_k8s_version
137+
determine_git_base_branch
138+
determine_upstream_git_remote
139+
read_k0s_rc_version
140+
read_k0s_hotfix_version
141+
construct_tag_name
142+
create_tag
143+
push_tag_to_upstream_remote
144+
}
145+
146+
if [ $# = 1 ] && [ "$1" = h ]; then
147+
print_usage
148+
exit 1
149+
fi
150+
151+
if [ $# != 0 ]; then
152+
print_usage >&2
153+
exit 1
154+
fi
155+
156+
do_release

0 commit comments

Comments
 (0)