-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
tag.sh
50 lines (39 loc) · 1.23 KB
/
tag.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
#!/bin/bash
# Get the desired version bump type from command line argument
if [ $# -ne 1 ]; then
echo "Usage: $0 [major|minor|patch]"
exit 1
fi
VERSION_BUMP="$1"
# Get the current version from git tags or set to 1.0.0 if no tags exist
CURRENT_VERSION=$(git describe --abbrev=0 --tags 2>/dev/null || echo "v1.0.0")
CURRENT_VERSION=${CURRENT_VERSION:1}
echo "Current Version: $CURRENT_VERSION"
# Split the current version into an array using '.' as a delimiter
IFS='.' read -ra CURRENT_VERSION_PARTS <<< "$CURRENT_VERSION"
# Extract major, minor, and patch version numbers
VNUM1=${CURRENT_VERSION_PARTS[0]}
VNUM2=${CURRENT_VERSION_PARTS[1]}
VNUM3=${CURRENT_VERSION_PARTS[2]}
# Increment the version based on the bump type
if [ "$VERSION_BUMP" == 'major' ]; then
VNUM1=$((VNUM1+1))
VNUM2=0
VNUM3=0
elif [ "$VERSION_BUMP" == 'minor' ]; then
VNUM2=$((VNUM2+1))
VNUM3=0
elif [ "$VERSION_BUMP" == 'patch' ]; then
VNUM3=$((VNUM3+1))
else
echo "Invalid version bump type. Use 'major', 'minor', or 'patch'."
exit 1
fi
# Create the new version number
NEW_TAG="v$VNUM1.$VNUM2.$VNUM3"
echo "Bumping $VERSION_BUMP version to $NEW_TAG"
# Create a new tag and push it to the remote repository
git tag "$NEW_TAG"
git push --tags
git push
exit 0