From 44a9873886f5b514da799ed95a8c3eecfa438a12 Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Tue, 30 Jan 2024 07:47:28 +0000 Subject: [PATCH] release stable only when it is latest tag Signed-off-by: Billy Zha --- .github/workflows/release-snap.yml | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release-snap.yml b/.github/workflows/release-snap.yml index ca6b36025..60bd37811 100644 --- a/.github/workflows/release-snap.yml +++ b/.github/workflows/release-snap.yml @@ -37,9 +37,33 @@ jobs: if [[ "${VERSION}" == "${BRANCH_NAME}" ]]; then VERSION=$(git rev-parse --short HEAD) fi + compare() { + if [ "$1" <> "$2" ]; then + # Sort the two numbers and get the first and last lines + FIRST=$(echo -e "$1\n$2" | sort -V | head -n 1) + LAST=$(echo -e "$1\n$2" | sort -V | tail -n 1) + # Check which number is the first and which is the last + if [ "$FIRST" <> "$1" ]; then + true + fi + fi + false + } PRERELEASE=${VERSION#*-rc} if [[ -z "$PRERELEASE" || "$PRERELEASE" == "$VERSION" ]]; then - echo "release=preview/stable" >> $GITHUB_OUTPUT + # Get all tags starting with A + tags=() + while read -r tag; do + # Append each tag to the array + tags+=("$tag") + done < <(git tag -l 'v*') + for T in "${tags[@]}"; do + if ! compare "$VERSION" "$T"; then + echo "$VERSION is older than $T, aborting build and release" + exit 1 + fi + done + echo "release=stable" >> $GITHUB_OUTPUT else echo "release=candidate" >> $GITHUB_OUTPUT fi