Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
OWNER=$(echo ${TRAVIS_REPO_SLUG} | grep -Po '\w*' | head -n 1)
# Get the tags
TAGS="$(curl -s -u ${OWNER}:${SECRET} https://api.github.com/repos/${TRAVIS_REPO_SLUG}/git/refs/tags | grep -Po '(ref|sha)":.*' | paste -d" " - -)"
# Get the most recent tag number
VER=$(echo "${TAGS}" | sed 's/ref": "refs\/tags\/v//g' | sed 's/", sha":.*//g' | sort -V | tail -n 1)
# Get the associated tag ref
TAG_SHA=$(echo "${TAGS}" | grep $VER | sed 's/.*sha": "//g' | sed 's/",//g')
# Get the associated commit ref
COM_SHA=$(curl -s -u ${OWNER}:${SECRET} https://api.github.com/repos/${TRAVIS_REPO_SLUG}/git/tags/${SHA} | grep sha | tail -n 1 | grep -Po \\w{40})
# Get the commits-after count
POINT_VER=$(curl -s -u ${OWNER}:${SECRET} https://api.github.com/repos/${TRAVIS_REPO_SLUG}/compare/${COM_REF}...${TRAVIS_COMMIT} | grep ahead_by | grep -Po '\d*')
FINAL_VER="${VER}.${POINT_VER}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment