Created
February 19, 2021 09:28
-
-
Save tuxpeople/2624ddc4f132e0fe6d50fc988b91ab92 to your computer and use it in GitHub Desktop.
Shell - Get latest release from GitHub API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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