-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcut-release.sh
More file actions
executable file
·76 lines (65 loc) · 1.58 KB
/
cut-release.sh
File metadata and controls
executable file
·76 lines (65 loc) · 1.58 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
#!/bin/bash
USAGE="Usage: $0 major|minor [BRANCH=release]"
# Evaluate arguments
case $1 in
major|minor)
RELEASE_TYPE=$1
;;
*)
echo "ERROR: Invalid release type: $1" >&2
echo $USAGE
exit 1
;;
esac
case $# in
1)
BRANCH="release"
;;
2)
BRANCH=$2
;;
*)
echo $USAGE
exit 1
;;
esac
git fetch --unshallow >/dev/null 2>&1
git checkout main >/dev/null 2>&1
git pull >/dev/null 2>&1
# Check if the release branch already exists
if git show-ref --verify --quiet refs/heads/$BRANCH; then
echo "ERROR: Branch '$BRANCH' already exists." >&2
exit 1
fi
# Get the latest version tag, default to 0.0.0
VERSION=$(git describe --tags --abbrev=0)
# Verify no active release candidates exist
if [[ $VERSION == *rc* ]]; then
echo "ERROR: An active release candidate already exists: $VERSION" >&2
exit 1
fi
read MAJOR MINOR PATCH <<< $(.github/scripts/split-version.sh $VERSION)
# Bump the version
case $RELEASE_TYPE in
major)
RELEASE_VERSION="$((MAJOR + 1)).0rc0"
;;
minor)
RELEASE_VERSION="${MAJOR}.$((MINOR + 1))rc0"
;;
esac
RELEASE_TAG="v$RELEASE_VERSION"
# Create a new branch for the release candidate
OUTPUT=$(git checkout -b $BRANCH >/dev/null 2>&1)
if [ $? -ne 0 ]; then
echo "ERROR: Failed to create branch '$BRANCH'." >&2
echo "$OUTPUT" >&2
exit 1
fi
OUTPUT=$(git push origin $BRANCH 2>&1)
if [ $? -ne 0 ]; then
echo "ERROR: Failed to push branch '$BRANCH' to origin." >&2
echo "$OUTPUT" >&2
exit 1
fi
echo $RELEASE_TAG