Skip to content

Instantly share code, notes, and snippets.

@mcgwiz
Created July 14, 2016 01:23
Show Gist options
  • Save mcgwiz/b5c9e9a585db2dd5a24bfc10220009df to your computer and use it in GitHub Desktop.
Save mcgwiz/b5c9e9a585db2dd5a24bfc10220009df to your computer and use it in GitHub Desktop.
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