forked from clintmod/macprefs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbump.sh
executable file
·45 lines (37 loc) · 1.32 KB
/
bump.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
#!/usr/bin/env bash
function bump_version() {
local bump_type=$1
# Get current version from file
current_version=$(sed -n "s/__version__ = \"\([^']*\)\"/\1/p" macprefs/__init__.py | tr -d '\n')
# Split the version into an array
IFS='.' read -ra version_parts <<<"$current_version"
# Increment version based on the provided argument
if [[ $bump_type == "major" ]]; then
((version_parts[0]++))
version_parts[1]=0
version_parts[2]=0
elif [[ $bump_type == "minor" ]]; then
((version_parts[1]++))
version_parts[2]=0
elif [[ $bump_type == "patch" ]]; then
((version_parts[2]++))
else
echo "Invalid argument. Please use 'major', 'minor', or 'patch'."
return 1
fi
# Join the version parts back together
new_version="${version_parts[0]}.${version_parts[1]}.${version_parts[2]}"
# Update the version in the file
sed -i "" "s/${current_version}/${new_version}/" macprefs/__init__.py &>/dev/null
.venv/bin/black macprefs/__init__.py &>/dev/null
cp -f macprefs/__init__.py tests/__init__.py
git add macprefs/__init__.py tests/__init__.py &>/dev/null
git commit -m "${bump_type^^} Bump version to ${new_version}" &>/dev/null
git push origin master &>/dev/null
echo -n "$new_version"
}
# Usage:
# bump_version major
# bump_version minor
# bump_version patch
bump_version "$@"