Skip to content

Instantly share code, notes, and snippets.

@josephtaylor
Forked from marcuswhybrow/bump.sh
Created October 13, 2017 16:47
Show Gist options
  • Select an option

  • Save josephtaylor/9a155983a70d4555dfb011a32ee6abf7 to your computer and use it in GitHub Desktop.

Select an option

Save josephtaylor/9a155983a70d4555dfb011a32ee6abf7 to your computer and use it in GitHub Desktop.

Revisions

  1. josephtaylor revised this gist Oct 13, 2017. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions bump.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    #!/usr/bin/env bash

    latest_tag=$(git tag -l *.*.* --contains $(git rev-list --tags --max-count=1))

    if [[ ! "$latest_tag" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
    @@ -39,12 +41,8 @@ if [[ "$answer" =~ (y|Y|yes) ]]; then
    tag_message="Version $version"
    latest_message_version="$version"

    [ $major -eq 0 ] && tag_message="$tag_message Beta"
    [ $major -eq 0 ] && latest_message_version="$latest_message_version Beta"

    # Add the tag
    git tag -a $version -m "$tag_message" > /dev/null
    git tag -af latest -m "Latest recommended version ($latest_message_version)" > /dev/null

    echo "Latest tags:"
    git tag -n1 | tail -n5
  2. Marcus Whybrow created this gist Jun 28, 2012.
    53 changes: 53 additions & 0 deletions bump.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    latest_tag=$(git tag -l *.*.* --contains $(git rev-list --tags --max-count=1))

    if [[ ! "$latest_tag" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
    echo "The \"latest\" tag did not exist, or did not point to a commit which also had a semantic version tag."
    exit 1
    fi

    major=$(echo "$latest_tag" | awk -F '.' '{print $1}')
    minor=$(echo "$latest_tag" | awk -F '.' '{print $2}')
    patch=$(echo "$latest_tag" | awk -F '.' '{print $3}')

    echo "Latest semantic version tag: ${major}.${minor}.${patch}"

    case "$1" in
    major)
    echo "Bumping major version."
    major=$(( $major + 1 ))
    minor=0
    patch=0
    ;;
    minor)
    echo "Bumping minor version."
    minor=$(( $minor + 1 ))
    patch=0
    ;;
    patch|*)
    echo "Bumping patch version."
    patch=$(( $patch + 1 ))
    ;;
    esac

    echo "New semantic version is: ${major}.${minor}.${patch}"
    echo -n "Do you want to tag the current commit with that version? [y/N]: "

    read answer

    if [[ "$answer" =~ (y|Y|yes) ]]; then
    version="${major}.${minor}.${patch}"
    tag_message="Version $version"
    latest_message_version="$version"

    [ $major -eq 0 ] && tag_message="$tag_message Beta"
    [ $major -eq 0 ] && latest_message_version="$latest_message_version Beta"

    # Add the tag
    git tag -a $version -m "$tag_message" > /dev/null
    git tag -af latest -m "Latest recommended version ($latest_message_version)" > /dev/null

    echo "Latest tags:"
    git tag -n1 | tail -n5
    else
    echo "Aborted. No tags where added!"
    fi