2017-09-29 11:38:19 +02:00
|
|
|
#!/bin/bash
|
2018-03-05 14:29:24 +01:00
|
|
|
# Builds the latest released version
|
2017-09-29 11:38:19 +02:00
|
|
|
|
2018-04-10 10:58:31 +02:00
|
|
|
echo "▶️ $0 $*"
|
|
|
|
|
2019-10-10 12:42:10 +02:00
|
|
|
###
|
|
|
|
# Checking for the presence of GITHUB_OAUTH_CLIENT_ID
|
|
|
|
# and GITHUB_OAUTH_CLIENT_SECRET
|
|
|
|
###
|
2019-02-01 09:58:07 +01:00
|
|
|
if [ -n "${GITHUB_OAUTH_CLIENT_ID}" ] && [ -n "${GITHUB_OAUTH_CLIENT_SECRET}" ]; then
|
2018-08-28 18:21:08 +02:00
|
|
|
echo "🗝 Performing authenticated Github API calls."
|
|
|
|
GITHUB_OAUTH_PARAMS="client_id=${GITHUB_OAUTH_CLIENT_ID}&client_secret=${GITHUB_OAUTH_CLIENT_SECRET}"
|
|
|
|
else
|
|
|
|
echo "🕶 Performing unauthenticated Github API calls. This might result in lower Github rate limits!"
|
|
|
|
GITHUB_OAUTH_PARAMS=""
|
|
|
|
fi
|
|
|
|
|
2019-10-10 12:42:10 +02:00
|
|
|
###
|
|
|
|
# Checking if PRERELEASE is either unset, 'true' or 'false'
|
|
|
|
###
|
2019-10-15 00:40:48 +02:00
|
|
|
if [ -n "${PRERELEASE}" ] &&
|
|
|
|
{ [ "${PRERELEASE}" != "true" ] && [ "${PRERELEAS}E" != "false" ]; }; then
|
2019-10-10 12:42:10 +02:00
|
|
|
|
2019-10-15 00:40:48 +02:00
|
|
|
if [ -z "${DEBUG}" ]; then
|
|
|
|
echo "⚠️ PRERELEASE must be either unset, 'true' or 'false', but was '${PRERELEASE}'!"
|
2019-10-10 12:42:10 +02:00
|
|
|
exit 1
|
|
|
|
else
|
2019-10-15 00:40:48 +02:00
|
|
|
echo "⚠️ Would exit here with code '1', but DEBUG is enabled."
|
2019-10-10 12:42:10 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
###
|
|
|
|
# Calling Github to get the latest version
|
|
|
|
###
|
2019-07-02 21:32:58 +02:00
|
|
|
ORIGINAL_GITHUB_REPO="netbox-community/netbox"
|
2018-01-30 11:22:43 +01:00
|
|
|
GITHUB_REPO="${GITHUB_REPO-$ORIGINAL_GITHUB_REPO}"
|
2018-08-28 18:21:08 +02:00
|
|
|
URL_RELEASES="https://api.github.com/repos/${GITHUB_REPO}/releases?${GITHUB_OAUTH_PARAMS}"
|
2017-09-29 11:38:19 +02:00
|
|
|
|
2019-10-10 12:42:10 +02:00
|
|
|
# Composing the JQ commans to extract the most recent version number
|
2017-10-02 11:08:50 +02:00
|
|
|
JQ_LATEST="group_by(.prerelease) | .[] | sort_by(.published_at) | reverse | .[0] | select(.prerelease==${PRERELEASE-false}) | .tag_name"
|
|
|
|
|
2018-03-05 14:29:24 +01:00
|
|
|
CURL="curl -sS"
|
2017-10-02 11:08:50 +02:00
|
|
|
|
2019-10-10 12:42:10 +02:00
|
|
|
# Querying the Github API to fetch the most recent version number
|
2018-01-30 11:22:43 +01:00
|
|
|
VERSION=$($CURL "${URL_RELEASES}" | jq -r "${JQ_LATEST}")
|
2017-10-13 09:43:16 +02:00
|
|
|
|
2019-10-10 12:42:10 +02:00
|
|
|
###
|
2017-10-13 09:43:16 +02:00
|
|
|
# Check if the prerelease version is actually higher than stable version
|
2019-10-10 12:42:10 +02:00
|
|
|
###
|
2017-10-13 09:43:16 +02:00
|
|
|
if [ "${PRERELEASE}" == "true" ]; then
|
|
|
|
JQ_STABLE="group_by(.prerelease) | .[] | sort_by(.published_at) | reverse | .[0] | select(.prerelease==false) | .tag_name"
|
2018-03-05 14:29:24 +01:00
|
|
|
STABLE_VERSION=$($CURL "${URL_RELEASES}" | jq -r "${JQ_STABLE}")
|
2017-10-13 09:43:16 +02:00
|
|
|
|
2018-03-05 14:29:24 +01:00
|
|
|
# shellcheck disable=SC2003
|
2017-10-13 09:43:16 +02:00
|
|
|
MAJOR_STABLE=$(expr match "${STABLE_VERSION}" 'v\([0-9]\+\)')
|
2018-03-05 14:29:24 +01:00
|
|
|
# shellcheck disable=SC2003
|
2017-10-13 09:43:16 +02:00
|
|
|
MINOR_STABLE=$(expr match "${STABLE_VERSION}" 'v[0-9]\+\.\([0-9]\+\)')
|
2018-03-05 14:29:24 +01:00
|
|
|
# shellcheck disable=SC2003
|
2017-10-13 09:43:16 +02:00
|
|
|
MAJOR_UNSTABLE=$(expr match "${VERSION}" 'v\([0-9]\+\)')
|
2018-03-05 14:29:24 +01:00
|
|
|
# shellcheck disable=SC2003
|
2017-10-13 09:43:16 +02:00
|
|
|
MINOR_UNSTABLE=$(expr match "${VERSION}" 'v[0-9]\+\.\([0-9]\+\)')
|
2017-09-29 11:38:19 +02:00
|
|
|
|
2019-10-15 00:40:48 +02:00
|
|
|
if { [ "${MAJOR_STABLE}" -eq "${MAJOR_UNSTABLE}" ] \
|
|
|
|
&& [ "${MINOR_STABLE}" -ge "${MINOR_UNSTABLE}" ];
|
|
|
|
} || [ "${MAJOR_STABLE}" -gt "${MAJOR_UNSTABLE}" ]; then
|
2019-10-10 12:42:10 +02:00
|
|
|
|
2019-10-15 00:40:48 +02:00
|
|
|
echo "❎ Latest unstable version '${VERSION}' is not higher than the latest stable version '$STABLE_VERSION'."
|
2018-03-05 14:30:30 +01:00
|
|
|
if [ -z "$DEBUG" ]; then
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo "⚠️ Would exit here with code '0', but DEBUG is enabled."
|
|
|
|
fi
|
2017-10-13 09:43:16 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-10-14 21:54:49 +02:00
|
|
|
# shellcheck disable=SC2068
|
|
|
|
./build.sh "${VERSION}" $@
|
|
|
|
exit $?
|