-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathnext-version.sh
More file actions
executable file
·57 lines (50 loc) · 1.62 KB
/
next-version.sh
File metadata and controls
executable file
·57 lines (50 loc) · 1.62 KB
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
#!/usr/bin/env bash
#
# Returns the next version number for a release.
#
# Can be run four different ways.
#
# Return the next major version number, e.g. 1.0.0:
# ./next-version.sh -m
#
# Return the next minor version number (switch is optional), e.g. 0.1.0:
# ./next-version.sh
# ./next-version.sh -n
#
# Return the next version number with a supplied patch value, e.g. 0.0.123:
# ./next-version.sh -p 123
#
# Return the current version number:
# ./next-version.sh -c
set -e
# Ensure we're in the root of the repo so that gh works as expected
cd "$(dirname "$0")/.."
LATEST_VERSION=$(gh release list --exclude-drafts --exclude-pre-releases --json tagName --limit 1 | jq -r '.[0].tagName')
if [ "$LATEST_VERSION" == "null" ]; then
# this will be the first release
LATEST_VERSION="0.0.0"
fi
if [ "$1" == "-c" ]; then
echo $LATEST_VERSION
exit 0
fi
MAJOR_VERSION=$(echo "$LATEST_VERSION" | sed -En 's/^([0-9]+)\.[0-9]+\.[0-9]+$/\1/p')
MINOR_VERSION=$(echo "$LATEST_VERSION" | sed -En 's/^[0-9]+\.([0-9]+)\.[0-9]+$/\1/p')
if [ "$1" == "-m" ]; then
echo $((MAJOR_VERSION + 1)).0.0
exit 0
fi
if [ "$1" == "-n" ] || [ -z "$1" ]; then
echo $MAJOR_VERSION.$((MINOR_VERSION + 1)).0
exit 0
fi
if [ "$1" == "-p" ] && [ ! -z "$2" ]; then
echo $MAJOR_VERSION.$MINOR_VERSION.$2
exit 0
fi
echo "Usage: $0 [-c | -m | -n | -p <patch>]" 1>&2
echo " -c Return the current version number" 1>&2
echo " -m Return the next major version number" 1>&2
echo " -n Return the next minor version number (the default)" 1>&2
echo " -p <patch> Return the next version number using the supplied patch number" 1>&2
exit 1