Last active
August 30, 2023 21:13
-
-
Save a-magdy/279341fcf87356f9372c024d1f6f9c8b to your computer and use it in GitHub Desktop.
Get node latest version for a major release
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
#!/bin/bash | |
MAJOR_VERSION=${1:-7} | |
# $1 => major release version (e.g. 6, 7) | |
dotnet_get_latest_version() { | |
if [[ -n "$1" ]] ; then | |
# Get latest by major version using jq | |
curl -s https://api.github.com/repos/dotnet/core/releases | jq -r '.[].tag_name | select(. | startswith("v'"${1:-7}"'."))' | head -n 1 | sed 's/v//g' | |
else | |
# Get default latest | |
curl -s https://api.github.com/repos/dotnet/core/releases/latest | jq -r .tag_name | sed 's/v//g' | |
fi | |
} | |
dotnet_get_latest_version "$MAJOR_VERSION" |
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
#!/bin/bash | |
MAJOR_VERSION=${1:-16} | |
# $1 => major release version (e.g. 14, 16, 18) | |
node_get_latest_version() { | |
[[ "$OSTYPE" == "darwin"* ]] && REGEX_ATTIRUBTE="e" || REGEX_ATTIRUBTE="P" # -P for linux-gnu, -e for darwin* | |
curl -s "https://nodejs.org/download/release/latest-v${1:-16}.x/" | grep -o -"${REGEX_ATTIRUBTE}" '>node-v.*.pkg' | cut -d'v' -f2 | sed 's/.pkg//g' | |
# # Alternative approach (using jq) | |
# if [[ -n "$1" ]] ; then | |
# # Get latest for major version | |
# curl -s https://nodejs.org/dist/index.json | jq -r '.[].version | select(. | startswith("v'"${1:-16}"'."))' | head -n 1 | sed 's/v//g' | |
# # curl -s https://api.github.com/repos/nodejs/node/releases | jq -r '.[] | select(.tag_name | startswith("v'"${1:-16}"'."))' | head -n 1 | sed 's/v//g' | |
# else | |
# # Get latest using jq | |
# curl -s https://api.github.com/repos/nodejs/node/releases/latest | jq -r .tag_name | sed 's/v//g' | |
# fi | |
} | |
node_get_latest_version "$MAJOR_VERSION" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment