-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·127 lines (109 loc) · 3.78 KB
/
release.sh
File metadata and controls
executable file
·127 lines (109 loc) · 3.78 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env bash
set -euo pipefail
# === CONFIGURATION ===
REPO="github.com/Zachacious/presto" # Your GitHub repo (user/repo)
MAIN_BRANCH="main" # Or "master"
INITIAL_VERSION="v0.1.0" # The version for the very first release
# === SCRIPT LOGIC ===
# --- Initial Health Checks ---
if ! command -v gh >/dev/null 2>&1; then
echo "❌ GitHub CLI (gh) is required but not found. Please install it: https://cli.github.com/"
exit 1
fi
if ! git diff-index --quiet HEAD --; then
echo "❌ Uncommitted changes detected. Please commit or stash them before running a release."
git status --short
exit 1
fi
# --- Git Synchronization ---
echo "🔄 Switching to '$MAIN_BRANCH' and pulling latest changes..."
git checkout "$MAIN_BRANCH"
if ! GIT_TERMINAL_PROMPT=0 git pull origin "$MAIN_BRANCH"; then
echo "❌ Git Error: Failed to pull from origin. Please ensure your git credentials are configured correctly."
exit 1
fi
echo "🔄 Fetching all tags from the 'origin' remote..."
if ! GIT_TERMINAL_PROMPT=0 git fetch origin --tags --force; then
echo "❌ Git Error: Failed to fetch tags. Please ensure your git credentials are configured correctly."
exit 1
fi
# --- Argument Parsing ---
BUMP="patch"
VERSION=""
NOTES=""
while [[ $# -gt 0 ]]; do
case "$1" in
v*.*.*) VERSION="$1"; shift ;;
--major) BUMP="major"; shift ;;
--minor) BUMP="minor"; shift ;;
--patch) BUMP="patch"; shift ;;
-m|--message) NOTES="$2"; shift 2 ;;
*) echo "❌ Unknown argument: $1"; exit 1 ;;
esac
done
# --- Detect and Calculate Version ---
# This logic block is the corrected part.
if [[ -z "$VERSION" ]]; then
# We check if the 'git describe' command SUCCEEDS. If it fails, it means no tags exist.
if LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null); then
# The command succeeded, so tags exist.
echo "🔍 Latest tag found: $LATEST_TAG"
if [[ $LATEST_TAG =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
else
echo "❌ Invalid latest tag format: '$LATEST_TAG'. Expected vX.Y.Z"
exit 1
fi
case "$BUMP" in
major) ((MAJOR++)); MINOR=0; PATCH=0 ;;
minor) ((MINOR++)); PATCH=0 ;;
patch) ((PATCH++)) ;;
esac
VERSION="v$MAJOR.$MINOR.$PATCH"
else
# The command failed, which means no tags were found.
echo "🔍 No existing tags found. Creating initial release."
VERSION="$INITIAL_VERSION"
fi
fi
# --- Confirmation Step ---
echo "✅ New version will be: $VERSION"
read -p " Are you sure you want to proceed with tagging? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "🛑 Release cancelled."
exit 1
fi
# Get release notes from the user
if [[ -z "$NOTES" ]]; then
echo "✏️ Please enter the release notes. End with Ctrl+D."
NOTES=$(</dev/stdin)
fi
if [[ -z "$NOTES" ]]; then
echo "❌ Release notes cannot be empty."
exit 1
fi
# --- Execution Step ---
echo "1. Tagging version $VERSION..."
git tag -a "$VERSION" -m "Release $VERSION"
echo "2. Pushing tag to GitHub..."
if ! GIT_TERMINAL_PROMPT=0 git push origin "$VERSION"; then
echo "❌ Git Error: Failed to push the new tag. Please check your permissions and credentials."
git tag -d "$VERSION"
exit 1
fi
echo "3. Building release artifacts using 'make'..."
make release
echo "4. Creating GitHub Release..."
gh release create "$VERSION" dist/* \
--title "$VERSION" \
--notes "$NOTES"
echo "5. Notifying Go proxy..."
(
go list -m "$REPO@$VERSION" &>/dev/null
curl -sSf "https://proxy.golang.org/$REPO/@v/$VERSION.info" > /dev/null
) &
echo ""
echo "✅ Release $VERSION completed successfully!"