-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
version-bump.sh
executable file
·78 lines (72 loc) · 1.83 KB
/
version-bump.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
# Directory of this script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
#
# Takes a version number, and the mode to bump it, and increments/resets
# the proper components so that the result is placed in the variable
# `NEW_VERSION`.
#
# $1 = mode (major, minor, patch)
# $2 = version (x.y.z)
#
function bump {
local mode="$1"
local old="$2"
local parts=( ${old//./ } )
case "$1" in
major)
local bv=$((parts[0] + 1))
NEW_VERSION="${bv}.0.0"
;;
minor)
local bv=$((parts[1] + 1))
NEW_VERSION="${parts[0]}.${bv}.0"
;;
patch)
local bv=$((parts[2] + 1))
NEW_VERSION="${parts[0]}.${parts[1]}.${bv}"
;;
esac
}
git config --global user.email $EMAIL
git config --global user.name $NAME
OLD_VERSION=$($DIR/get-version.sh)
BUMP_MODE="none"
if [[ "${TYPE}" == "" ]]
then
if git log -1 | grep -q "#major"; then
BUMP_MODE="major"
elif git log -1 | grep -q "#minor"; then
BUMP_MODE="minor"
elif git log -1 | grep -q "#patch"; then
BUMP_MODE="patch"
fi
else
case "$TYPE" in
major)
BUMP_MODE="major"
;;
minor)
BUMP_MODE="minor"
;;
patch)
BUMP_MODE="patch"
;;
esac
fi
if [[ "${BUMP_MODE}" == "none" ]]
then
echo "No matching commit tags found or no release type set."
echo "pom.xml at" $POMPATH "will remain at" $OLD_VERSION
else
echo $BUMP_MODE "version bump detected"
bump $BUMP_MODE $OLD_VERSION
echo "pom.xml at" $POMPATH "will be bumped from" $OLD_VERSION "to" $NEW_VERSION
mvn --file $POMPATH/pom.xml -q versions:set -DnewVersion="${NEW_VERSION}"
git add $POMPATH/pom.xml
REPO="https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY.git"
git commit -m "Bump pom.xml from $OLD_VERSION to $NEW_VERSION"
git tag $NEW_VERSION
git push $REPO --follow-tags
git push $REPO --tags
fi