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