-
Notifications
You must be signed in to change notification settings - Fork 1
/
bumpversion.sh
executable file
·71 lines (65 loc) · 2.57 KB
/
bumpversion.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
#!/usr/bin/env bash
current_version="1.0.0"
new_version=$current_version
__set_new_version()
{
# Split version into major, minor, and patch
IFS="." read -a version_array <<< "$current_version"
major=$((version_array[0]))
minor=$((version_array[1]))
patch=$((version_array[2]))
# Get version we're bumping from args and change version accordingly
case $1 in
"major")
major=$((major + 1))
minor=0
patch=0
;;
"minor")
minor=$((minor + 1))
patch=0
;;
"patch")
patch=$((patch + 1))
;;
*)
echo "Usage: ./bumpversion.sh major|minor|patch"
exit 1
;;
esac
new_version="$major.$minor.$patch"
}
set -euo pipefail
__set_new_version $1
# OSX and Linux sed are different, so we need to account for that with regard to the -i option
os_string=$(uname)
case $os_string in
"Darwin")
# Replace only the first instance in Cargo.toml (because there might be others that are for other libraries)
sed -i '' -e "1,6s#version = \"$current_version\"#version = \"$new_version\"#" Cargo.toml
# Update in the user guide
sed -i '' -e "s#v$current_version#v$new_version#" UserGuide.md
# Do it in the places we need to update in carrot_cli
sed -i '' -e "s#version = \"$current_version\"#version = \"$new_version\"#" carrot_cli/setup.py
sed -i '' -e "s#Current version: $current_version#Current version: $new_version#" carrot_cli/README.md
sed -i '' -e "s#__version = \"$current_version\"#__version = \"$new_version\"#" carrot_cli/src/carrot_cli/__main__.py
# Finally update it in this script
sed -i '' -e "s#current_version=\"$current_version\"#current_version=\"$new_version\"#" bumpversion.sh
;;
"Linux")
# Replace only the first instance in Cargo.toml (because there might be others that are for other libraries)
sed -i -e "1,6s#version = \"$current_version\"#version = \"$new_version\"#" Cargo.toml
# Update in the user guide
sed -i -e "s#v$current_version#v$new_version#" UserGuide.md
# Do it in the places we need to update in carrot_cli
sed -i -e "s#version = \"$current_version\"#version = \"$new_version\"#" carrot_cli/setup.py
sed -i -e "s#Current version: $current_version#Current version: $new_version#" carrot_cli/README.md
sed -i -e "s#__version = \"$current_version\"#__version = \"$new_version\"#" carrot_cli/src/carrot_cli/__main__.py
# Finally update it in this script
sed -i -e "s#current_version=\"$current_version\"#current_version=\"$new_version\"#" bumpversion.sh
;;
*)
echo "Unsupported operating system"
exit 1
;;
esac