Skip to content

Commit

Permalink
contrib/scripts: Support patch releases in print-downgrade-version.sh
Browse files Browse the repository at this point in the history
Script contrib/scripts/print-downgrade-version.sh is used to derive the
name of the previous stable branch, based on the current version number
found in the repository. This is useful for testing upgrades and
dowgrades in CI, between the current branch and the previous stable
branch.

For some tests we need to perform similar checks between the current tip
of a branch and the latest patch release on the branch. For example,
when working on branch 1.14, we want to downgrade to the latest patch
release, 1.14.3 at this time, then upgrade back to the tip of 1.14. On
the main branch, this is not relevant, because we don't usually have
patch releases on that branch.

The current commit updates print-downgrade-version.sh to add support for
patch releases. When a user pass "patch" as first argument to the patch,
then instead of decrementing the minor version by one, the script
decrements the patch release number by one, and prints the results.

When the patch release number is 0 (new minor release) or 90 (release
preparation), the script returns an error, because it is non-trivial to
find the preceding patch release number in such cases (at least without
Git and the Git history). From the workflow's perspective (for
supporting upgrades from patch releases in a follow-up commit), for new
minor releases, update/downgrade is already covered in this case by
working with the previous stable branch; and for 90, we just don't have
an easy way to retrieve the previous number. We make the script print
errors on stderr, in order to make it easier to compare the string
returned on stdout (empty in case of error).

Some examples of numbers from VERSION and the corresponding values
returned:

    VERSION         Previous minor  Previous patch release

    1.14.3          v1.13           v1.14.2
    1.14.1          v1.13           v1.14.0
    1.14.0          v1.13           <error>
    1.14.1-dev      v1.13           v1.14.0
    1.15.0-dev      v1.14           <error>
    1.13.90         v1.12           <error>

In order to test the script easily, this commit also allows setting
$VERSION from the command line, defaulting to the content of file
VERSION if no value is provided.

Let's also add the errexit and nounset options to the script.

Signed-off-by: Quentin Monnet <quentin@isovalent.com>
  • Loading branch information
qmonnet committed Nov 22, 2023
1 parent 9ecca98 commit 56dfec2
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions contrib/scripts/print-downgrade-version.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
#!/usr/bin/env bash
#
# A utility script to print the branch name of the previous stable release.
# A utility script to print the branch name of the previous stable or patch
# release.

set -o errexit
set -o nounset

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
VERSION="$(cat "$SCRIPT_DIR/../../VERSION")"
if [[ $VERSION =~ ([0-9^]+)\.([0-9^]+)\..* ]] ; then
VERSION=${VERSION-"$(cat "$SCRIPT_DIR/../../VERSION")"}
if [[ $VERSION =~ ([0-9^]+)\.([0-9^]+)\.([0-9^]+).* ]] ; then
major=${BASH_REMATCH[1]}
minor=${BASH_REMATCH[2]}
((minor--))
echo "v${major}.${minor}${BRANCH_SUFFIX:-}"
patch=${BASH_REMATCH[3]}
else
echo "ERROR: failed to parse version '$VERSION'"
>&2 echo "ERROR: failed to parse version '$VERSION'"
exit 1
fi

if [[ ${1-} == "patch" ]] ; then
# If user passed "patch" as first argument, print the latest patch version
case ${patch} in
0|90)
# Patch release number 90 is used for preparing releases.
>&2 echo "ERROR: failed to deduce patch release previous to version '$VERSION'"
exit 1
;;
*)
((patch--))
echo "v${major}.${minor}.${patch}${TAG_SUFFIX:-}"
;;
esac
else
# Else print the previous stable version by decrementing the minor version
# and trimming the patch version.
((minor--))
echo "v${major}.${minor}${BRANCH_SUFFIX:-}"
fi

0 comments on commit 56dfec2

Please sign in to comment.