Skip to content

Commit

Permalink
Fix find_prev_release() in tools/release/common.sh returns incorrect …
Browse files Browse the repository at this point in the history
…tag (#4825)

* Checking previous release should not be sorted by taggeddate

Signed-off-by: Jon Kartago Lamida <[email protected]>

* Implement correct previous release finder

Signed-off-by: Jon Kartago Lamida <[email protected]>

* Update comment

Signed-off-by: Jon Kartago Lamida <[email protected]>

* Update tools/release/common.sh

Co-authored-by: Charles Korn <[email protected]>

---------

Signed-off-by: Jon Kartago Lamida <[email protected]>
Co-authored-by: George Krajcsovits <[email protected]>
Co-authored-by: Charles Korn <[email protected]>
  • Loading branch information
3 people authored Oct 20, 2023
1 parent aca8116 commit 50fdbdf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
20 changes: 15 additions & 5 deletions tools/release/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions tools/release/create-draft-release-notes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 50fdbdf

Please sign in to comment.