-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbump_version.sh
executable file
·140 lines (118 loc) · 3.4 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
# Read current version from VERSION file
current_version=$(cat VERSION)
# Function to increment version
bump_version() {
local version="$1"
local type="$2"
local IFS="."
local -a parts=(${version})
case "$type" in
"major")
parts[0]=$((parts[0] + 1))
parts[1]=0
parts[2]=0
;;
"minor")
parts[1]=$((parts[1] + 1))
parts[2]=0
;;
"patch")
parts[2]=$((parts[2] + 1))
;;
*)
echo "Invalid bump type: $type"
return 1
;;
esac
echo "${parts[0]}.${parts[1]}.${parts[2]}"
}
# Calculate new versions
new_patch_version=$(bump_version "$current_version" "patch")
new_minor_version=$(bump_version "$current_version" "minor")
new_major_version=$(bump_version "$current_version" "major")
# Menu items
menu_items=(
"patch (${current_version} → ${new_patch_version})"
"minor (${current_version} → ${new_minor_version})"
"major (${current_version} → ${new_major_version})"
"exit"
)
# Function to draw menu
draw_menu() {
local selected=$1
clear
echo "Current version: $current_version"
echo "Use ↑/↓ arrows to navigate, Enter to select"
echo
for i in "${!menu_items[@]}"; do
if [ $i -eq $selected ]; then
echo "→ ${menu_items[$i]} ←"
else
echo " ${menu_items[$i]}"
fi
done
}
# Initialize selection
selected=0
# Hide cursor and configure terminal
tput civis
stty -echo
# Cleanup function
cleanup() {
tput cnorm
stty echo
}
trap cleanup EXIT
# Main menu loop
while true; do
draw_menu $selected
# Read a key
IFS= read -r -n1 key
case "$key" in
$'\x1b') # ESC sequence
read -r -n2 rest
case "$rest" in
'[A') # Up arrow
if [ $selected -gt 0 ]; then
selected=$((selected - 1))
fi
;;
'[B') # Down arrow
if [ $selected -lt $((${#menu_items[@]} - 1)) ]; then
selected=$((selected + 1))
fi
;;
esac
;;
"") # Enter key
clear
stty echo
tput cnorm
case $selected in
0) new_version="$new_patch_version" ;;
1) new_version="$new_minor_version" ;;
2) new_version="$new_major_version" ;;
3) echo "Exiting..."; exit 0 ;;
esac
read -p "Confirm version bump to $new_version? [y/N] " confirm
if [[ ! "$confirm" =~ ^[Yy] ]]; then
echo "Cancelled"
exit 0
fi
# Update VERSION file
echo "$new_version" > VERSION
# Update the cask file with the new version
sed -i "" "s/version \".*\"/version \"$new_version\"/g" Casks/chilikeys.rb
# Commit the changes
git add Casks/chilikeys.rb VERSION
git commit -m "Update cask version to $new_version"
# Add the new tag
git tag "v$new_version"
# Push the tags
git push origin --tags
echo "Version bumped to $new_version and tag v$new_version added and pushed successfully."
exit 0
;;
esac
done