Only build prerelease if version higher than stable

This commit is contained in:
Christian Mäder 2017-10-13 09:43:16 +02:00
parent d7ff6027e6
commit 7ed050316a
No known key found for this signature in database
GPG Key ID: 92FFD0A711F196BB

View File

@ -1,10 +1,28 @@
#!/bin/bash #!/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" 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}" $@ ./build.sh "${VERSION}" $@