Skip to content

Instantly share code, notes, and snippets.

@tuxpeople
Created February 19, 2021 09:28
Show Gist options
  • Save tuxpeople/2624ddc4f132e0fe6d50fc988b91ab92 to your computer and use it in GitHub Desktop.
Save tuxpeople/2624ddc4f132e0fe6d50fc988b91ab92 to your computer and use it in GitHub Desktop.
Shell - Get latest release from GitHub API
# This gets the newest release version from a project.
# Even if they to not set the "latest" tag.
# And even if they release multiple version paths.
# Needs jq.
#
# Usage:
# $ get_latest_release "rancher/rke"
#
get_latest_release() {
curl --silent "https://api.github.com/repos/$1/releases" | # Get releases from GitHub api
jq -r '.[] | select(.prerelease == false) | select(.draft == false) | .tag_name' | # Get tags for releases not draft and not prerelease
sort -r | head -1 # Sort the tags highest first, then get the first one
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment