-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
109 lines (88 loc) · 2.62 KB
/
release.sh
File metadata and controls
109 lines (88 loc) · 2.62 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
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# ModelingEvolution.Mjpeg Release Script
# Usage: ./release.sh [--patch|--minor|--major|--version X.X.X]
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
print_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
print_error() { echo -e "${RED}[ERROR]${NC} $1"; }
get_latest_version() {
local latest_tag=$(git tag -l "v*" | sort -V | tail -1)
if [ -n "$latest_tag" ]; then
echo "${latest_tag#v}"
else
echo "0.0.0"
fi
}
calculate_next_version() {
local current_version=$1
local bump_type=$2
IFS='.' read -ra VERSION_PARTS <<< "$current_version"
local major="${VERSION_PARTS[0]:-0}"
local minor="${VERSION_PARTS[1]:-0}"
local patch="${VERSION_PARTS[2]:-0}"
case "$bump_type" in
major)
major=$((major + 1))
minor=0
patch=0
;;
minor)
minor=$((minor + 1))
patch=0
;;
patch)
patch=$((patch + 1))
;;
esac
echo "$major.$minor.$patch"
}
main() {
local bump_type="patch"
local custom_version=""
while [[ $# -gt 0 ]]; do
case $1 in
--patch) bump_type="patch"; shift ;;
--minor) bump_type="minor"; shift ;;
--major) bump_type="major"; shift ;;
--version) custom_version="$2"; shift 2 ;;
-h|--help)
echo "Usage: $0 [--patch|--minor|--major|--version X.X.X]"
exit 0
;;
*) print_error "Unknown option: $1"; exit 1 ;;
esac
done
# Must be in a git repo
if ! git rev-parse --git-dir > /dev/null 2>&1; then
print_error "Not in a git repository"
exit 1
fi
# Abort if uncommitted changes
if ! git diff-index --quiet HEAD --; then
print_error "Uncommitted changes. Commit first."
exit 1
fi
local current_version=$(get_latest_version)
print_info "Current version: $current_version"
local next_version
if [ -n "$custom_version" ]; then
next_version="$custom_version"
else
next_version=$(calculate_next_version "$current_version" "$bump_type")
fi
local tag_name="v$next_version"
# Check tag doesn't exist
if git tag -l "$tag_name" | grep -q "$tag_name"; then
print_error "Tag $tag_name already exists"
exit 1
fi
print_info "Creating tag: $tag_name"
git tag -a "$tag_name" -m "Release $next_version"
print_info "Pushing tag to origin..."
git push origin "$tag_name"
print_info "Done! Monitor: https://github.com/modelingevolution/mjpeg/actions"
}
main "$@"