-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbump-version.sh
64 lines (51 loc) · 1.42 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
#!/bin/bash
# Usage Examples:
# ./bump-version.sh major
# ./bump-version.sh minor
# ./bump-version.sh patch
# ./bump-version.sh (same as patch)
# Default to patch if no argument provided
VERSION_TYPE=${1:-patch}
# Validate version type
if [[ ! "$VERSION_TYPE" =~ ^(major|minor|patch)$ ]]; then
echo "Error: Version type must be 'major', 'minor', or 'patch'"
exit 1
fi
CSPROJ_PATH="SaveHere/SaveHere/SaveHere.csproj"
# Check if file exists
if [ ! -f "$CSPROJ_PATH" ]; then
echo "Error: Could not find $CSPROJ_PATH"
exit 1
fi
# Extract current version
CURRENT_VERSION=$(grep -oP '(?<=<Version>)\d+\.\d+\.\d+(?=</Version>)' "$CSPROJ_PATH")
if [ -z "$CURRENT_VERSION" ]; then
echo "Error: Could not find version in $CSPROJ_PATH"
exit 1
fi
# Split version into parts
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
# Increment based on type
case $VERSION_TYPE in
"major")
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
"minor")
MINOR=$((MINOR + 1))
PATCH=0
;;
"patch")
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
# Update the file
sed -i "s/<Version>$CURRENT_VERSION<\/Version>/<Version>$NEW_VERSION<\/Version>/" "$CSPROJ_PATH"
echo "Version bumped to $NEW_VERSION"
# If script was double-clicked or run without arguments, wait for input
if [ -z "$1" ]; then
echo -e "\nPress ENTER to exit..."
read -r
fi