-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
80 lines (67 loc) · 1.79 KB
/
release.sh
File metadata and controls
80 lines (67 loc) · 1.79 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
#!/bin/bash
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
# Parse arguments
DRY_RUN=false
VERSION=""
INCREMENT="patch"
MESSAGE=""
while [[ $# -gt 0 ]]; do
case $1 in
-p|--patch) INCREMENT="patch"; shift ;;
-n|--minor) INCREMENT="minor"; shift ;;
-M|--major) INCREMENT="major"; shift ;;
-m|--message) MESSAGE="$2"; shift 2 ;;
--dry-run) DRY_RUN=true; shift ;;
-*) echo "Unknown option: $1"; exit 1 ;;
*) VERSION="$1"; shift ;;
esac
done
# Check for uncommitted changes
if ! git diff --quiet || ! git diff --staged --quiet; then
echo "Error: Uncommitted changes. Commit or stash first."
exit 1
fi
# Get latest version from tags
get_latest_version() {
git tag -l 'v*.*.*' | sort -V | tail -n1 | sed 's/^v//' || echo "0.0.0"
}
# Increment version
increment_version() {
local v=$1 part=$2
IFS='.' read -r major minor patch <<< "$v"
case $part in
major) echo "$((major + 1)).0.0" ;;
minor) echo "$major.$((minor + 1)).0" ;;
patch) echo "$major.$minor.$((patch + 1))" ;;
esac
}
# Determine version
if [ -z "$VERSION" ]; then
LATEST=$(get_latest_version)
if [ "$LATEST" = "0.0.0" ]; then
VERSION="1.0.0"
else
VERSION=$(increment_version "$LATEST" "$INCREMENT")
fi
fi
TAG="v$VERSION"
# Check tag doesn't exist
if git tag -l "$TAG" | grep -q "$TAG"; then
echo "Error: Tag $TAG already exists"
exit 1
fi
echo "Creating release: $TAG"
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would create and push tag: $TAG"
exit 0
fi
# Create and push tag
if [ -n "$MESSAGE" ]; then
git tag -a "$TAG" -m "$MESSAGE"
else
git tag "$TAG"
fi
git push origin "$TAG"
echo "Release $TAG created! GitHub Actions will publish to NuGet.org"