Created
July 30, 2014 21:04
-
-
Save ericbmerritt/f52f1c48b86150704270 to your computer and use it in GitHub Desktop.
Shell script for parsing semvers from git-describe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# Assumes that you tag versions with the version number (e.g., "1.1") | |
# and then the build number is that plus the number of commits since | |
# the tag (e.g., "1.1.17") | |
DESCRIBE=`git describe --tags --always` | |
# increment the build number (ie 115 to 116) | |
VERSION=`echo $DESCRIBE | awk '{split($0,a,"-"); print a[1]}'` | |
BUILD=`echo $DESCRIBE | awk '{split($0,a,"-"); print a[2]}'` | |
PATCH=`echo $DESCRIBE | awk '{split($0,a,"-"); print a[3]}'` | |
if [[ "${DESCRIBE}" =~ ^[A-Fa-f0-9]+$ ]]; then | |
VERSION="0.0.0" | |
BUILD=`git rev-list HEAD --count` | |
PATCH=${DESCRIBE} | |
fi | |
if [ "${BUILD}" = "" ]; then | |
BUILD='0' | |
fi | |
if [ "${BUILD}" = "" ]; then | |
PATCH=$DESCRIBE | |
fi | |
echo ${VERSION}+build.${BUILD}.${PATCH} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment