Skip to content

Instantly share code, notes, and snippets.

@dreamstarter
Last active March 6, 2020 18:24
Show Gist options
  • Select an option

  • Save dreamstarter/c06d198d6ffcf69ea24b6c5da0af6d20 to your computer and use it in GitHub Desktop.

Select an option

Save dreamstarter/c06d198d6ffcf69ea24b6c5da0af6d20 to your computer and use it in GitHub Desktop.

Revisions

  1. dreamstarter revised this gist Mar 6, 2020. 1 changed file with 47 additions and 27 deletions.
    74 changes: 47 additions & 27 deletions version.sh
    Original file line number Diff line number Diff line change
    @@ -1,33 +1,53 @@
    #!/bin/bash
    # enable debug
    #set -x

    version="$1"
    major=3
    minor=0
    maint=0
    build=0
    # variables
    VERSIONFILE="$HOME/current-version.sh"

    # break down the version number into it's components
    regex="([0-9]+).([0-9]+).([0-9]+).([0-9]+)"
    if [[ $version =~ $regex ]]; then
    major="${BASH_REMATCH[1]}"
    minor="${BASH_REMATCH[2]}"
    maint="${BASH_REMATCH[3]}"
    build="${BASH_REMATCH[4]}"
    fi
    # functions
    function saveVersion () {
    echo "#!/bin/bash
    MAJOR=${1}
    MINOR=${2}
    MAINT=${3}
    BUILD=${4}" > $5
    }

    # load current VERSION
    . $VERSIONFILE

    # main
    # check paramater to see which number to increment
    if [[ "$2" == "feature" ]] then
    minor=$[$minor + 1]
    elif [[ "$2" == "bug" ]] then
    build=$[$build + 1]
    elif [[ "$2" == "maintenance" ]]; then
    maint=$[$maint + 1]
    elif [[ "$2" == "major" ]] then
    major=$[$major+1]
    else
    echo "usage: ./version.sh version_number [major/feature/maintenance/bug]"
    exit -1
    fi
    case $1 in
    release)
    MAJOR=$[$MAJOR + 1]
    MINOR=0
    MAINT=0
    BUILD=0
    ;;
    feature)
    MINOR=$[$MINOR + 1]
    ;;
    maint)
    MAINT=$[$MAINT + 1]
    ;;
    bug)
    BUILD=$[$BUILD + 1]
    ;;
    current)
    echo "Current version: ${MAJOR}.${MINOR}.${MAINT}.${BUILD}"
    exit 0
    ;;
    *)
    echo "Current version: ${MAJOR}.${MINOR}.${MAINT}.${BUILD}"
    echo " "
    echo "Usage: $(basename $0) (current || release || feature || maint || bug)"
    exit 1
    esac

    # echo the new VERSION number
    echo "NEW VERSION: ${MAJOR}.${MINOR}.${MAINT}.${BUILD}"
    saveVersion "${MAJOR}" "${MINOR}" "${MAINT}" "${BUILD}" "$VERSIONFILE"

    # echo the new version number
    echo "new version: ${major}.${minor}.${maint}.${build}"
    exit 0
  2. dreamstarter revised this gist Mar 6, 2020. 1 changed file with 10 additions and 10 deletions.
    20 changes: 10 additions & 10 deletions version.sh
    Original file line number Diff line number Diff line change
    @@ -3,31 +3,31 @@
    version="$1"
    major=3
    minor=0
    maintenance=0
    maint=0
    build=0

    # break down the version number into it's components
    regex="([0-9]+).([0-9]+).([0-9]+).([0-9]+)"
    if [[ $version =~ $regex ]]; then
    major="${BASH_REMATCH[1]}"
    minor="${BASH_REMATCH[2]}"
    maintenance="${BASH_REMATCH[3]}"
    maint="${BASH_REMATCH[3]}"
    build="${BASH_REMATCH[4]}"
    fi

    # check paramater to see which number to increment
    if [[ "$2" == "feature" ]]; then
    minor=$(echo $minor + 1 | bc)
    elif [[ "$2" == "bug" ]]; then
    build=$(echo $build + 1 | bc)
    if [[ "$2" == "feature" ]] then
    minor=$[$minor + 1]
    elif [[ "$2" == "bug" ]] then
    build=$[$build + 1]
    elif [[ "$2" == "maintenance" ]]; then
    maintenance=$(echo $maintenance + 1 | bc)
    elif [[ "$2" == "major" ]]; then
    major=$(echo $major+1 | bc)
    maint=$[$maint + 1]
    elif [[ "$2" == "major" ]] then
    major=$[$major+1]
    else
    echo "usage: ./version.sh version_number [major/feature/maintenance/bug]"
    exit -1
    fi

    # echo the new version number
    echo "new version: ${major}.${minor}.${maintenance}.${build}"
    echo "new version: ${major}.${minor}.${maint}.${build}"
  3. dreamstarter revised this gist Mar 6, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion version.sh
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ regex="([0-9]+).([0-9]+).([0-9]+).([0-9]+)"
    if [[ $version =~ $regex ]]; then
    major="${BASH_REMATCH[1]}"
    minor="${BASH_REMATCH[2]}"
    minor="${BASH_REMATCH[3]}"
    maintenance="${BASH_REMATCH[3]}"
    build="${BASH_REMATCH[4]}"
    fi

  4. dreamstarter created this gist Mar 6, 2020.
    33 changes: 33 additions & 0 deletions version.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/bin/bash

    version="$1"
    major=3
    minor=0
    maintenance=0
    build=0

    # break down the version number into it's components
    regex="([0-9]+).([0-9]+).([0-9]+).([0-9]+)"
    if [[ $version =~ $regex ]]; then
    major="${BASH_REMATCH[1]}"
    minor="${BASH_REMATCH[2]}"
    minor="${BASH_REMATCH[3]}"
    build="${BASH_REMATCH[4]}"
    fi

    # check paramater to see which number to increment
    if [[ "$2" == "feature" ]]; then
    minor=$(echo $minor + 1 | bc)
    elif [[ "$2" == "bug" ]]; then
    build=$(echo $build + 1 | bc)
    elif [[ "$2" == "maintenance" ]]; then
    maintenance=$(echo $maintenance + 1 | bc)
    elif [[ "$2" == "major" ]]; then
    major=$(echo $major+1 | bc)
    else
    echo "usage: ./version.sh version_number [major/feature/maintenance/bug]"
    exit -1
    fi

    # echo the new version number
    echo "new version: ${major}.${minor}.${maintenance}.${build}"