-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·269 lines (221 loc) · 8.97 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·269 lines (221 loc) · 8.97 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/bin/bash
set -e
# ─────────────────────────────────────────────
# DockMaster Pro — Release Script
# Usage:
# ./release.sh # interactive mode
# ./release.sh 1.1.0 # specify version directly
# ─────────────────────────────────────────────
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
INFO_PLIST="${SCRIPT_DIR}/DockMasterPro/App/Info.plist"
REPO_PRIVATE="devlive-community/DockMasterPro"
REPO_PUBLIC="devlive-community/DockMaster-Pro"
# ── Colors ────────────────────────────────────
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
info() { echo -e "${BLUE}▶ $1${NC}"; }
success() { echo -e "${GREEN}✓ $1${NC}"; }
warn() { echo -e "${YELLOW}⚠ $1${NC}"; }
error() { echo -e "${RED}✗ $1${NC}"; exit 1; }
# ── Get current version ───────────────────────
get_current_version() {
defaults read "${INFO_PLIST}" CFBundleShortVersionString 2>/dev/null || \
plutil -extract CFBundleShortVersionString raw "${INFO_PLIST}" 2>/dev/null || \
echo "0.0.0"
}
# ── Validate semver ───────────────────────────
validate_version() {
if [[ ! "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
error "Invalid version format: $1 (expected: MAJOR.MINOR.PATCH, e.g. 1.1.0)"
fi
}
# ── Check git status ──────────────────────────
check_git_clean() {
if [ -n "$(git status --porcelain)" ]; then
error "Working tree is not clean. Commit or stash changes first."
fi
}
# ── Check remote tag exists ───────────────────
check_remote_tag() {
local tag="v$1"
if git ls-remote --tags origin "refs/tags/${tag}" | grep -q "${tag}"; then
warn "Tag ${tag} already exists on remote."
return 1
fi
return 0
}
# ── Check GitHub release exists ───────────────
check_github_release() {
local tag="v$1"
# Check private repo
if gh release view "${tag}" --repo "${REPO_PRIVATE}" &>/dev/null; then
warn "Release ${tag} already exists on ${REPO_PRIVATE}"
return 1
fi
# Check public repo
if gh release view "${tag}" --repo "${REPO_PUBLIC}" &>/dev/null; then
warn "Release ${tag} already exists on ${REPO_PUBLIC}"
return 1
fi
return 0
}
# ── Update Info.plist version ─────────────────
update_version() {
local version="$1"
local build_num
build_num=$(date +%Y%m%d%H%M)
# Update CFBundleShortVersionString
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${version}" "${INFO_PLIST}"
# Update CFBundleVersion (build number)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${build_num}" "${INFO_PLIST}"
success "Updated Info.plist: version=${version}, build=${build_num}"
}
# ── Generate changelog preview ────────────────
generate_changelog_preview() {
local current_version="$1"
local new_version="$2"
local tag="v${new_version}"
echo ""
echo -e "${BLUE}━━━ Expected Release Notes ━━━${NC}"
# Try to find the previous tag
local prev_tag
prev_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$prev_tag" ]; then
local range="${prev_tag}..HEAD"
echo -e "${YELLOW}Changes since ${prev_tag}:${NC}"
echo ""
section() {
local emoji="$1"
local title="$2"
local pattern="$3"
local items
items=$(git log "$range" --no-merges --pretty=format:"%s" \
| grep -E "^${pattern}" \
| sed -E "s/^${pattern}(\([^)]*\))?: //" \
| sed 's/^/- /' || true)
if [ -n "$items" ]; then
echo -e "${emoji} ${title}"
echo "$items"
echo ""
fi
}
# Use inline pattern matching
for pattern_title in "feat:🚀 New Features" "fix:🐛 Bug Fixes" "perf:⚡ Performance" "i18n:🌍 Internationalization" "refactor:🔧 Refactoring"; do
pattern="${pattern_title%%:*}"
title="${pattern_title#*:}"
items=$(git log "$range" --no-merges --pretty=format:"%s" \
| grep -E "^${pattern}" \
| sed -E "s/^${pattern}(\([^)]*\))?: //" \
| sed 's/^/- /' || true)
if [ -n "$items" ]; then
echo "$title"
echo "$items"
echo ""
fi
done
# Other changes
other=$(git log "$range" --no-merges --pretty=format:"%s" \
| grep -vE "^(feat|fix|perf|i18n|refactor|Merge)" \
| sed 's/^/- /' || true)
if [ -n "$other" ]; then
echo "📝 Other Changes"
echo "$other"
echo ""
fi
else
warn "No previous tag found. This will be the first release."
fi
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
}
# ── Main ──────────────────────────────────────
main() {
echo ""
echo -e "${BLUE}╔══════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ DockMaster Pro — Release Script ║${NC}"
echo -e "${BLUE}╚══════════════════════════════════════╝${NC}"
echo ""
# Check prerequisites
info "Checking prerequisites..."
if ! command -v gh &>/dev/null; then
error "GitHub CLI (gh) is not installed. Run: brew install gh"
fi
if ! command -v plutil &>/dev/null; then
error "plutil not found. This script requires macOS."
fi
check_git_clean
# Determine version
local current_version
current_version=$(get_current_version)
local new_version="$1"
if [ -z "$new_version" ]; then
echo -e "Current version: ${GREEN}${current_version}${NC}"
echo ""
# Suggest next versions
IFS='.' read -r major minor patch <<< "$current_version"
echo "Suggested versions:"
echo " 1) ${major}.$((minor + 1)).0 (minor)"
echo " 2) ${major}.${minor}.$((patch + 1)) (patch)"
echo " 3) $((major + 1)).0.0 (major)"
echo ""
read -rp "Enter new version (e.g. 1.1.0): " new_version
fi
validate_version "$new_version"
echo ""
info "New version: ${GREEN}${new_version}${NC}"
local same_version=false
if [ "$new_version" = "$current_version" ]; then
warn "New version equals current version. Will only tag and push without updating Info.plist."
same_version=true
fi
# Check remote
info "Checking remote for existing tag and releases..."
local tag_exists=true
check_remote_tag "$new_version" || tag_exists=false
check_github_release "$new_version" || tag_exists=false
if [ "$tag_exists" = false ]; then
read -rp "Version v${new_version} may already exist. Continue anyway? (y/N): " confirm
if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then
error "Release cancelled."
fi
else
success "No conflicts found on remote."
fi
# Show changelog preview
generate_changelog_preview "$current_version" "$new_version"
# Confirm
read -rp "Release v${new_version}? This will commit, tag, and push. (y/N): " confirm
if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then
error "Release cancelled."
fi
# Execute release
echo ""
if [ "$same_version" = false ]; then
info "Updating version in Info.plist..."
update_version "$new_version"
info "Committing version bump..."
git add "${INFO_PLIST}"
git commit -m "chore: bump version to ${new_version}"
else
info "Version matches current Info.plist. Skipping version update."
fi
local tag="v${new_version}"
info "Creating tag ${tag}..."
git tag -a "$tag" -m "Release ${tag}"
info "Pushing to remote..."
git push origin HEAD
git push origin "$tag"
echo ""
success "Release v${new_version} initiated!"
echo ""
echo "CI is now building and will publish to:"
echo " - ${REPO_PUBLIC} (with binaries)"
echo " - ${REPO_PRIVATE} (release notes only)"
echo ""
echo "Monitor progress: https://github.com/${REPO_PRIVATE}/actions"
echo ""
}
main "$@"