forked from gitbutlerapp/gitbutler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.sh
executable file
·57 lines (49 loc) · 1.25 KB
/
next.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
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
function help() {
local to="$1"
echo "Usage: $0 <version> <bump>" 1>&$to
echo 1>&$to
echo "where:" 1>&$to
echo " <version> is a current semver version." 1>&$to
echo " <bump> is either 'patch', 'major' or 'minor'." 1>&$to
}
function error() {
echo "error: $@" 1>&2
echo 1>&2
help 2
exit 1
}
function info() {
echo "$@"
}
VERSION="$1"
BUMP="$2"
# https://semver.org/
SEMVER_REGEX="^(0|[1-9][[:digit:]]*)\.(0|[1-9][[:digit:]]*)\.(0|[1-9][[:digit:]]*)(?:-((?:0|[1-9][[:digit:]]*|[[:digit:]]*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9][[:digit:]]*|[[:digit:]]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
(echo "$VERSION" | grep -Eq "$SEMVER_REGEX") || error "'$VERSION' not a semver"
case "$BUMP" in
major)
MAJOR="$(($(echo "$VERSION" | cut -d. -f1) + 1))"
MINOR="0"
PATCH="0"
echo "$MAJOR.$MINOR.$PATCH"
;;
minor)
MAJOR="$(echo "$VERSION" | cut -d. -f1)"
MINOR="$(($(echo "$VERSION" | cut -d. -f2) + 1))"
PATCH="0"
echo "$MAJOR.$MINOR.$PATCH"
;;
patch)
MAJOR="$(echo "$VERSION" | cut -d. -f1)"
MINOR="$(echo "$VERSION" | cut -d. -f2)"
PATCH="$(($(echo "$VERSION" | cut -d. -f3) + 1))"
echo "$MAJOR.$MINOR.$PATCH"
;;
*)
error "invalid bump type: $BUMP"
;;
esac