From 7ed050316a183b5123a50cc8cd587cfd7b570a61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Fri, 13 Oct 2017 09:43:16 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Only=20build=20prerelease=20if=20ve?= =?UTF-8?q?rsion=20higher=20than=20stable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-latest.sh | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/build-latest.sh b/build-latest.sh index 7b79091..4a37237 100755 --- a/build-latest.sh +++ b/build-latest.sh @@ -1,10 +1,28 @@ #!/bin/bash -URL_LATEST=https://api.github.com/repos/digitalocean/netbox/releases +URL_RELEASES=https://api.github.com/repos/digitalocean/netbox/releases JQ_LATEST="group_by(.prerelease) | .[] | sort_by(.published_at) | reverse | .[0] | select(.prerelease==${PRERELEASE-false}) | .tag_name" -VERSION=$(curl "${URL_LATEST}" | jq -r "${JQ_LATEST}") +CURL_OPTS="-s" + +VERSION=$(curl $CURL_OPTS "${URL_RELEASES}" | jq -r "${JQ_LATEST}") + +# Check if the prerelease version is actually higher than stable version +if [ "${PRERELEASE}" == "true" ]; then + JQ_STABLE="group_by(.prerelease) | .[] | sort_by(.published_at) | reverse | .[0] | select(.prerelease==false) | .tag_name" + STABLE_VERSION=$(curl $CURL_OPTS "${URL_RELEASES}" | jq -r "${JQ_STABLE}") + + MAJOR_STABLE=$(expr match "${STABLE_VERSION}" 'v\([0-9]\+\)') + MINOR_STABLE=$(expr match "${STABLE_VERSION}" 'v[0-9]\+\.\([0-9]\+\)') + MAJOR_UNSTABLE=$(expr match "${VERSION}" 'v\([0-9]\+\)') + MINOR_UNSTABLE=$(expr match "${VERSION}" 'v[0-9]\+\.\([0-9]\+\)') + + if ( [ "$MAJOR_STABLE" -eq "$MAJOR_UNSTABLE" ] && [ "$MINOR_STABLE" -ge "$MINOR_UNSTABLE" ] ) \ + || [ "$MAJOR_STABLE" -gt "$MAJOR_UNSTABLE" ]; then + echo "Latest unstable version ('$VERSION') is not higher than the latest stable version ('$STABLE_VERSION')." + exit 0 + fi +fi ./build.sh "${VERSION}" $@ -