From e5d196569cbda6f3967527c30982896717b69fd7 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Wed, 26 Jan 2022 18:25:40 +0100 Subject: [PATCH] ci: find relup base version using script scripts/relup-base-vsns.sh --- .github/workflows/build_packages.yaml | 6 +-- .github/workflows/run_fvt_tests.yaml | 7 +-- scripts/relup-base-vsns.sh | 71 +++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 9 deletions(-) create mode 100755 scripts/relup-base-vsns.sh diff --git a/.github/workflows/build_packages.yaml b/.github/workflows/build_packages.yaml index e2b3841a4..efae501e6 100644 --- a/.github/workflows/build_packages.yaml +++ b/.github/workflows/build_packages.yaml @@ -27,14 +27,12 @@ jobs: shell: bash run: | cd source - vsn="$(./pkg-vsn.sh)" - base_vsn_prefix="$(echo $vsn | grep -oE '^[0-9]+\.[0-9]+')" if make emqx-ee --dry-run > /dev/null 2>&1; then - old_vsns="$(git tag -l | grep -E "^e${base_vsn_prefix}\.[0-9]+$" | grep -v "e${vsn}" | xargs)" + old_vsns="$(./scripts/relup-base-vsns.sh enterprise | xargs)" echo "::set-output name=old_vsns::$old_vsns" echo "::set-output name=profiles::[\"emqx-ee\"]" else - old_vsns="$(git tag -l | grep -E "^v${base_vsn_prefix}\.[0-9]+$" | grep -v "v${vsn}" | xargs)" + old_vsns="$(./scripts/relup-base-vsns.sh community | xargs)" echo "::set-output name=old_vsns::$old_vsns" echo "::set-output name=profiles::[\"emqx\", \"emqx-edge\"]" fi diff --git a/.github/workflows/run_fvt_tests.yaml b/.github/workflows/run_fvt_tests.yaml index eab4e9e5a..6d4d94461 100644 --- a/.github/workflows/run_fvt_tests.yaml +++ b/.github/workflows/run_fvt_tests.yaml @@ -201,16 +201,13 @@ jobs: run: | cd emqx vsn="$(./pkg-vsn.sh)" - pre_vsn="$(echo $vsn | grep -oE '^[0-9]+.[0-9]')" - if make emqx-ee --dry-run > /dev/null 2>&1; then profile="emqx-ee" - old_vsns="$(git tag -l "e$pre_vsn.[0-9]" | xargs echo -n | sed "s/e$vsn//")" + old_vsns="$(./scripts/relup-base-vsns.sh enterprise | xargs)" broker="emqx-ee" - else profile="emqx" - old_vsns="$(git tag -l "v$pre_vsn.[0-9]" | xargs echo -n | sed "s/v$vsn//")" + old_vsns="$(./scripts/relup-base-vsns.sh community | xargs)" broker="emqx-ce" fi diff --git a/scripts/relup-base-vsns.sh b/scripts/relup-base-vsns.sh new file mode 100755 index 000000000..65d755994 --- /dev/null +++ b/scripts/relup-base-vsns.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +set -euo pipefail + +## This script prints the relup upgrade base versions +## for the given EMQ X edition (specified as first arg) +## +## The second argument is the current release version +## if not provided, it's taken from pkg-vsn.sh + +usage() { + echo "Usage: $0 []" + echo "e.g. $0 enterprise 4.3.10" + exit 1 +} + +parse_semver() { + echo "$1" | tr '.|-' ' ' +} + +PROFILE="${1:-}" +[ -z "${PROFILE}" ] && usage + +## Get the current release version +## e.g. +## 5.0.0 when GA +## 5.0.0-beta.3 when pre-release +## 5.0.0-beta.3.abcdef00 when developing +CUR="${2:-}" +if [ -z "${CUR}" ]; then + CUR="$(./pkg-vsn.sh)" +fi + +# shellcheck disable=SC2207 +CUR_SEMVER=($(parse_semver "$CUR")) + +if [ "${#CUR_SEMVER[@]}" -lt 3 ]; then + echo "$CUR is not Major.Minor.Patch" + usage +fi + +## when the current version has no suffix such as -abcdef00 +## it is a formal release +if [ "${#CUR_SEMVER[@]}" -eq 3 ]; then + IS_RELEASE=true +else + IS_RELEASE=false +fi + +case "${PROFILE}" in + *enterprise*) + GIT_TAG_PREFIX="e" + ;; + *) + GIT_TAG_PREFIX="v" + ;; +esac + +while read -r git_tag; do + # shellcheck disable=SC2207 + semver=($(parse_semver "$git_tag")) + if [ "${#semver[@]}" -eq 3 ] && [ "${semver[2]}" -le "${CUR_SEMVER[2]}" ]; then + if [ ${IS_RELEASE} = true ] && [ "${semver[2]}" -eq "${CUR_SEMVER[2]}" ] ; then + # do nothing + # exact match, do not print current version + # because current version is not an upgrade base + true + else + echo "$git_tag" + fi + fi +done < <(git tag -l "${GIT_TAG_PREFIX}${CUR_SEMVER[0]}.${CUR_SEMVER[1]}.*")