-
Notifications
You must be signed in to change notification settings - Fork 9
/
tag.sh
executable file
·45 lines (37 loc) · 1001 Bytes
/
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
#!/bin/bash
BUMP_MAJOR="major"
BUMP_MINOR="minor"
BUMP_PATCH="patch"
DEFAULT_BUMP=$BUMP_PATCH
# Parse argument to get the bump type
if [ $# -eq 0 ]; then
BUMP=$DEFAULT_BUMP
else
BUMP=$1
fi
# Get the latest tag using `git describe`
LATEST_TAG=$(git describe --abbrev=0 --tags)
# Extract version numbers from the latest tag
VERSION=$(echo "$LATEST_TAG" | sed 's/v//')
# Split version into major, minor, and patch components
IFS='.' read -ra VERSION_ARRAY <<< "$VERSION"
MAJOR=${VERSION_ARRAY[0]}
MINOR=${VERSION_ARRAY[1]}
PATCH=${VERSION_ARRAY[2]}
# Increment the version based on the bump type
if [ "$BUMP" = "$BUMP_MAJOR" ]; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
elif [ "$BUMP" = "$BUMP_MINOR" ]; then
MINOR=$((MINOR + 1))
PATCH=0
elif [ "$BUMP" = "$BUMP_PATCH" ]; then
PATCH=$((PATCH + 1))
else
echo "Unknown bump type. Please use either 'major', 'minor', or 'patch'."
exit 1
fi
# Construct the new tag
NEW_TAG="v$MAJOR.$MINOR.$PATCH"
echo $NEW_TAG