Skip to content

Instantly share code, notes, and snippets.

@agsimfzi
Forked from CSTDev/auto-increment-version.sh
Created October 22, 2023 16:54

Revisions

  1. @CSTDev CSTDev revised this gist Dec 23, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion auto-increment-version.sh
    Original file line number Diff line number Diff line change
    @@ -44,7 +44,7 @@ NEEDS_TAG=`git describe --contains $GIT_COMMIT`
    if [ -z "$NEEDS_TAG" ]; then
    echo "Tagged with $NEW_TAG (Ignoring fatal:cannot describe - this means commit is untagged) "
    git tag $NEW_TAG
    git push https://${GH_TOKEN}@github.com/CSTDev/go-helpers --tags
    git push --tags
    else
    echo "Already a tag on this commit"
    fi
  2. @CSTDev CSTDev revised this gist Dec 23, 2019. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions auto-increment-version.sh
    Original file line number Diff line number Diff line change
    @@ -12,11 +12,6 @@ VNUM2=${VERSION_BITS[1]}
    VNUM3=${VERSION_BITS[2]}
    VNUM1=`echo $VNUM1 | sed 's/v//'`

    echo $VNUM1
    echo $VNUM2
    echo $VNUM3


    # Check for #major or #minor in commit message and increment the relevant version number
    MAJOR=`git log --format=%B -n 1 HEAD | grep '#major'`
    MINOR=`git log --format=%B -n 1 HEAD | grep '#minor'`
  3. @CSTDev CSTDev revised this gist Dec 23, 2019. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions auto-increment-version.sh
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,12 @@ VERSION_BITS=(${VERSION//./ })
    VNUM1=${VERSION_BITS[0]}
    VNUM2=${VERSION_BITS[1]}
    VNUM3=${VERSION_BITS[2]}
    VNUM1=`echo $VNUM1 | sed 's/v//'`

    echo $VNUM1
    echo $VNUM2
    echo $VNUM3


    # Check for #major or #minor in commit message and increment the relevant version number
    MAJOR=`git log --format=%B -n 1 HEAD | grep '#major'`
    @@ -31,7 +37,7 @@ fi


    #create new tag
    NEW_TAG="$VNUM1.$VNUM2.$VNUM3"
    NEW_TAG="v$VNUM1.$VNUM2.$VNUM3"

    echo "Updating $VERSION to $NEW_TAG"

    @@ -43,7 +49,7 @@ NEEDS_TAG=`git describe --contains $GIT_COMMIT`
    if [ -z "$NEEDS_TAG" ]; then
    echo "Tagged with $NEW_TAG (Ignoring fatal:cannot describe - this means commit is untagged) "
    git tag $NEW_TAG
    git push --tags
    git push https://${GH_TOKEN}@github.com/CSTDev/go-helpers --tags
    else
    echo "Already a tag on this commit"
    fi
    fi
  4. @CSTDev CSTDev revised this gist Aug 7, 2019. No changes.
  5. @CSTDev CSTDev revised this gist Aug 7, 2019. No changes.
  6. @CSTDev CSTDev created this gist Aug 7, 2019.
    49 changes: 49 additions & 0 deletions auto-increment-version.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    #!/bin/bash

    #get highest tag number
    VERSION=`git describe --abbrev=0 --tags`

    #replace . with space so can split into an array
    VERSION_BITS=(${VERSION//./ })

    #get number parts and increase last one by 1
    VNUM1=${VERSION_BITS[0]}
    VNUM2=${VERSION_BITS[1]}
    VNUM3=${VERSION_BITS[2]}

    # Check for #major or #minor in commit message and increment the relevant version number
    MAJOR=`git log --format=%B -n 1 HEAD | grep '#major'`
    MINOR=`git log --format=%B -n 1 HEAD | grep '#minor'`

    if [ "$MAJOR" ]; then
    echo "Update major version"
    VNUM1=$((VNUM1+1))
    VNUM2=0
    VNUM3=0
    elif [ "$MINOR" ]; then
    echo "Update minor version"
    VNUM2=$((VNUM2+1))
    VNUM3=0
    else
    echo "Update patch version"
    VNUM3=$((VNUM3+1))
    fi


    #create new tag
    NEW_TAG="$VNUM1.$VNUM2.$VNUM3"

    echo "Updating $VERSION to $NEW_TAG"

    #get current hash and see if it already has a tag
    GIT_COMMIT=`git rev-parse HEAD`
    NEEDS_TAG=`git describe --contains $GIT_COMMIT`

    #only tag if no tag already (would be better if the git describe command above could have a silent option)
    if [ -z "$NEEDS_TAG" ]; then
    echo "Tagged with $NEW_TAG (Ignoring fatal:cannot describe - this means commit is untagged) "
    git tag $NEW_TAG
    git push --tags
    else
    echo "Already a tag on this commit"
    fi