-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.sh
More file actions
executable file
·99 lines (79 loc) · 2.12 KB
/
version.sh
File metadata and controls
executable file
·99 lines (79 loc) · 2.12 KB
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
#!/bin/bash
# Semantic version bumping script for Envoy
# Usage: ./version.sh [patch|minor|major]
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print error and exit
error_exit() {
echo -e "${RED}Error: $1${NC}" >&2
exit 1
}
# Function to print success message
success_msg() {
echo -e "${GREEN}$1${NC}"
}
# Check if a bump type is provided
if [ $# -eq 0 ]; then
error_exit "Missing argument. Usage: $0 [patch|minor|major]"
fi
BUMP_TYPE=$1
# Validate bump type
case $BUMP_TYPE in
patch|minor|major)
;;
*)
error_exit "Invalid bump type '$BUMP_TYPE'. Must be one of: patch, minor, major"
;;
esac
# Check if working directory is clean
if [ -n "$(git status --porcelain)" ]; then
error_exit "Working directory is not clean. Commit or stash changes first."
fi
# Get the latest version tag
LATEST_TAG=$(git tag --sort=-version:refname --list "v[0-9]*" | head -n 1)
# If no tags exist, start with v0.0.0
if [ -z "$LATEST_TAG" ]; then
LATEST_TAG="v0.0.0"
success_msg "No existing tags found. Starting with v0.0.0"
fi
# Remove 'v' prefix for processing
VERSION=${LATEST_TAG#v}
# Split version into components
MAJOR=$(echo $VERSION | cut -d. -f1)
MINOR=$(echo $VERSION | cut -d. -f2)
PATCH=$(echo $VERSION | cut -d. -f3)
# Increment version based on type
case $BUMP_TYPE in
patch)
PATCH=$((PATCH + 1))
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
esac
# Construct new version
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
# Confirm the bump
echo -e "${YELLOW}Bumping version:${NC} $LATEST_TAG -> $NEW_VERSION"
read -p "Continue? [y/N] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Cancelled."
exit 0
fi
# Create annotated tag
git tag -a "$NEW_VERSION" -m "Bump version to $NEW_VERSION"
# Push the tag
git push origin "$NEW_VERSION"
success_msg "Successfully created and pushed tag: $NEW_VERSION"
echo -e "Users can now install with: ${GREEN}go install ytsruh.com/envoy@${NEW_VERSION}${NC}"