-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbump_version.sh
executable file
·89 lines (76 loc) · 1.74 KB
/
bump_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
# Usage: ./bump_version.sh -r <patch|minor|major> - Increments version by chosen release type.
function help() {
echo "Usage: ./bump_version.sh -r <patch|minor|major> - Increments version by chosen release type."
echo ""
echo "Flags:"
echo "-r: release type (patch, minor, major)"
echo "-h: help"
}
# get version from version file
VERSION=$(cat VERSION | tr -d '\n')
# r flag is for release
while getopts ":r:h" opt; do
case $opt in
r)
RELEASE=$OPTARG
;;
h)
help
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
# if release flag is not set, exit
if [ -z "$RELEASE" ]; then
echo "No release flag set. Aborting."
help
exit 1
fi
# bump version (version, release)
function bump_version(){
major=$(echo "$1" | cut -d'.' -f1)
minor=$(echo "$1" | cut -d'.' -f2)
patch=$(echo "$1" | cut -d'.' -f3)
case "$2" in
"major")
major=$((major+1))
minor=0
patch=0
;;
"minor")
minor=$((minor+1))
patch=0
;;
"patch")
patch=$((patch+1))
;;
esac
echo "$major.$minor.$patch"
}
function confirm() {
read -r -p "$@ [Y/n]: " confirm
case "$confirm" in
[Nn][Oo]|[Nn])
echo "Aborting."
exit
;;
esac
}
# convert release flag to lowercase
RELEASE=$(echo "$RELEASE" | tr '[:upper:]' '[:lower:]')
# if release flag is not patch, minor, or major, exit
if [ "$RELEASE" != "patch" ] && [ "$RELEASE" != "minor" ] && [ "$RELEASE" != "major" ]; then
echo "Invalid release flag. Aborting."
exit 1
fi
# update version
VERSION=$(bump_version "$VERSION" "$RELEASE")
confirm "Updating version to $VERSION ?"
# update version in version file
echo $VERSION > ./VERSION
echo $VERSION
export VERSION=$VERSION