-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.sh
executable file
·58 lines (46 loc) · 1.1 KB
/
version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
# defaults to minor version bump
ARGS=$*
if [ -z "$ARGS" ]; then
ARGS=minor
fi
# run the python 'bumpversion' command
/usr/bin/env bumpversion $ARGS
# ensure it succeeded, or else bail out
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo "Bump version succeeded"
else
echo "Bump version failed"
exit 1
fi
# get the build number from the git commit count
BUILD=$(git rev-list HEAD --count)
# get the branch
BRANCH=$(git branch | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
# get the major/minor version from the git tag and parse it
VERSION=$(git describe --long --tags | sed -E 's/^v([0-9]*)\.([0-9]*)\.[0-9]*-([0-9]*)-(.*)$/\1.\2.\3.\4/')
IFS='.' read -a versionparts <<< "$VERSION"
MAJOR=${versionparts[0]}
if [ -z "$MAJOR" ]; then
MAJOR=0
fi
MINOR=${versionparts[1]}
if [ -z "$MINOR" ]; then
MINOR=0
fi
OFFSET=${versionparts[2]}
if [ -z "$OFFSET" ]; then
OFFSET=0
fi
HASH=${versionparts[3]}
if [ -z "$MAJOR" ]; then
MAJOR=0
fi
echo "Version: $VERSION"
echo "Major: $MAJOR"
echo "Minor: $MINOR"
echo "Build: $BUILD"
echo "Branch: $BRANCH"
echo "Offset: $OFFSET"
echo "Hash: $HASH"