Merge pull request #6873 from zmstone/ci-find-relup-base-using-a-script

ci: find relup base version using a script
This commit is contained in:
Zaiming (Stone) Shi 2022-01-26 20:51:46 +01:00 committed by GitHub
commit bf8d30f4f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 6 deletions

View File

@ -36,12 +36,8 @@ jobs:
shell: bash shell: bash
working-directory: source working-directory: source
run: | run: |
ce_vsn="$(./pkg-vsn.sh community)" ce_old_vsns="$(./scripts/relup-base-vsns.sh community | xargs)"
ee_vsn="$(./pkg-vsn.sh enterprise)" ee_old_vsns="$(./scripts/relup-base-vsns.sh enterprise | xargs)"
ce_base_vsn_prefix="$(echo $ce_vsn | grep -oE '^[0-9]+\.[0-9]+')"
ee_base_vsn_prefix="$(echo $ee_vsn | grep -oE '^[0-9]+\.[0-9]+')"
ce_old_vsns="$(git tag -l | grep -E "v${ce_base_vsn_prefix}\.[0-9]+$" | grep -v "v${ee_vsn}" | xargs)"
ee_old_vsns="$(git tag -l | grep -E "e${ee_base_vsn_prefix}\.[0-9]+$" | grep -v "e${ee_vsn}" | xargs)"
echo "::set-output name=ce_old_vsns::${ce_old_vsns}" echo "::set-output name=ce_old_vsns::${ce_old_vsns}"
echo "::set-output name=ee_old_vsns::${ee_old_vsns}" echo "::set-output name=ee_old_vsns::${ee_old_vsns}"
- name: get_all_deps - name: get_all_deps

71
scripts/relup-base-vsns.sh Executable file
View File

@ -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 <EMQX_PROFILE> [<CURRENT_VERSION>]"
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 "$PROFILE")"
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]}.*")