-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
new-version.sh
executable file
Β·143 lines (125 loc) Β· 3.93 KB
/
new-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
141
142
143
#!/bin/bash
set -e
check_pending_changes() {
if ! git diff-index --quiet HEAD --; then
echo "β There are uncommitted changes in the repository."
echo "π Please commit or stash them before running this script."
exit 1
fi
}
confirm() {
read -r -p "${1:-Are you sure? [y/N]} " response
case "$response" in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}
show_help() {
echo "Version Bumper Script"
echo "Usage: $0 <command>"
echo ""
echo "This script is used for bumping the version number in the galaxy.yml file following semantic versioning."
echo ""
echo "Commands:"
echo " major Bumps the major version (e.g., 1.2.3 -> 2.0.0)"
echo " minor Bumps the minor version (e.g., 1.2.3 -> 1.3.0)"
echo " patch Bumps the patch version (e.g., 1.2.3 -> 1.2.4)"
echo " premajor Creates a pre-release major version (e.g., 1.2.3 -> 2.0.0-0)"
echo " preminor Creates a pre-release minor version (e.g., 1.2.3 -> 1.3.0-0)"
echo " prepatch Creates a pre-release patch version (e.g., 1.2.3 -> 1.2.4-0)"
echo " prerelease Bumps the pre-release version (e.g., 1.2.3-0 -> 1.2.3-1)"
echo ""
echo "Examples:"
echo " $0 patch # Bumps the patch version"
echo " $0 minor # Bumps the minor version"
echo " $0 major # Bumps the major version"
echo " $0 prerelease # Bumps the prerelease version"
echo ""
echo "Note: Make sure that 'yq' is installed and functioning properly."
}
bump_version() {
local version=$1
local type=$2
# Break the version number into its components
local major=$(echo $version | cut -d. -f1)
local minor=$(echo $version | cut -d. -f2)
local patch=$(echo $version | cut -d. -f3)
# Remove any pre-release or build metadata
patch=${patch%%[-+]*}
# Increment the appropriate part of the version number
case $type in
major)
major=$((major + 1))
minor=0
patch=0
;;
minor)
minor=$((minor + 1))
patch=0
;;
patch)
patch=$((patch + 1))
;;
premajor)
major=$((major + 1))
minor=0
patch=0
version="$major.$minor.$patch-0"
;;
preminor)
minor=$((minor + 1))
patch=0
version="$major.$minor.$patch-0"
;;
prepatch)
patch=$((patch + 1))
version="$major.$minor.$patch-0"
;;
prerelease)
if [[ $version =~ "-" ]]; then
local number=$(echo $version | cut -d- -f2)
number=$((number + 1))
version="$major.$minor.$patch-$number"
else
version="$major.$minor.$patch-0"
fi
;;
*)
echo "Invalid version type: $type"
exit 1
;;
esac
if [ "$type" != "prerelease" ] && [ "$type" != "premajor" ] && [ "$type" != "preminor" ] && [ "$type" != "prepatch" ]; then
version="$major.$minor.$patch"
fi
echo $version
}
# Check if argument is provided
if [ $# -ne 1 ]; then
show_help
exit 1
fi
check_pending_changes
# Read the current version
current_version=$(yq e '.version' galaxy.yml)
# Bump the version
new_version=$(bump_version $current_version $1)
if confirm "You are about to change the version to $new_version. Do you want to continue? [y/N]"; then
# Update galaxy.yml with the new version
yq e ".version = \"$new_version\"" -i galaxy.yml
# # Commit and tag
# git add galaxy.yml
# git commit -m "Bump version to $new_version"
# git tag $new_version
# # Push changes
# git push origin main
# git push origin --tags
echo "π Updated galaxy.yml to $new_version!"
else
echo "π Version update aborted."
exit 1
fi