netbox-docker/build-latest.sh

86 lines
2.6 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
2018-03-05 14:29:24 +01:00
# Builds the latest released version
# Check if we have everything needed for the build
source ./build-functions/check-commands.sh
2023-01-28 15:42:32 +01:00
source ./build-functions/gh-functions.sh
2018-04-10 10:58:31 +02:00
echo "▶️ $0 $*"
2023-01-28 12:00:40 +01:00
CURL_ARGS=(
--silent
)
###
2023-01-28 12:00:40 +01:00
# Checking for the presence of GITHUB_TOKEN
###
2023-01-28 12:00:40 +01:00
if [ -n "${GITHUB_TOKEN}" ]; then
echo "🗝 Performing authenticated Github API calls."
2023-01-28 12:00:40 +01:00
CURL_ARGS+=(
--header "Authorization: Bearer ${GITHUB_TOKEN}"
)
else
echo "🕶 Performing unauthenticated Github API calls. This might result in lower Github rate limits!"
fi
###
# Checking if PRERELEASE is either unset, 'true' or 'false'
###
2019-10-15 00:40:48 +02:00
if [ -n "${PRERELEASE}" ] &&
2021-02-08 12:16:04 +01:00
{ [ "${PRERELEASE}" != "true" ] && [ "${PRERELEASE}" != "false" ]; }; then
2019-10-15 00:40:48 +02:00
if [ -z "${DEBUG}" ]; then
echo "⚠️ PRERELEASE must be either unset, 'true' or 'false', but was '${PRERELEASE}'!"
exit 1
else
2019-10-15 00:40:48 +02:00
echo "⚠️ Would exit here with code '1', but DEBUG is enabled."
fi
fi
###
# Calling Github to get the latest version
###
ORIGINAL_GITHUB_REPO="netbox-community/netbox"
GITHUB_REPO="${GITHUB_REPO-$ORIGINAL_GITHUB_REPO}"
2023-01-28 12:00:40 +01:00
URL_RELEASES="https://api.github.com/repos/${GITHUB_REPO}/releases"
# Composing the JQ commans to extract the most recent version number
JQ_LATEST="group_by(.prerelease) | .[] | sort_by(.published_at) | reverse | .[0] | select(.prerelease==${PRERELEASE-false}) | .tag_name"
2023-01-28 12:00:40 +01:00
CURL="curl"
# Querying the Github API to fetch the most recent version number
2023-01-28 12:00:40 +01:00
VERSION=$($CURL "${CURL_ARGS[@]}" "${URL_RELEASES}" | jq -r "${JQ_LATEST}" 2>/dev/null)
###
# 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"
2023-01-28 12:00:40 +01: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]\+\)')
2021-02-08 12:16:04 +01:00
if {
[ "${MAJOR_STABLE}" -eq "${MAJOR_UNSTABLE}" ] &&
[ "${MINOR_STABLE}" -ge "${MINOR_UNSTABLE}" ]
} || [ "${MAJOR_STABLE}" -gt "${MAJOR_UNSTABLE}" ]; then
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
2023-01-28 15:42:32 +01:00
gh_out "skipped=true"
2018-03-05 14:30:30 +01:00
exit 0
else
echo "⚠️ Would exit here with code '0', but DEBUG is enabled."
fi
fi
fi
# shellcheck disable=SC2068
./build.sh "${VERSION}" $@
exit $?