github.com/yggdrasil-network/yggdrasil-go@v0.5.6/contrib/msi/msversion.sh (about)

     1  #!/bin/sh
     2  
     3  # Get the last tag
     4  TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" 2>/dev/null)
     5  
     6  # Did getting the tag succeed?
     7  if [ $? != 0 ] || [ -z "$TAG" ]; then
     8    printf -- "unknown"
     9    exit 0
    10  fi
    11  
    12  # Get the current branch
    13  BRANCH=$(git symbolic-ref -q HEAD --short 2>/dev/null)
    14  
    15  # Did getting the branch succeed?
    16  if [ $? != 0 ] || [ -z "$BRANCH" ]; then
    17    BRANCH="master"
    18  fi
    19  
    20  # Split out into major, minor and patch numbers
    21  MAJOR=$(echo $TAG | cut -c 2- | cut -d "." -f 1)
    22  MINOR=$(echo $TAG | cut -c 2- | cut -d "." -f 2)
    23  PATCH=$(echo $TAG | cut -c 2- | cut -d "." -f 3 | awk -F"rc" '{print $1}')
    24  
    25  # Output in the desired format
    26  if [ $((PATCH)) -eq 0 ]; then
    27    printf '%s%d.%d' "$PREPEND" "$((MAJOR))" "$((MINOR))"
    28  else
    29    printf '%s%d.%d.%d' "$PREPEND" "$((MAJOR))" "$((MINOR))" "$((PATCH))"
    30  fi
    31  
    32  # Add the build tag on non-master branches
    33  if [ "$BRANCH" != "master" ]; then
    34    BUILD=$(git rev-list --count $TAG..HEAD 2>/dev/null)
    35  
    36    # Did getting the count of commits since the tag succeed?
    37    if [ $? != 0 ] || [ -z "$BUILD" ]; then
    38      printf -- "-unknown"
    39      exit 0
    40    fi
    41  
    42    # Is the build greater than zero?
    43    if [ $((BUILD)) -gt 0 ]; then
    44        printf -- "-%04d" "$((BUILD))"
    45    fi
    46  fi