8
8
set -euo pipefail
9
9
10
10
remote_url=$( git remote get-url origin)
11
+ # Newest tag by semantic version (may include prerelease like -rc/-beta/-alpha)
11
12
current_version=" $( git tag -l | sort --version-sort | tail -n1) "
13
+ # Newest stable version tag (strict X.Y.Z; excludes prereleases)
14
+ stable_version=" $( git tag -l | sort --version-sort | grep -E ' ^(v)?[0-9]+\.[0-9]+\.[0-9]+$' | tail -n1) "
12
15
13
16
function help() {
14
17
echo " $0 [options] [arguments]"
15
18
echo " "
16
19
echo " options:"
17
20
echo " -h, --help show brief help"
18
21
echo " -c, --current show the current version"
22
+ echo " -s, --stable show the current stable version"
19
23
echo " -b, --bump bump the version based on the given argument"
20
24
exit 0
21
25
}
@@ -25,11 +29,11 @@ function bump_version() {
25
29
local new_version
26
30
27
31
if [[ $version == " major" ]]; then
28
- new_version=$( echo $current_version | sed ' s/^v//' | awk -F. ' {print "v" $1+1".0.0"}' )
32
+ new_version=$( echo $stable_version | sed ' s/^v//' | awk -F. ' {print "v" $1+1".0.0"}' )
29
33
elif [[ $version == " minor" ]]; then
30
- new_version=$( echo $current_version | awk -F. ' {print $1"."$2+1".0"}' )
34
+ new_version=$( echo $stable_version | awk -F. ' {print $1"."$2+1".0"}' )
31
35
elif [[ $version == " patch" ]]; then
32
- new_version=$( echo $current_version | awk -F. ' {print $1"."$2"."$3+1}' )
36
+ new_version=$( echo $stable_version | awk -F. ' {print $1"."$2"."$3+1}' )
33
37
else
34
38
echo " Error: Unknown argument $version "
35
39
exit 1
@@ -38,11 +42,16 @@ function bump_version() {
38
42
echo $new_version
39
43
}
40
44
45
+ # Show the newest tag (stable or prerelease like -rc/-beta/-alpha), without the leading 'v'.
41
46
function show_current() {
42
- # Version without the "v" prefix.
43
47
echo " ${current_version# v} "
44
48
}
45
49
50
+ # Show the newest stable tag (strict X.Y.Z), without the leading 'v'.
51
+ function show_stable() {
52
+ echo " ${stable_version# v} "
53
+ }
54
+
46
55
if [ $# == 0 ]; then
47
56
show_current
48
57
fi
@@ -56,6 +65,10 @@ while test $# -gt 0; do
56
65
show_current
57
66
shift
58
67
;;
68
+ -s|--stable)
69
+ show_stable
70
+ shift
71
+ ;;
59
72
-b|--bump)
60
73
if [ $# -lt 2 ]; then
61
74
echo " Error: Missing argument for bump"
0 commit comments