Last active
October 26, 2021 22:29
-
-
Save brandond/001841d5d6dc08e8cb1423b420093b4d to your computer and use it in GitHub Desktop.
RKE2 release cut script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
set -o noglob | |
ORIGIN="${ORIGIN:-rancher}" | |
USERNAME="${USERNAME:-${USER}}" | |
print() { | |
echo -e "\033[0;32m$@\033[0m" >&2 | |
} | |
do_kube_proxy() { | |
local VERSION="$1" | |
local TAG="$2" | |
if [[ -z "${TAG}" ]]; then | |
print "Error: no hardened-kubernetes tag provided" | |
return | |
fi | |
pushd "$(go env GOPATH)/src/github.com/rancher/rke2-charts" 1>/dev/null | |
git fetch "${ORIGIN}" | |
git reset --hard &>/dev/null || true | |
git rebase --abort &>/dev/null || true | |
git clean -xffd &>/dev/null || true | |
git checkout -B "bump_rke2-kube-proxy-${VERSION}" "${ORIGIN}/main-source" &>/dev/null | |
PACKAGE="rke2-kube-proxy-${VERSION}" | |
APP_VERSION="$(cut -d- -f1-2 <<< "${TAG}")" | |
sed -Ei "s/version: .*/version: ${TAG}/" "packages/${PACKAGE}/charts/Chart.yaml" | |
sed -Ei "s/appVersion: .*/appVersion: ${APP_VERSION}/" "packages/${PACKAGE}/charts/Chart.yaml" | |
sed -Ei "s/tag: .*/tag: ${TAG}/" "packages/${PACKAGE}/charts/values.yaml" | |
sed -Ei "s/packageVersion: .*/packageVersion: 01/" "packages/${PACKAGE}/package.yaml" | |
git add "packages/${PACKAGE}" | |
git commit -sm "Bump ${PACKAGE} to ${TAG}" | |
git push --set-upstream "${USERNAME}" --force-with-lease | |
popd 1>/dev/null | |
} | |
do_hardened_kubernetes() { | |
local TAG="$1" | |
if [[ -z "${TAG}" ]]; then | |
print "Error: no hardened-kubernetes tag provided" | |
return | |
fi | |
APP_VERSION="$(cut -d- -f1-2 <<< "${TAG}")" | |
pushd "$(go env GOPATH)/src/github.com/rancher/image-build-kubernetes" 1>/dev/null | |
git fetch "${ORIGIN}" | |
git reset --hard &>/dev/null || true | |
git rebase --abort &>/dev/null || true | |
git clean -xffd &>/dev/null || true | |
git checkout "${ORIGIN}/master" &>/dev/null | |
EXISTING_TAG="$(git tag -l "${APP_VERSION}-build*" | tail -n 1)" | |
if [[ -z "${EXISTING_TAG}" ]]; then | |
print "Creating new tag ${TAG}" | |
git tag "${TAG}" | |
git push "${ORIGIN}" "refs/tags/${TAG}" | |
echo "${TAG}" | |
else | |
print "Using existing tag ${EXISTING_TAG}" | |
echo "${EXISTING_TAG}" | |
fi | |
popd 1>/dev/null | |
} | |
do_release_tag() { | |
local BRANCH="$1" | |
local BUMP_PATCH=$2 | |
print "\nDoing release for ${BRANCH}" | |
pushd "$(go env GOPATH)/src/github.com/rancher/rke2" 1>/dev/null | |
git fetch "${ORIGIN}" | |
TAG=$(git tag --merged "${ORIGIN}/${BRANCH}" --sort -committerdate | head -n1) | |
if [[ "${TAG}" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)([-+][a-zA-Z0-9]+)?([-+]rke2r[0-9]+)$ ]]; then | |
MAJOR=${BASH_REMATCH[1]} | |
MINOR=${BASH_REMATCH[2]} | |
PATCH=${BASH_REMATCH[3]} | |
RC=${BASH_REMATCH[4]} | |
RKE2_PATCH=${BASH_REMATCH[5]} | |
print "TAG=${TAG} parsed as MAJOR=${MAJOR} MINOR=${MINOR} PATCH=${PATCH} RC=${RC} RKE2_PATCH=${RKE2_PATCH}" | |
else | |
print "Couldn't match ${TAG}" | |
return | |
fi | |
if [[ "${BUMP_PATCH}" == "true" ]]; then | |
print "Incrementing PATCH and resetting RKE2_PATCH/RC" | |
((++PATCH)) | |
RC="-rc1" | |
RKE2_PATCH="+rke2r1" | |
else | |
if [[ -n "${RC}" ]]; then | |
print "Previous tag was an RC; incrementing RC" | |
NUM=$(grep -Eo '[[:digit:]]+$' <<<"${RC}") | |
((++NUM)) | |
RC="-rc${NUM}" | |
else | |
print "Previous tag was not RC; incrementing RKE2_PATCH and adding RC" | |
NUM=$(grep -Eo '[[:digit:]]+$' <<<"${RKE2_PATCH}") | |
((++NUM)) | |
RC="-rc1" | |
RKE2_PATCH="+rke2r${NUM}" | |
fi | |
fi | |
VERSION="v${MAJOR}.${MINOR}.${PATCH}${RC}${RKE2_PATCH}" | |
HEAD_COMMIT=$(git rev-parse --short "${ORIGIN}/${BRANCH}") | |
HEAD_MESSAGE=$(git show --quiet "${HEAD_COMMIT}") | |
print "\nHead of ${BRANCH} is:\n---\n${HEAD_MESSAGE}\n---\n" | |
print "Ready to tag:\n\tgit tag ${VERSION} ${HEAD_COMMIT} && git push ${ORIGIN} refs/tags/${VERSION}" | |
} | |
do_release_branch() { | |
local BRANCH="$1" | |
local BUMP_PATCH=$2 | |
print "\nDoing release for ${BRANCH}" | |
pushd "$(go env GOPATH)/src/github.com/rancher/rke2" 1>/dev/null | |
git fetch "${ORIGIN}" | |
TAG=$(git tag --merged "${ORIGIN}/${BRANCH}" --sort -committerdate | head -n1) | |
if [[ "${TAG}" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)([-+][a-zA-Z0-9]+)?([-+]rke2r[0-9]+)$ ]]; then | |
MAJOR=${BASH_REMATCH[1]} | |
MINOR=${BASH_REMATCH[2]} | |
PATCH=${BASH_REMATCH[3]} | |
RC=${BASH_REMATCH[4]} | |
RKE2_PATCH=${BASH_REMATCH[5]} | |
print "TAG=${TAG} parsed as MAJOR=${MAJOR} MINOR=${MINOR} PATCH=${PATCH} RC=${RC} RKE2_PATCH=${RKE2_PATCH}" | |
else | |
print "Couldn't match ${TAG}" | |
return | |
fi | |
if [[ "${BUMP_PATCH}" == "true" ]]; then | |
print "Incrementing PATCH and resetting RKE2_PATCH/RC" | |
((++PATCH)) | |
RC="-rc1" | |
RKE2_PATCH="+rke2r1" | |
else | |
if [[ -n "${RC}" ]]; then | |
print "Previous tag was an RC; incrementing RC" | |
NUM=$(grep -Eo '[[:digit:]]+$' <<<"${RC}") | |
((++NUM)) | |
RC="-rc${NUM}" | |
else | |
print "Previous tag was not RC; incrementing RKE2_PATCH and adding RC" | |
NUM=$(grep -Eo '[[:digit:]]+$' <<<"${RKE2_PATCH}") | |
((++NUM)) | |
RC="-rc1" | |
RKE2_PATCH="+rke2r${NUM}" | |
fi | |
fi | |
BUILD_DATE=$(TZ=utc date '+-build%Y%m%d') | |
VERSION="v${MAJOR}.${MINOR}.${PATCH}${RC}${RKE2_PATCH}" | |
KUBERNETES_TAG=$(tr + - <<< "v${MAJOR}.${MINOR}.${PATCH}${RKE2_PATCH}${BUILD_DATE}") | |
print "Preparing for ${VERSION} with hardened kubernetes ${KUBERNETES_TAG}" | |
git reset --hard &>/dev/null || true | |
git rebase --abort &>/dev/null || true | |
git clean -xffd &>/dev/null || true | |
git checkout -B "rke2_bump_${BRANCH}" "${ORIGIN}/${BRANCH}" &>/dev/null | |
KUBERNETES_TAG="$(do_hardened_kubernetes "${KUBERNETES_TAG}")" | |
if [[ "${MINOR}" -le "21" ]]; then | |
do_kube_proxy "${MAJOR}.${MINOR}" "${KUBERNETES_TAG}" | |
fi | |
sed -Ei "s/:v.*rke2.*[0-9]+/:${KUBERNETES_TAG}/" Dockerfile | |
sed -Ei "s/v.*rke2.*[0-9]+/${KUBERNETES_TAG}/" pkg/images/images.go | |
sed -Ei "s/CHART_VERSION=\"v.*rke2.*[0-9]+/CHART_VERSION=\"${KUBERNETES_TAG}01/" Dockerfile | |
sed -Ei "s/KUBERNETES_VERSION:.*[0-9]+/KUBERNETES_VERSION:-v${MAJOR}.${MINOR}.${PATCH}/" scripts/version.sh | |
sed -Ei "s/KUBERNETES_IMAGE_TAG:-.*[0-9]+/KUBERNETES_IMAGE_TAG:-${KUBERNETES_TAG}/" scripts/version.sh | |
git add Dockerfile pkg/images/images.go scripts/version.sh | |
git commit -sm "Bump RKE2 to ${VERSION}" | |
git push --set-upstream "${USERNAME}" --force-with-lease | |
popd 1>/dev/null | |
} | |
for BRANCH in ${BRANCHES:-master release-1.21 release-1.20 release-1.19}; do | |
case "${ACTION:-bump}" in | |
bump) | |
do_release_branch "${BRANCH}" "${BUMP_PATCH:-false}" || true | |
;; | |
tag) | |
do_release_tag "${BRANCH}" | |
;; | |
*) | |
echo "Invalid action" | |
exit 1 | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment