Skip to content

Commit

Permalink
sdfdf
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasge committed Jan 28, 2023
1 parent 1a4cc25 commit 4b42dd8
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions build-latest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ if ! command -v jq; then
exit 1
fi

CURL_ARGS=(
--silent
)

###
# Checking for the presence of GITHUB_OAUTH_CLIENT_ID
# and GITHUB_OAUTH_CLIENT_SECRET
# Checking for the presence of GITHUB_TOKEN
###
if [ -n "${GITHUB_TOKEN}" ]; then
echo "🗝 Performing authenticated Github API calls."
CURL_AUTH_HEADER="--header 'authorization: Bearer ${GITHUB_TOKEN}'"
CURL_ARGS+=(
--header 'Authorization: Bearer ${GITHUB_TOKEN}'
)
else
echo "🕶 Performing unauthenticated Github API calls. This might result in lower Github rate limits!"
CURL_AUTH_HEADER=""
fi

###
Expand All @@ -42,22 +46,22 @@ fi
###
ORIGINAL_GITHUB_REPO="netbox-community/netbox"
GITHUB_REPO="${GITHUB_REPO-$ORIGINAL_GITHUB_REPO}"
URL_RELEASES="https://api.github.com/repos/${GITHUB_REPO}/releases?"
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"

CURL="curl -sS ${CURL_AUTH_HEADER}"
CURL="curl"

# Querying the Github API to fetch the most recent version number
VERSION=$($CURL "${URL_RELEASES}" | jq -r "${JQ_LATEST}")
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"
STABLE_VERSION=$($CURL "${URL_RELEASES}" | jq -r "${JQ_STABLE}")
STABLE_VERSION=$($CURL "${CURL_ARGS[@]}" "${URL_RELEASES}" | jq -r "${JQ_STABLE}" 2>/dev/null)

# shellcheck disable=SC2003
MAJOR_STABLE=$(expr match "${STABLE_VERSION}" 'v\([0-9]\+\)')
Expand Down

0 comments on commit 4b42dd8

Please sign in to comment.