diff --git a/build/release/Makefile b/build/release/Makefile index c25af5fa1..64b8196cd 100644 --- a/build/release/Makefile +++ b/build/release/Makefile @@ -20,7 +20,6 @@ include ../makelib/helm.mk # ==================================================================================== # Options -LATEST_DOCS_BRANCH=release-1.10 CHANNEL ?= master ifeq ($(filter master release,$(CHANNEL)),) $(error invalid channel $(CHANNEL)) @@ -40,7 +39,7 @@ else DOCS_VERSION := $(shell echo $(BRANCH_NAME) | sed -E "s/^release\-([0-9]+)\.([0-9]+)$$/v\1.\2/g") endif -ifeq ($(shell echo $(BRANCH_NAME)),$(LATEST_DOCS_BRANCH)) +ifeq ($(shell echo $(BRANCH_NAME)),$(shell $(ROOT_DIR)/build/release/latest_release_branch.sh)) DOCS_VERSION_ALIAS := latest-release else DOCS_VERSION_ALIAS := diff --git a/build/release/latest_release_branch.sh b/build/release/latest_release_branch.sh new file mode 100755 index 000000000..b48098943 --- /dev/null +++ b/build/release/latest_release_branch.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -eEuo pipefail + +# Get list of release- branches +RELEASE_BRANCHES="$(git branch -r | grep -v mergify | grep '/release-' | cut -d'/' -f2 | sort | uniq)" +LATEST_RELEASE_BRANCH="" +MAX_TRIES=2 + +TRY=1 +until [ -n "${LATEST_RELEASE_BRANCH}" ] || [ ${TRY} -gt ${MAX_TRIES} ]; do + LATEST_RELEASE_BRANCH="$(echo "${RELEASE_BRANCHES}" | sort --version-sort | tail -n 1 | cut -d'/' -f2)" + BRANCH_VERSION="v$(echo "${LATEST_RELEASE_BRANCH}" | cut -d'-' -f2-)" + + # Get tags for the release version and filter out any alpha or beta versions + set +o pipefail + set +e + TAGS="$(git tag | grep -F "${BRANCH_VERSION}.0" | grep -Ev "alpha|beta")" + set -o pipefail + set -e + + # If the list is empty remove last line from $RELEASE_BRANCHES and + # clear $LATEST_RELEASE_BRANCH var + if [ -z "${TAGS}" ]; then + LATEST_RELEASE_BRANCH="" + RELEASE_BRANCHES="$(echo "${RELEASE_BRANCHES}" | sed '$d')" + fi + (( TRY++ )) +done + +if [ -z "${LATEST_RELEASE_BRANCH}" ]; then + echo "Failed to find latest released release branch!" + exit 1 +fi + +echo "${LATEST_RELEASE_BRANCH}"