-
Notifications
You must be signed in to change notification settings - Fork 331
Expand file tree
/
Copy pathperform-release.sh
More file actions
executable file
·105 lines (95 loc) · 3.87 KB
/
perform-release.sh
File metadata and controls
executable file
·105 lines (95 loc) · 3.87 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
#!/usr/bin/env bash
set -euo pipefail
# Ask for confirmation before continuing the release
function confirmOrAbort() {
read -p "Do you want to continue? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Aborting."
exit 1
fi
}
# Check if current branch is either 'master' or 'release/v*'
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$CURRENT_BRANCH" == "master" ]]; then
MINOR_RELEASE=true
elif [[ "$CURRENT_BRANCH" =~ ^release/v[0-9]+\.[0-9]+\.x$ ]]; then
MINOR_RELEASE=false
else
echo "❌ Please check out either 'master' branch or a 'release/v*' branch to perform a release first."
exit 1
fi
echo -n "✅ Current branch is '$CURRENT_BRANCH'. Performing a "
if [ "$MINOR_RELEASE" = true ]; then
echo "minor release."
else
echo "patch release."
fi
# Check upstream branch is set
if ! git rev-parse --abbrev-ref --symbolic-full-name "@{u}" >/dev/null 2>&1; then
echo "❌ No upstream branch set. Please set the upstream branch for the current branch."
exit 1
fi
# Get the remote name
REMOTE=$(git config --get "branch.$CURRENT_BRANCH.remote")
if [ -z "$REMOTE" ]; then
echo "❌ Unable to determine the remote name. Please ensure you have a remote set."
exit 1
fi
# Check if working copy is clean
if ! git diff-index --quiet HEAD; then
echo "❌ Working copy is not clean. Please commit or stash your changes before performing a release."
exit 1
fi
# Check if clone is up to date
if ! git fetch "$REMOTE" --quiet ; then
echo "❌ Unable to fetch the latest changes from $REMOTE. Please check your network connection."
exit 1
fi
if ! git diff-index --quiet "$REMOTE/$CURRENT_BRANCH"; then
echo "❌ Working copy is not up to date with $REMOTE/$CURRENT_BRANCH. Please pull the latest changes before performing a release."
exit 1
fi
echo "✅ Working copy is clean and up-to-date."
# Check the git log history
LAST_RELEASE_TAG=$(git describe --tags --abbrev=0 --match='v[0-9]*.[0-9]*.[0-9]*')
echo "ℹ️ Last release version: $LAST_RELEASE_TAG"
SUSPICIOUS_COMMITS=$(git log --oneline --first-parent "$LAST_RELEASE_TAG"..HEAD | grep -E -v "Merge pull request #" | grep -E -v "\(#" || true)
if [ -n "$SUSPICIOUS_COMMITS" ]; then
echo "❌ The following commits are not merge commits and may not be suitable for a release:"
echo "$SUSPICIOUS_COMMITS"
echo "Please review these commits before proceeding with the release."
confirmOrAbort
else
echo "✅ All commits since the last release are merge commits."
fi
# Get the next version to release
VERSION=$(echo "$LAST_RELEASE_TAG" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sed 's/^v//' || true)
if [ -z "$VERSION" ]; then
echo "❌ Unable to determine the next release version from the last release tag: $LAST_RELEASE_TAG"
exit 1
fi
if [ "$MINOR_RELEASE" = true ]; then
NEXT_VERSION=$(echo "$VERSION" | awk -F. '{printf "%d.%d.0", $1, $2 + 1}')
else
NEXT_VERSION=$(echo "$VERSION" | awk -F. '{printf "%d.%d.%d", $1, $2, $3 + 1}')
fi
echo "ℹ️ Next version to release: $NEXT_VERSION"
# Check milestone exists
if ! gh api "repos/{owner}/{repo}/milestones" --paginate --jq ".[].title" | grep -qx "$NEXT_VERSION"; then
echo "❌ Milestone '$NEXT_VERSION' does not exist. Please reach out to the guild before performing a release."
exit 1
fi
echo "✅ GitHub milestone for $NEXT_VERSION exists."
# Create and push the release tag
NEXT_RELEASE_TAG="v$NEXT_VERSION"
echo "ℹ️ The release tag $NEXT_RELEASE_TAG will be created and pushed. No abort is possible after this point."
confirmOrAbort
git tag -a -s -m "Release $NEXT_RELEASE_TAG" "$NEXT_RELEASE_TAG"
if ! git push "$REMOTE" "$NEXT_RELEASE_TAG" --no-verify; then
echo "❌ Unable to push the release tag to $REMOTE."
echo "ℹ️ Deleting the created local tag."
git tag -d "$NEXT_RELEASE_TAG"
exit 1
fi
echo "✅ Release tag $NEXT_RELEASE_TAG created and pushed to $REMOTE."