diff --git a/tools/release/common.sh b/tools/release/common.sh index 75de0fb1c0..6d057ba123 100755 --- a/tools/release/common.sh +++ b/tools/release/common.sh @@ -6,6 +6,9 @@ set -e +# Use GNU sed on MacOS falling back to `sed` everywhere else +SED=$(which gsed || which sed) + check_required_setup() { # Ensure "gh" tool is installed. if ! command -v gh &> /dev/null; then @@ -22,8 +25,9 @@ check_required_setup() { fi } +# Last release is the version we want to release now. find_last_release() { - LAST_RELEASE_TAG=$(git tag --list --sort=taggerdate 'mimir-[0-9]*' | tail -1) + LAST_RELEASE_TAG=$(git describe --abbrev=0 --match 'mimir-[0-9]*') if [ -z "${LAST_RELEASE_TAG}" ]; then echo "Unable to find the last release git tag" > /dev/stderr @@ -38,15 +42,21 @@ find_last_release() { export LAST_RELEASE_VERSION } -# Find the previous release. If the last release is a stable release then it only takes in account stable releases -# (the previous release of a stable release must be another stable release). +# Previous release is one version before last release. +# If last release is an rc, previous release can be any rc or non-rc. +# If last release is a stable (non-rc) release, previous release must be a non-rc release. find_prev_release() { find_last_release + ALL_RELEASE_TAGS=$(git tag --list 'mimir-[0-9]*') + + # To sort rc version correctly we use sed to append non-rc version with a temporary suffix + SORTED_RELEASE_TAGS=$(echo "$ALL_RELEASE_TAGS" | $SED '/rc/b; s/\(.*\)/\1-xx.x/' | sort --version-sort | $SED 's/-xx.x//') + if [[ $LAST_RELEASE_VERSION =~ "-rc" ]]; then - PREV_RELEASE_TAG=$(git tag --list --sort=taggerdate 'mimir-[0-9]*' | tail -2 | head -1) + PREV_RELEASE_TAG=$(echo "$SORTED_RELEASE_TAGS" | grep $(echo $LAST_RELEASE_VERSION) -B1 | head -1) else - PREV_RELEASE_TAG=$(git tag --list --sort=taggerdate 'mimir-[0-9]*' | grep -v -- '-rc' | tail -2 | head -1) + PREV_RELEASE_TAG=$(echo "$SORTED_RELEASE_TAGS" | grep -v -- '-rc' | grep $(echo $LAST_RELEASE_VERSION) -B1 | head -1) fi if [ -z "${PREV_RELEASE_TAG}" ]; then diff --git a/tools/release/create-draft-release-notes.sh b/tools/release/create-draft-release-notes.sh index fb6ed92487..b67baa66bd 100755 --- a/tools/release/create-draft-release-notes.sh +++ b/tools/release/create-draft-release-notes.sh @@ -3,9 +3,6 @@ set -e -# Use GNU sed on MacOS falling back to `sed` everywhere else -SED=$(which gsed || which sed) - # Load common lib. CURR_DIR="$(dirname "$0")" . "${CURR_DIR}/common.sh"