mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-12-22 16:07:31 +00:00
Update semver to hopefully avoid squash merges
This commit is contained in:
parent
e8e7e6bcf5
commit
10a66a4edc
@ -1,26 +1,46 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Merge commits from this branch are counted
|
||||||
|
DEVELOPBRANCH="yggdrasil-network/develop"
|
||||||
|
|
||||||
# Get the last tag
|
# Get the last tag
|
||||||
TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*" 2>/dev/null)
|
TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*" 2>/dev/null)
|
||||||
|
|
||||||
# Get the number of commits from the last tag
|
# Get last merge to master
|
||||||
COUNT=$(git rev-list $TAG..HEAD --count 2>/dev/null)
|
MERGE=$(git rev-list $TAG..master --grep "from $DEVELOPBRANCH" 2>/dev/null | head -n 1)
|
||||||
|
|
||||||
|
# Get the number of merges since the last merge to master
|
||||||
|
PATCH=$(git rev-list $TAG..master --count --merges --grep="from $DEVELOPBRANCH" 2>/dev/null)
|
||||||
|
|
||||||
# If it fails then there's no last tag - go from the first commit
|
# If it fails then there's no last tag - go from the first commit
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
COUNT=$(git rev-list HEAD --count 2>/dev/null)
|
PATCH=$(git rev-list HEAD --count 2>/dev/null)
|
||||||
|
|
||||||
printf 'v0.0.%d' "$COUNT"
|
printf 'v0.0.%d' "$PATCH"
|
||||||
exit -1
|
exit -1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Get the number of merges on the current branch since the last tag
|
||||||
|
BUILD=$(git rev-list $TAG..HEAD --count --merges)
|
||||||
|
|
||||||
# Split out into major, minor and patch numbers
|
# Split out into major, minor and patch numbers
|
||||||
MAJOR=$(echo $TAG | cut -c 2- | cut -d "." -f 1)
|
MAJOR=$(echo $TAG | cut -c 2- | cut -d "." -f 1)
|
||||||
MINOR=$(echo $TAG | cut -c 2- | cut -d "." -f 2)
|
MINOR=$(echo $TAG | cut -c 2- | cut -d "." -f 2)
|
||||||
|
|
||||||
|
# Get the current checked out branch
|
||||||
|
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||||
|
|
||||||
# Output in the desired format
|
# Output in the desired format
|
||||||
if [ $COUNT = 0 ]; then
|
if [ $PATCH = 0 ]; then
|
||||||
printf 'v%d.%d' "$MAJOR" "$MINOR"
|
printf 'v%d.%d' "$MAJOR" "$MINOR"
|
||||||
else
|
else
|
||||||
printf 'v%d.%d.%d' "$MAJOR" "$MINOR" "$COUNT"
|
printf 'v%d.%d.%d' "$MAJOR" "$MINOR" "$PATCH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Add the build tag on non-master branches
|
||||||
|
if [ $BRANCH != "master" ]; then
|
||||||
|
if [ $BUILD != 0 ]; then
|
||||||
|
printf -- "-%04d" "$BUILD"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user