github.com/vnforks/kid/v5@v5.22.1-0.20200408055009-b89d99c65676/scripts/get_latest_release.sh (about) 1 #!/usr/bin/env bash 2 # $1 - repo to check against 3 # $2 - release branch pattern to match 4 # This script will check if the current repo has version pattern $2 ('release-5.20') in the branch name. 5 # If it does it will check for a matching release version in the $1 repo and if found check for the newest dot version. 6 # If the branch pattern isn't found than it will default to the newest release available in $1. 7 REPO_TO_USE=$1 8 BRANCH_TO_USE=$2 9 10 LATEST_REL=$(curl --silent "https://api.github.com/repos/$REPO_TO_USE/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') 11 12 # Check if this is a release branch 13 THIS_BRANCH=$(git rev-parse --abbrev-ref HEAD) 14 15 if [[ $(echo "$THIS_BRANCH" | grep -c ^"$BRANCH_TO_USE") == 1 ]]; 16 then 17 VERSION_REL=${THIS_BRANCH//$BRANCH_TO_USE/v} 18 REL_TO_USE=$(curl --silent "https://api.github.com/repos/$REPO_TO_USE/releases" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | sed -n "/$VERSION_REL/p" | sort -rV | head -n 1) 19 else 20 REL_TO_USE=$(echo "$THIS_BRANCH" | sed "s/\(.*\)/$LATEST_REL/") 21 fi 22 23 echo "$REL_TO_USE"