-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
executable file
·71 lines (57 loc) · 1.69 KB
/
release.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
#!/bin/bash
# Ensure the script exits if any command fails
set -e
# Function to get the current version from Cargo.toml
get_version() {
grep '^version =' Cargo.toml | sed -E 's/version = "(.*)"/\1/'
}
# Function to bump the patch version
bump_patch() {
IFS='.' read -r -a parts <<< "$1"
parts[2]=$((parts[2] + 1))
echo "${parts[0]}.${parts[1]}.${parts[2]}"
}
# Function to bump the minor version
bump_minor() {
IFS='.' read -r -a parts <<< "$1"
parts[1]=$((parts[1] + 1))
parts[2]=0
echo "${parts[0]}.${parts[1]}.${parts[2]}"
}
# Function to bump the major version
bump_major() {
IFS='.' read -r -a parts <<< "$1"
parts[0]=$((parts[0] + 1))
parts[1]=0
parts[2]=0
echo "${parts[0]}.${parts[1]}.${parts[2]}"
}
current_version=$(get_version)
echo "Current version: $current_version"
if [ "$1" == "bump_patch" ]; then
new_version=$(bump_patch "$current_version")
elif [ "$1" == "bump_minor" ]; then
new_version=$(bump_minor "$current_version")
elif [ "$1" == "bump_major" ]; then
new_version=$(bump_major "$current_version")
else
echo "Usage: $0 {bump_patch|bump_minor|bump_major}"
exit 1
fi
echo "New version: $new_version"
# Update the version in Cargo.toml
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
sed -i '' -E "s/^version = \"$current_version\"/version = \"$new_version\"/" Cargo.toml
else
# GNU/Linux
sed -i -E "s/^version = \"$current_version\"/version = \"$new_version\"/" Cargo.toml
fi
cargo update
git add Cargo.toml
git add Cargo.lock
git commit -m "Bump version to $new_version"
git tag "v$new_version"
git push origin main
git push origin "v$new_version"
echo "Version bumped to $new_version and tagged with git."